@@ -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,25 @@ 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
+ pub fn mknodat < P : ?Sized + NixPath > (
57
+ dirfd : RawFd ,
58
+ path : & P ,
59
+ kind : SFlag ,
60
+ perm : Mode ,
61
+ dev : dev_t ,
62
+ ) -> Result < ( ) > {
63
+ let res = path. with_nix_path ( |cstr| unsafe {
64
+ libc:: mknodat ( dirfd, cstr. as_ptr ( ) , kind. bits | perm. bits ( ) as mode_t , dev)
49
65
} ) ?;
50
66
51
67
Errno :: result ( res) . map ( drop)
0 commit comments