123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- use types::*;
- const AT_FDCWD: c_int = -100;
- pub fn brk(addr: *const c_void) -> c_int {
- unsafe {
- let newbrk = syscall!(BRK, addr);
- if newbrk < addr as usize {
- -1
- } else {
- 0
- }
- }
- }
- pub fn chdir(path: *const c_char) -> c_int {
- unsafe { syscall!(CHDIR, path) as c_int }
- }
- pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int {
- unsafe { syscall!(CHOWN, owner as u32, group as u32) as c_int }
- }
- pub fn close(fildes: c_int) -> c_int {
- unsafe { syscall!(CLOSE, fildes) as c_int }
- }
- pub fn dup(fildes: c_int) -> c_int {
- unsafe { syscall!(DUP, fildes) as c_int }
- }
- pub fn dup2(fildes: c_int, fildes2: c_int) -> c_int {
- unsafe { syscall!(DUP2, fildes, fildes2) as c_int }
- }
- pub fn exit(status: c_int) -> ! {
- unsafe {
- syscall!(EXIT, status);
- }
- loop {}
- }
- pub fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int {
- unsafe { syscall!(FCHOWN, fildes, owner, group) as c_int }
- }
- pub fn fchdir(fildes: c_int) -> c_int {
- unsafe { syscall!(FCHDIR, fildes) as c_int }
- }
- pub fn fsync(fildes: c_int) -> c_int {
- unsafe { syscall!(FSYNC, fildes) as c_int }
- }
- pub fn ftruncate(fildes: c_int, length: off_t) -> c_int {
- unsafe { syscall!(FTRUNCATE, fildes, length) as c_int }
- }
- pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char {
- unsafe {
- syscall!(GETCWD, buf, size);
- buf as *mut c_char
- }
- }
- pub fn getegid() -> gid_t {
- unsafe { syscall!(GETEGID) }
- }
- pub fn geteuid() -> uid_t {
- unsafe { syscall!(GETEUID) }
- }
- pub fn getgid() -> gid_t {
- unsafe { syscall!(GETGID) }
- }
- pub fn getpgid(pid: pid_t) -> pid_t {
- unsafe { syscall!(GETPGID, pid) }
- }
- pub fn getpid() -> pid_t {
- unsafe { syscall!(GETPID) }
- }
- pub fn getppid() -> pid_t {
- unsafe { syscall!(GETPPID) }
- }
- pub fn getuid() -> uid_t {
- unsafe { syscall!(GETUID) }
- }
- pub fn link(path1: *const c_char, path2: *const c_char) -> c_int {
- unsafe { syscall!(LINK, path1, path2) as c_int }
- }
- #[cfg(target_arch = "x86_64")]
- pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
- unsafe { syscall!(OPEN, path, oflag, mode) as c_int }
- }
- #[cfg(target_arch = "aarch64")]
- pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
- unsafe { syscall!(OPENAT, AT_FDCWD, path, oflag, mode) as c_int }
- }
- pub fn write(fildes: c_int, buf: &[u8]) -> ssize_t {
- unsafe { syscall!(WRITE, fildes, buf.as_ptr(), buf.len()) as ssize_t }
- }
|