@@ -6,9 +6,9 @@ use crate::path::{Path, PathBuf};
66use crate :: sys:: time:: SystemTime ;
77use crate :: sys:: unsupported;
88
9- struct Fd ( * mut vex_sdk:: FIL ) ;
9+ struct FileDesc ( * mut vex_sdk:: FIL ) ;
1010
11- pub struct File ( Fd ) ;
11+ pub struct File ( FileDesc ) ;
1212
1313//TODO: We may be able to get some of this info
1414#[ derive( Clone ) ]
@@ -173,7 +173,7 @@ impl File {
173173 if file. is_null ( ) {
174174 Err ( io:: Error :: new ( io:: ErrorKind :: NotFound , "Could not open file" ) )
175175 } else {
176- Ok ( Self ( Fd ( file) ) )
176+ Ok ( Self ( FileDesc ( file) ) )
177177 }
178178 }
179179
@@ -182,73 +182,75 @@ impl File {
182182 }
183183
184184 pub fn fsync ( & self ) -> io:: Result < ( ) > {
185- todo ! ( )
185+ self . flush ( )
186186 }
187187
188188 pub fn datasync ( & self ) -> io:: Result < ( ) > {
189- todo ! ( )
189+ self . flush ( )
190190 }
191191
192192 pub fn truncate ( & self , _size : u64 ) -> io:: Result < ( ) > {
193- todo ! ( )
193+ unsupported ( )
194194 }
195195
196196 pub fn read ( & self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
197197 let len = buf. len ( ) as _ ;
198198 let buf_ptr = buf. as_mut_ptr ( ) ;
199199 let read = unsafe { vex_sdk:: vexFileRead ( buf_ptr. cast ( ) , 1 , len, self . 0 . 0 ) } ;
200200 if read < 0 {
201- Err ( io:: Error :: new (
202- io:: ErrorKind :: Other ,
203- "Could not read from file" ,
204- ) )
201+ Err ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not read from file" ) )
205202 } else {
206203 Ok ( read as usize )
207204 }
208205 }
209206
210- pub fn read_vectored ( & self , _bufs : & mut [ IoSliceMut < ' _ > ] ) -> io:: Result < usize > {
211- todo ! ( )
207+ pub fn read_vectored ( & self , bufs : & mut [ IoSliceMut < ' _ > ] ) -> io:: Result < usize > {
208+ crate :: io :: default_read_vectored ( |buf| self . read ( buf ) , bufs )
212209 }
213210
211+ #[ inline]
214212 pub fn is_read_vectored ( & self ) -> bool {
215- todo ! ( )
213+ false
216214 }
217215
218- pub fn read_buf ( & self , _cursor : BorrowedCursor < ' _ > ) -> io:: Result < ( ) > {
219- todo ! ( )
216+ pub fn read_buf ( & self , cursor : BorrowedCursor < ' _ > ) -> io:: Result < ( ) > {
217+ crate :: io :: default_read_buf ( |b| self . read ( b ) , cursor )
220218 }
221219
222220 pub fn write ( & self , _buf : & [ u8 ] ) -> io:: Result < usize > {
223221 todo ! ( )
224222 }
225223
226- pub fn write_vectored ( & self , _bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
227- todo ! ( )
224+ pub fn write_vectored ( & self , bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
225+ crate :: io :: default_write_vectored ( |buf| self . write ( buf ) , bufs )
228226 }
229227
228+ #[ inline]
230229 pub fn is_write_vectored ( & self ) -> bool {
231- todo ! ( )
230+ false
232231 }
233232
234233 pub fn flush ( & self ) -> io:: Result < ( ) > {
235- todo ! ( )
234+ unsafe {
235+ vex_sdk:: vexFileSync ( self . 0 . 0 ) ;
236+ }
237+ Ok ( ( ) )
236238 }
237239
238240 pub fn seek ( & self , _pos : SeekFrom ) -> io:: Result < u64 > {
239- todo ! ( )
241+ todo ! ( ) ;
240242 }
241243
242244 pub fn duplicate ( & self ) -> io:: Result < File > {
243- todo ! ( )
245+ unsupported ! ( )
244246 }
245247
246248 pub fn set_permissions ( & self , _perm : FilePermissions ) -> io:: Result < ( ) > {
247- todo ! ( )
249+ unsupported ( )
248250 }
249251
250252 pub fn set_times ( & self , _times : FileTimes ) -> io:: Result < ( ) > {
251- todo ! ( )
253+ unsupported ( )
252254 }
253255}
254256
0 commit comments