@@ -9,6 +9,7 @@ use std::os::unix::io::RawFd;
99use crate :: sys:: time:: { TimeSpec , TimeVal } ;
1010
1111libc_bitflags ! (
12+ /// "File type" flags for `mknod` and related functions.
1213 pub struct SFlag : mode_t {
1314 S_IFIFO ;
1415 S_IFCHR ;
@@ -22,6 +23,7 @@ libc_bitflags!(
2223) ;
2324
2425libc_bitflags ! {
26+ /// "File mode / permissions" flags.
2527 pub struct Mode : mode_t {
2628 S_IRWXU ;
2729 S_IRUSR ;
@@ -41,11 +43,26 @@ libc_bitflags! {
4143 }
4244}
4345
46+ /// Create a special or ordinary file, by pathname.
4447pub fn mknod < P : ?Sized + NixPath > ( path : & P , kind : SFlag , perm : Mode , dev : dev_t ) -> Result < ( ) > {
45- let res = path. with_nix_path ( |cstr| {
46- unsafe {
47- libc:: mknod ( cstr. as_ptr ( ) , kind. bits | perm. bits ( ) as mode_t , dev)
48- }
48+ let res = path. with_nix_path ( |cstr| unsafe {
49+ libc:: mknod ( cstr. as_ptr ( ) , kind. bits | perm. bits ( ) as mode_t , dev)
50+ } ) ?;
51+
52+ Errno :: result ( res) . map ( drop)
53+ }
54+
55+ /// Create a special or ordinary file, relative to a given directory.
56+ #[ cfg( not( any( target_os = "ios" , target_os = "macos" , target_os = "redox" ) ) ) ]
57+ pub fn mknodat < P : ?Sized + NixPath > (
58+ dirfd : RawFd ,
59+ path : & P ,
60+ kind : SFlag ,
61+ perm : Mode ,
62+ dev : dev_t ,
63+ ) -> Result < ( ) > {
64+ let res = path. with_nix_path ( |cstr| unsafe {
65+ libc:: mknodat ( dirfd, cstr. as_ptr ( ) , kind. bits | perm. bits ( ) as mode_t , dev)
4966 } ) ?;
5067
5168 Errno :: result ( res) . map ( drop)
0 commit comments