Browse Source

ctru-rs: impl Seek for File

pull/10/head
Fenrir 8 years ago
parent
commit
47e4c16118
  1. 23
      ctru-rs/src/services/fs.rs

23
ctru-rs/src/services/fs.rs

@ -3,7 +3,7 @@
//! This module contains basic methods to manipulate the contents of the 3DS's filesystem. //! This module contains basic methods to manipulate the contents of the 3DS's filesystem.
//! Only the SD card is currently supported. //! Only the SD card is currently supported.
use std::io::{Read, Write}; use std::io::{Read, Write, Seek, SeekFrom};
use std::io::Error as IoError; use std::io::Error as IoError;
use std::io::Result as IoResult; use std::io::Result as IoResult;
use std::io::ErrorKind as IoErrorKind; use std::io::ErrorKind as IoErrorKind;
@ -923,6 +923,27 @@ impl Write for File {
} }
} }
impl Seek for File {
fn seek(&mut self, pos: SeekFrom) -> IoResult<u64> {
match pos {
SeekFrom::Start(off) => {
self.offset = off;
},
SeekFrom::End(off) => {
let mut temp = self.metadata()?.len() as i64;
temp += off;
self.offset = temp as u64;
},
SeekFrom::Current(off) => {
let mut temp = self.offset as i64;
temp += off;
self.offset = temp as u64;
},
}
Ok(self.offset)
}
}
impl Drop for Fs { impl Drop for Fs {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {

Loading…
Cancel
Save