Skip to content

Commit b5ef9a3

Browse files
committed
Emerald: Implemented File::seek
1 parent 942910c commit b5ef9a3

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,15 +1212,15 @@ dependencies = [
12121212

12131213
[[package]]
12141214
name = "emerald_kernel_user_link"
1215-
version = "0.2.4"
1215+
version = "0.2.7"
12161216
dependencies = [
12171217
"compiler_builtins",
12181218
"rustc-std-workspace-core",
12191219
]
12201220

12211221
[[package]]
12221222
name = "emerald_std"
1223-
version = "0.2.7"
1223+
version = "0.2.8"
12241224
dependencies = [
12251225
"compiler_builtins",
12261226
"emerald_kernel_user_link",

library/std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ r-efi-alloc = { version = "1.0.0", features = ['rustc-dep-of-std'] }
6161
# This is from `https://github.com/Amjad50/Emerald`, i.e. it must be run from that context
6262
# TODO: for now we are using relative path, as we are using `libm` from `git` and we can't publish
6363
# that. Fix it later
64-
emerald_std = { version = "0.2.5", features = ['rustc-dep-of-std'], path = "../../../../libraries/emerald_std" }
64+
emerald_std = { version = "0.2.8", features = ['rustc-dep-of-std'], path = "../../../../libraries/emerald_std" }
6565

6666
[features]
6767
backtrace = [

library/std/src/sys/pal/emerald/fs.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::ffi::CStr;
22

3-
use emerald_std::io::FileStat;
3+
use emerald_std::io::{FileStat, SeekWhence};
44

55
use crate::ffi::OsString;
66
use crate::fmt;
@@ -300,8 +300,20 @@ impl File {
300300
Ok(())
301301
}
302302

303-
pub fn seek(&self, _pos: SeekFrom) -> io::Result<u64> {
304-
todo!()
303+
pub fn seek(&self, pos: SeekFrom) -> io::Result<u64> {
304+
let (whence, offset) = match pos {
305+
// Casting to `i64` is fine, too large values will end up as
306+
// negative which will cause an error in `sys_seek`.
307+
SeekFrom::Start(off) => (SeekWhence::Start, off as i64),
308+
SeekFrom::Current(off) => (SeekWhence::Current, off),
309+
SeekFrom::End(off) => (SeekWhence::End, off),
310+
};
311+
312+
let seek = emerald_std::io::SeekFrom { whence, offset };
313+
314+
unsafe {
315+
emerald_std::io::syscall_seek(self.fd.as_raw_fd(), seek).map_err(syscall_to_io_error)
316+
}
305317
}
306318

307319
pub fn duplicate(&self) -> io::Result<File> {

0 commit comments

Comments
 (0)