summaryrefslogtreecommitdiff
path: root/test/test_stat.rs
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_stat.rs')
-rw-r--r--test/test_stat.rs71
1 files changed, 39 insertions, 32 deletions
diff --git a/test/test_stat.rs b/test/test_stat.rs
index 42c536a8..922c25fd 100644
--- a/test/test_stat.rs
+++ b/test/test_stat.rs
@@ -11,7 +11,6 @@ use std::path::Path;
#[cfg(not(any(target_os = "netbsd", target_os = "redox")))]
use libc::{S_IFMT, S_IFLNK};
-#[cfg(not(target_os = "redox"))]
use libc::mode_t;
#[cfg(not(target_os = "redox"))]
@@ -312,39 +311,47 @@ fn test_mkdirat_fail() {
target_os = "ios",
target_os = "macos",
target_os = "redox")))]
-fn test_mknod_family() {
+fn test_mknod() {
+ use stat::{lstat, mknod, SFlag};
+
+ let file_name = "test_file";
+ let tempdir = tempfile::tempdir().unwrap();
+ let target = tempdir.path().join(file_name);
+ mknod(&target, SFlag::S_IFREG, Mode::S_IRWXU, 0).unwrap();
+ let mode = lstat(&target).unwrap().st_mode as mode_t;
+ assert!(mode & libc::S_IFREG == libc::S_IFREG);
+ assert!(mode & libc::S_IRWXU == libc::S_IRWXU);
+}
+
+#[test]
+#[cfg(not(any(target_os = "freebsd",
+ target_os = "illumos",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "redox")))]
+fn test_mknodat() {
use fcntl::{AtFlags, OFlag};
use nix::dir::Dir;
- use stat::{fstatat, lstat, mknod, mknodat, SFlag};
+ use stat::{fstatat, mknodat, SFlag};
let file_name = "test_file";
- {
- let tempdir = tempfile::tempdir().unwrap();
- let target = tempdir.path().join(file_name);
- mknod(&target, SFlag::S_IFREG, Mode::S_IRWXU, 0).unwrap();
- let mode = lstat(&target).unwrap().st_mode as mode_t;
- assert!(mode & libc::S_IFREG == libc::S_IFREG);
- assert!(mode & libc::S_IRWXU == libc::S_IRWXU);
- }
- {
- let tempdir = tempfile::tempdir().unwrap();
- let target_dir = Dir::open(tempdir.path(), OFlag::O_DIRECTORY, Mode::S_IRWXU).unwrap();
- mknodat(
- target_dir.as_raw_fd(),
- file_name,
- SFlag::S_IFREG,
- Mode::S_IRWXU,
- 0,
- )
- .unwrap();
- let mode = fstatat(
- target_dir.as_raw_fd(),
- file_name,
- AtFlags::AT_SYMLINK_NOFOLLOW,
- )
- .unwrap()
- .st_mode as mode_t;
- assert!(mode & libc::S_IFREG == libc::S_IFREG);
- assert!(mode & libc::S_IRWXU == libc::S_IRWXU);
- }
+ let tempdir = tempfile::tempdir().unwrap();
+ let target_dir = Dir::open(tempdir.path(), OFlag::O_DIRECTORY, Mode::S_IRWXU).unwrap();
+ mknodat(
+ target_dir.as_raw_fd(),
+ file_name,
+ SFlag::S_IFREG,
+ Mode::S_IRWXU,
+ 0,
+ )
+ .unwrap();
+ let mode = fstatat(
+ target_dir.as_raw_fd(),
+ file_name,
+ AtFlags::AT_SYMLINK_NOFOLLOW,
+ )
+ .unwrap()
+ .st_mode as mode_t;
+ assert!(mode & libc::S_IFREG == libc::S_IFREG);
+ assert!(mode & libc::S_IRWXU == libc::S_IRWXU);
}