@@ -2,10 +2,12 @@ pub use libc::dev_t;
2
2
pub use libc:: stat as FileStat ;
3
3
4
4
use { Errno , Result , NixPath } ;
5
- use libc:: { self , mode_t} ;
5
+ use libc:: { self , c_int , mode_t} ;
6
6
use std:: mem;
7
7
use std:: os:: unix:: io:: RawFd ;
8
8
9
+ pub use self :: consts:: * ;
10
+
9
11
mod ffi {
10
12
use libc:: { c_char, c_int, mode_t, dev_t} ;
11
13
pub use libc:: { stat, fstat, lstat} ;
@@ -109,3 +111,62 @@ pub fn fstat(fd: RawFd) -> Result<FileStat> {
109
111
110
112
Ok ( dst)
111
113
}
114
+
115
+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
116
+ mod consts {
117
+ use libc:: c_int;
118
+
119
+ bitflags ! (
120
+ flags FstatatFlag : c_int {
121
+ const AT_SYMLINK_NOFOLLOW = 0o000400 ,
122
+ const AT_NO_AUTOMOUNT = 0o004000 ,
123
+ const AT_EMPTY_PATH = 0o010000 ,
124
+ }
125
+ ) ;
126
+ }
127
+
128
+ #[ cfg( any( target_os = "freebsd" , target_os = "dragonfly" ) ) ]
129
+ mod consts {
130
+ use libc:: c_int;
131
+
132
+ bitflags ! (
133
+ flags FstatatFlag : c_int {
134
+ const AT_SYMLINK_NOFOLLOW = 0o1 ,
135
+ }
136
+ ) ;
137
+ }
138
+
139
+ #[ cfg( target_os = "openbsd" ) ]
140
+ mod consts {
141
+ use libc:: c_int;
142
+
143
+ bitflags ! (
144
+ flags FstatatFlag : c_int {
145
+ const AT_SYMLINK_NOFOLLOW = 0o02 ,
146
+ }
147
+ ) ;
148
+ }
149
+
150
+ #[ cfg( target_os = "netbsd" ) ]
151
+ mod consts {
152
+ use libc:: c_int;
153
+
154
+ bitflags ! (
155
+ flags FstatatFlag : c_int {
156
+ const AT_SYMLINK_NOFOLLOW = 0o1000 ,
157
+ }
158
+ ) ;
159
+ }
160
+
161
+ #[ cfg( any( target_os = "linux" , target_os = "android" , target_os = "freebsd" , target_os = "dragonfly" , target_os = "netbsd" ) ) ]
162
+ pub fn fstatat < P : ?Sized + NixPath > ( dirfd : RawFd , pathname : & P , f : FstatatFlag ) -> Result < FileStat > {
163
+ let mut dst = unsafe { mem:: uninitialized ( ) } ;
164
+ let res = try!( pathname. with_nix_path ( |cstr| {
165
+ unsafe { libc:: fstatat ( dirfd, cstr. as_ptr ( ) , & mut dst as * mut FileStat , f. bits ( ) as c_int ) }
166
+ } ) ) ;
167
+
168
+ try!( Errno :: result ( res) ) ;
169
+
170
+ Ok ( dst)
171
+ }
172
+
0 commit comments