LibC: Implement truncate

This commit is contained in:
2025-06-01 05:07:15 +03:00
parent b75970958e
commit 31bcad2535
4 changed files with 14 additions and 4 deletions

View File

@@ -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) \

View File

@@ -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)