@@ -9,6 +9,7 @@ use std::os::unix::io::RawFd;
9
9
use crate :: sys:: time:: { TimeSpec , TimeVal } ;
10
10
11
11
libc_bitflags ! (
12
+ /// "File type" flags for `mknod` and related functions.
12
13
pub struct SFlag : mode_t {
13
14
S_IFIFO ;
14
15
S_IFCHR ;
@@ -22,6 +23,7 @@ libc_bitflags!(
22
23
) ;
23
24
24
25
libc_bitflags ! {
26
+ /// "File mode / permissions" flags.
25
27
pub struct Mode : mode_t {
26
28
S_IRWXU ;
27
29
S_IRUSR ;
@@ -41,11 +43,26 @@ libc_bitflags! {
41
43
}
42
44
}
43
45
46
+ /// Create a special or ordinary file, by pathname.
44
47
pub 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)
49
66
} ) ?;
50
67
51
68
Errno :: result ( res) . map ( drop)
0 commit comments