Merge remote-tracking branch 'origin/truncate-n-mkfifo'
This commit is contained in:
@@ -5,7 +5,7 @@ use core::{convert::TryFrom, mem, ptr, slice};
|
||||
use crate::{
|
||||
c_str::CStr,
|
||||
header::{
|
||||
errno, limits, stdlib::getenv, sys_ioctl, sys_time, sys_utsname, termios, time::timespec,
|
||||
errno, fcntl, limits, stdlib::getenv, sys_ioctl, sys_time, sys_utsname, termios, time::timespec,
|
||||
},
|
||||
platform::{self, types::*, Pal, Sys},
|
||||
};
|
||||
@@ -649,9 +649,19 @@ pub extern "C" fn tcsetpgrp(fd: c_int, pgrp: pid_t) -> c_int {
|
||||
pgrp
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn truncate(path: *const c_char, length: off_t) -> c_int {
|
||||
unimplemented!();
|
||||
let file = unsafe { CStr::from_ptr(path) };
|
||||
let fd = Sys::open(file, fcntl::O_WRONLY, 0);
|
||||
if fd < 0 {
|
||||
return -1;
|
||||
}
|
||||
|
||||
let res = ftruncate(fd, length);
|
||||
|
||||
Sys::close(fd);
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
||||
Reference in New Issue
Block a user