1
+ use r_efi:: protocols:: file;
2
+
1
3
use crate :: ffi:: OsString ;
2
4
use crate :: fmt;
3
5
use crate :: hash:: Hash ;
@@ -22,7 +24,12 @@ pub struct ReadDir(!);
22
24
pub struct DirEntry ( !) ;
23
25
24
26
#[ derive( Clone , Debug ) ]
25
- pub struct OpenOptions { }
27
+ pub struct OpenOptions {
28
+ mode : u64 ,
29
+ append : bool ,
30
+ truncate : bool ,
31
+ create_new : bool ,
32
+ }
26
33
27
34
#[ derive( Copy , Clone , Debug , Default ) ]
28
35
pub struct FileTimes { }
@@ -141,15 +148,48 @@ impl DirEntry {
141
148
142
149
impl OpenOptions {
143
150
pub fn new ( ) -> OpenOptions {
144
- OpenOptions { }
151
+ OpenOptions { mode : 0 , append : false , create_new : false , truncate : false }
152
+ }
153
+
154
+ pub fn read ( & mut self , read : bool ) {
155
+ if read {
156
+ self . mode |= file:: MODE_READ ;
157
+ } else {
158
+ self . mode &= !file:: MODE_READ ;
159
+ }
145
160
}
146
161
147
- pub fn read ( & mut self , _read : bool ) { }
148
- pub fn write ( & mut self , _write : bool ) { }
149
- pub fn append ( & mut self , _append : bool ) { }
150
- pub fn truncate ( & mut self , _truncate : bool ) { }
151
- pub fn create ( & mut self , _create : bool ) { }
152
- pub fn create_new ( & mut self , _create_new : bool ) { }
162
+ pub fn write ( & mut self , write : bool ) {
163
+ if write {
164
+ self . mode |= file:: MODE_WRITE ;
165
+ } else {
166
+ self . mode &= !file:: MODE_WRITE ;
167
+ }
168
+ }
169
+
170
+ pub fn append ( & mut self , append : bool ) {
171
+ // Docs state that `.write(true).append(true)` has the same effect as `.append(true)`
172
+ if append {
173
+ self . write ( true ) ;
174
+ }
175
+ self . append = append;
176
+ }
177
+
178
+ pub fn truncate ( & mut self , truncate : bool ) {
179
+ self . truncate = truncate;
180
+ }
181
+
182
+ pub fn create ( & mut self , create : bool ) {
183
+ if create {
184
+ self . mode |= file:: MODE_CREATE ;
185
+ } else {
186
+ self . mode &= !file:: MODE_CREATE ;
187
+ }
188
+ }
189
+
190
+ pub fn create_new ( & mut self , create_new : bool ) {
191
+ self . create_new = create_new;
192
+ }
153
193
}
154
194
155
195
impl File {
0 commit comments