summaryrefslogtreecommitdiffstats
path: root/vendor/sysinfo/src/utils.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/sysinfo/src/utils.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/sysinfo/src/utils.rs')
-rw-r--r--vendor/sysinfo/src/utils.rs61
1 files changed, 61 insertions, 0 deletions
diff --git a/vendor/sysinfo/src/utils.rs b/vendor/sysinfo/src/utils.rs
new file mode 100644
index 000000000..578ab61c6
--- /dev/null
+++ b/vendor/sysinfo/src/utils.rs
@@ -0,0 +1,61 @@
+// Take a look at the license at the top of the repository in the LICENSE file.
+
+/* convert a path to a NUL-terminated Vec<u8> suitable for use with C functions */
+#[cfg(all(
+ not(feature = "unknown-ci"),
+ any(target_os = "linux", target_os = "android", target_vendor = "apple")
+))]
+pub(crate) fn to_cpath(path: &std::path::Path) -> Vec<u8> {
+ use std::{ffi::OsStr, os::unix::ffi::OsStrExt};
+
+ let path_os: &OsStr = path.as_ref();
+ let mut cpath = path_os.as_bytes().to_vec();
+ cpath.push(0);
+ cpath
+}
+
+/// Converts the value into a parallel iterator (if the multithread feature is enabled)
+/// Uses the rayon::iter::IntoParallelIterator trait
+#[cfg(all(
+ all(
+ any(
+ target_os = "linux",
+ target_os = "android",
+ target_os = "macos",
+ target_os = "windows",
+ target_os = "freebsd",
+ ),
+ feature = "multithread"
+ ),
+ not(feature = "apple-sandbox"),
+ not(feature = "unknown-ci")
+))]
+pub(crate) fn into_iter<T>(val: T) -> T::Iter
+where
+ T: rayon::iter::IntoParallelIterator,
+{
+ val.into_par_iter()
+}
+
+/// Converts the value into a sequential iterator (if the multithread feature is disabled)
+/// Uses the std::iter::IntoIterator trait
+#[cfg(all(
+ all(
+ any(
+ target_os = "linux",
+ target_os = "android",
+ target_os = "macos",
+ target_os = "windows",
+ target_os = "freebsd",
+ ),
+ not(feature = "multithread")
+ ),
+ not(feature = "unknown-ci"),
+ not(feature = "apple-sandbox")
+))]
+pub(crate) fn into_iter<T>(val: T) -> T::IntoIter
+where
+ T: IntoIterator,
+{
+ val.into_iter()
+}