Skip to content

Commit 12abfd6

Browse files
committed
add support for mknodat
1 parent 97c4ca2 commit 12abfd6

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2424
([#739](https://github.com/nix-rust/nix/pull/739))
2525
- Added nix::sys::ptrace::detach.
2626
([#749](https://github.com/nix-rust/nix/pull/749))
27+
- Added mknodat
28+
([#747](https://github.com/nix-rust/nix/pull/747))
2729

2830
### Changed
2931
- Renamed existing `ptrace` wrappers to encourage namespacing ([#692](https://github.com/nix-rust/nix/pull/692))

src/sys/stat.rs

+13
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ pub fn mknod<P: ?Sized + NixPath>(path: &P, kind: SFlag, perm: Mode, dev: dev_t)
5050
Errno::result(res).map(drop)
5151
}
5252

53+
/// Create a special or ordinary file
54+
/// ([posix specification](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mknod.html)).
55+
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
56+
pub fn mknodat<P: ?Sized + NixPath>(dirfd: &RawFd, path: &P, kind: SFlag, perm: Mode, dev: dev_t) -> Result<()> {
57+
let res = try!(path.with_nix_path(|cstr| {
58+
unsafe {
59+
libc::mknodat(*dirfd, cstr.as_ptr(), kind.bits | perm.bits() as mode_t, dev)
60+
}
61+
}));
62+
63+
Errno::result(res).map(drop)
64+
}
65+
5366
#[cfg(target_os = "linux")]
5467
pub fn major(dev: dev_t) -> u64 {
5568
((dev >> 32) & 0xfffff000) |

0 commit comments

Comments
 (0)