mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibC: Add truncate().
Implemented in user space for now.
This commit is contained in:
parent
246e0e47ec
commit
9825f7792b
Notes:
sideshowbarker
2024-07-19 05:38:38 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/9825f7792b4 Pull-request: https://github.com/SerenityOS/serenity/pull/2559
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);
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue