31
31
32
32
#![ unstable( feature = "std_misc" ) ]
33
33
34
- use vec:: Vec ;
35
- use sys:: os_str:: Buf ;
36
- use sys_common:: { AsInner , IntoInner , FromInner } ;
37
34
use ffi:: { OsStr , OsString } ;
35
+ use fs:: { Permissions , OpenOptions } ;
36
+ use fs;
38
37
use libc;
38
+ use mem;
39
+ use sys:: os_str:: Buf ;
40
+ use sys_common:: { AsInner , AsInnerMut , IntoInner , FromInner } ;
41
+ use vec:: Vec ;
39
42
40
43
use old_io;
41
44
@@ -54,6 +57,12 @@ impl AsRawFd for old_io::fs::File {
54
57
}
55
58
}
56
59
60
+ impl AsRawFd for fs:: File {
61
+ fn as_raw_fd ( & self ) -> Fd {
62
+ self . as_inner ( ) . fd ( ) . raw ( )
63
+ }
64
+ }
65
+
57
66
impl AsRawFd for old_io:: pipe:: PipeStream {
58
67
fn as_raw_fd ( & self ) -> Fd {
59
68
self . as_inner ( ) . fd ( )
@@ -123,18 +132,49 @@ impl OsStringExt for OsString {
123
132
124
133
// Unix-specific extensions to `OsStr`.
125
134
pub trait OsStrExt {
135
+ fn from_byte_slice ( slice : & [ u8 ] ) -> & OsStr ;
126
136
fn as_byte_slice ( & self ) -> & [ u8 ] ;
127
137
}
128
138
129
139
impl OsStrExt for OsStr {
140
+ fn from_byte_slice ( slice : & [ u8 ] ) -> & OsStr {
141
+ unsafe { mem:: transmute ( slice) }
142
+ }
130
143
fn as_byte_slice ( & self ) -> & [ u8 ] {
131
144
& self . as_inner ( ) . inner
132
145
}
133
146
}
134
147
148
+ // Unix-specific extensions to `Permissions`
149
+ pub trait PermissionsExt {
150
+ fn set_mode ( & mut self , mode : i32 ) ;
151
+ }
152
+
153
+ impl PermissionsExt for Permissions {
154
+ fn set_mode ( & mut self , mode : i32 ) {
155
+ * self = FromInner :: from_inner ( FromInner :: from_inner ( mode) ) ;
156
+ }
157
+ }
158
+
159
+ // Unix-specific extensions to `OpenOptions`
160
+ pub trait OpenOptionsExt {
161
+ /// Set the mode bits that a new file will be created with.
162
+ ///
163
+ /// If a new file is created as part of a `File::open_opts` call then this
164
+ /// specified `mode` will be used as the permission bits for the new file.
165
+ fn mode ( & mut self , mode : i32 ) -> & mut Self ;
166
+ }
167
+
168
+ impl OpenOptionsExt for OpenOptions {
169
+ fn mode ( & mut self , mode : i32 ) -> & mut OpenOptions {
170
+ self . as_inner_mut ( ) . mode ( mode) ; self
171
+ }
172
+ }
173
+
135
174
/// A prelude for conveniently writing platform-specific code.
136
175
///
137
176
/// Includes all extension traits, and some important type definitions.
138
177
pub mod prelude {
139
- pub use super :: { Fd , AsRawFd } ;
178
+ #[ doc( no_inline) ]
179
+ pub use super :: { Fd , AsRawFd , OsStrExt , OsStringExt , PermissionsExt } ;
140
180
}
0 commit comments