From 8a042a220d825a248ff3ab663023d4bcb1ba2d32 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 25 Nov 2018 14:34:18 -0700 Subject: [PATCH] Implement pread, add more poll constants --- src/header/poll/mod.rs | 4 ++++ src/header/unistd/mod.rs | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/header/poll/mod.rs b/src/header/poll/mod.rs index fab03b382d..47c2b655ef 100644 --- a/src/header/poll/mod.rs +++ b/src/header/poll/mod.rs @@ -6,6 +6,10 @@ use platform::{Pal, Sys}; pub const POLLIN: c_short = 0x001; pub const POLLPRI: c_short = 0x002; pub const POLLOUT: c_short = 0x004; +pub const POLLERR: c_short = 0x008; +pub const POLLHUP: c_short = 0x010; +pub const POLLNVAL: c_short = 0x020; + pub type nfds_t = c_ulong; diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 3cf2e16bd3..4573d4d854 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -387,9 +387,25 @@ pub unsafe extern "C" fn pipe(fildes: *mut c_int) -> c_int { Sys::pipe(slice::from_raw_parts_mut(fildes, 2)) } -// #[no_mangle] +#[no_mangle] pub extern "C" fn pread(fildes: c_int, buf: *mut c_void, nbyte: size_t, offset: off_t) -> ssize_t { - unimplemented!(); + //TODO: better pread using system calls + + let previous = lseek(fildes, offset, SEEK_SET); + if previous == -1 { + return -1; + } + + let res = read(fildes, buf, nbyte); + if res < 0 { + return res; + } + + if lseek(fildes, previous, SEEK_SET) == -1 { + return -1; + } + + res } // #[no_mangle]