mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:47:45 +00:00
LibC: Add truncate().
Implemented in user space for now.
This commit is contained in:
parent
246e0e47ec
commit
9825f7792b
2 changed files with 14 additions and 0 deletions
|
@ -553,6 +553,19 @@ int ftruncate(int fd, off_t length)
|
||||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
__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()
|
int gettid()
|
||||||
{
|
{
|
||||||
if (!s_cached_tid)
|
if (!s_cached_tid)
|
||||||
|
|
|
@ -127,6 +127,7 @@ char* getlogin();
|
||||||
int chown(const char* pathname, uid_t, gid_t);
|
int chown(const char* pathname, uid_t, gid_t);
|
||||||
int fchown(int fd, uid_t, gid_t);
|
int fchown(int fd, uid_t, gid_t);
|
||||||
int ftruncate(int fd, off_t length);
|
int ftruncate(int fd, off_t length);
|
||||||
|
int truncate(const char* path, off_t length);
|
||||||
int halt();
|
int halt();
|
||||||
int reboot();
|
int reboot();
|
||||||
int mount(int source_fd, const char* target, const char* fs_type, int flags);
|
int mount(int source_fd, const char* target, const char* fs_type, int flags);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue