1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 21:58:12 +00:00

LibC: Add truncate().

Implemented in user space for now.
This commit is contained in:
Nico Weber 2020-06-15 11:28:42 -04:00 committed by Andreas Kling
parent 246e0e47ec
commit 9825f7792b
2 changed files with 14 additions and 0 deletions

View file

@ -553,6 +553,19 @@ int ftruncate(int fd, off_t length)
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int truncate(const char* path, off_t length)
{
int fd = open(path, O_RDWR | O_CREAT, 0666);
if (fd < 0)
return fd;
int rc = ftruncate(fd, length);
int saved_errno = errno;
if (int close_rc = close(fd); close_rc < 0)
return close_rc;
errno = saved_errno;
return rc;
}
int gettid()
{
if (!s_cached_tid)