Implement pread, add more poll constants

This commit is contained in:
Jeremy Soller
2018-11-25 14:34:18 -07:00
parent 869eb160bd
commit 8a042a220d
2 changed files with 22 additions and 2 deletions
+4
View File
@@ -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;
+18 -2
View File
@@ -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]