LibC: Implement truncate
This commit is contained in:
@@ -74,7 +74,7 @@ __BEGIN_DECLS
|
||||
O(SYS_LISTEN, listen) \
|
||||
O(SYS_PSELECT, pselect) \
|
||||
O(SYS_PPOLL, ppoll) \
|
||||
O(SYS_TRUNCATE, truncate) \
|
||||
O(SYS_FTRUNCATE, ftruncate) \
|
||||
O(SYS_SMO_CREATE, smo_create) \
|
||||
O(SYS_SMO_DELETE, smo_delete) \
|
||||
O(SYS_SMO_MAP, smo_map) \
|
||||
|
||||
@@ -157,9 +157,19 @@ off_t lseek(int fildes, off_t offset, int whence)
|
||||
return syscall(SYS_SEEK, fildes, offset, whence);
|
||||
}
|
||||
|
||||
int truncate(const char* path, off_t length)
|
||||
{
|
||||
const int fd = open(path, O_WRONLY);
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
int ret = ftruncate(fd, length);
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ftruncate(int fildes, off_t length)
|
||||
{
|
||||
return syscall(SYS_TRUNCATE, fildes, length);
|
||||
return syscall(SYS_FTRUNCATE, fildes, length);
|
||||
}
|
||||
|
||||
int fsync(int fildes)
|
||||
|
||||
Reference in New Issue
Block a user