@@ -339,33 +339,19 @@ impl File {
339
339
SeekFrom :: Start ( offset) => unsafe {
340
340
map_fresult ( vex_sdk:: vexFileSeek ( self . fd . 0 , try_convert_offset ( offset) ?, SEEK_SET ) ) ?
341
341
} ,
342
-
343
- // VEXos does not allow seeking with negative offsets.
344
- // That means we need to calculate the offset from the start for both of these.
345
342
SeekFrom :: End ( offset) => unsafe {
346
- // If our offset is positive, everything is easy
347
343
if offset >= 0 {
348
344
map_fresult ( vex_sdk:: vexFileSeek (
349
345
self . fd . 0 ,
350
346
try_convert_offset ( offset) ?,
351
347
SEEK_END ,
352
348
) ) ?
353
349
} else {
354
- // Get the position of the end of the file...
350
+ // `vexFileSeek` does not support seeking with negative offset, meaning
351
+ // we have to calculate the offset from the end of the file ourselves.
355
352
map_fresult ( vex_sdk:: vexFileSeek (
356
353
self . fd . 0 ,
357
- try_convert_offset ( offset) ?,
358
- SEEK_END ,
359
- ) ) ?;
360
- // The number returned by the VEX SDK tell is stored as a 32 bit interger,
361
- // and therefore this conversion cannot fail.
362
- let position = self . tell ( ) ? as i64 ;
363
-
364
- // Offset from that position
365
- let new_position = position + offset;
366
- map_fresult ( vex_sdk:: vexFileSeek (
367
- self . fd . 0 ,
368
- try_convert_offset ( new_position) ?,
354
+ try_convert_offset ( self . file_attr ( ) . size + offset) ?,
369
355
SEEK_SET ,
370
356
) ) ?
371
357
}
@@ -378,12 +364,11 @@ impl File {
378
364
SEEK_CUR ,
379
365
) ) ?
380
366
} else {
381
- let position = self . tell ( ) ? as i64 ;
382
-
383
- let new_position = position + offset;
367
+ // `vexFileSeek` does not support seeking with negative offset, meaning
368
+ // we have to calculate the offset from the stream position ourselves.
384
369
map_fresult ( vex_sdk:: vexFileSeek (
385
370
self . fd . 0 ,
386
- try_convert_offset ( new_position ) ?,
371
+ try_convert_offset ( ( self . tell ( ) ? as i64 ) + offset ) ?,
387
372
SEEK_SET ,
388
373
) ) ?
389
374
}
0 commit comments