Browse Source
This isn't complete yet, but subsequent steps will depend on Rust libstd and libc bindings changes that are in flight.pull/1984/head
Dan Gohman
4 years ago
committed by
Jakub Konka
9 changed files with 108 additions and 7 deletions
@ -0,0 +1,23 @@ |
|||
use crate::from_success_code; |
|||
use std::io::Result; |
|||
use std::os::wasi::prelude::*; |
|||
|
|||
#[derive(Debug, Copy, Clone)] |
|||
#[repr(i32)] |
|||
pub enum PosixFadviseAdvice { |
|||
Normal = libc::POSIX_FADV_NORMAL, |
|||
Sequential = libc::POSIX_FADV_SEQUENTIAL, |
|||
Random = libc::POSIX_FADV_RANDOM, |
|||
NoReuse = libc::POSIX_FADV_NOREUSE, |
|||
WillNeed = libc::POSIX_FADV_WILLNEED, |
|||
DontNeed = libc::POSIX_FADV_DONTNEED, |
|||
} |
|||
|
|||
pub unsafe fn posix_fadvise( |
|||
fd: RawFd, |
|||
offset: libc::off_t, |
|||
len: libc::off_t, |
|||
advice: PosixFadviseAdvice, |
|||
) -> Result<()> { |
|||
from_success_code(libc::posix_fadvise(fd, offset, len, advice as libc::c_int)) |
|||
} |
@ -0,0 +1,21 @@ |
|||
use std::{ |
|||
io::{Error, Result}, |
|||
os::wasi::prelude::*, |
|||
}; |
|||
|
|||
pub unsafe fn isatty(fd: RawFd) -> Result<bool> { |
|||
let res = libc::isatty(fd); |
|||
if res == 1 { |
|||
// isatty() returns 1 if fd is an open file descriptor referring to a terminal...
|
|||
Ok(true) |
|||
} else { |
|||
// ... otherwise 0 is returned, and errno is set to indicate the error.
|
|||
let errno = Error::last_os_error(); |
|||
let raw_errno = errno.raw_os_error().unwrap(); |
|||
if raw_errno == libc::ENOTTY { |
|||
Ok(false) |
|||
} else { |
|||
Err(errno) |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,33 @@ |
|||
use crate::filetime::FileTime; |
|||
use crate::from_success_code; |
|||
use std::fs::File; |
|||
use std::io; |
|||
|
|||
pub fn utimensat( |
|||
dirfd: &File, |
|||
path: &str, |
|||
atime: FileTime, |
|||
mtime: FileTime, |
|||
symlink_nofollow: bool, |
|||
) -> io::Result<()> { |
|||
use crate::filetime::to_timespec; |
|||
use std::ffi::CString; |
|||
use std::os::wasi::prelude::*; |
|||
|
|||
let p = CString::new(path.as_bytes())?; |
|||
let times = [to_timespec(&atime)?, to_timespec(&mtime)?]; |
|||
let flags = if symlink_nofollow { |
|||
libc::AT_SYMLINK_NOFOLLOW |
|||
} else { |
|||
0 |
|||
}; |
|||
|
|||
from_success_code(unsafe { |
|||
libc::utimensat( |
|||
dirfd.as_raw_fd() as libc::c_int, |
|||
p.as_ptr(), |
|||
times.as_ptr(), |
|||
flags, |
|||
) |
|||
}) |
|||
} |
@ -0,0 +1,3 @@ |
|||
pub(crate) mod fadvise; |
|||
pub(crate) mod file; |
|||
pub(crate) mod filetime; |
Loading…
Reference in new issue