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
Notes: sideshowbarker 2024-07-19 05:38:38 +09:00
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)

View file

@ -127,6 +127,7 @@ char* getlogin();
int chown(const char* pathname, uid_t, gid_t);
int fchown(int fd, uid_t, gid_t);
int ftruncate(int fd, off_t length);
int truncate(const char* path, off_t length);
int halt();
int reboot();
int mount(int source_fd, const char* target, const char* fs_type, int flags);