syscalls: ftruncate

This commit is contained in:
Matheus
2023-07-09 20:48:28 -03:00
parent 7a0bd0747e
commit 1259684ccf
4 changed files with 44 additions and 7 deletions
+27
View File
@@ -0,0 +1,27 @@
#include <kernel/syscalls.h>
syscallret_t syscall_ftruncate(int fd, size_t size) {
syscallret_t ret = {
.ret = -1
};
file_t *file = fd_get(fd);
if (file == NULL) {
ret.errno = EBADF;
return ret;
}
if ((file->flags & FILE_WRITE) == 0 || file->vnode->type != V_TYPE_REGULAR) {
ret.errno = EINVAL;
goto cleanup;
}
ret.errno = VOP_RESIZE(file->vnode, size, &_cpu()->thread->proc->cred);
ret.ret = ret.errno ? -1 : 0;
cleanup:
fd_release(file);
return ret;
}