diff options
-rw-r--r-- | kernel/fs/vfs.c | 6 | ||||
-rw-r--r-- | userland/libc/stdio/fopen.c | 5 |
2 files changed, 6 insertions, 5 deletions
diff --git a/kernel/fs/vfs.c b/kernel/fs/vfs.c index 25e2423..0d03dce 100644 --- a/kernel/fs/vfs.c +++ b/kernel/fs/vfs.c @@ -287,7 +287,11 @@ int vfs_open(const char *file, int flags, int mode) { } // FIXME: Maybe it is sometimes a TTY? - return vfs_create_fd(flags, mode, 0 /*is_tty*/, inode, NULL); + int rc = vfs_create_fd(flags, mode, 0 /*is_tty*/, inode, NULL); + if (flags & O_TRUNC) { + vfs_ftruncate(rc, 0); + } + return rc; } int vfs_close_process(process_t *p, int fd) { diff --git a/userland/libc/stdio/fopen.c b/userland/libc/stdio/fopen.c index fe0b5cf..38ccbf1 100644 --- a/userland/libc/stdio/fopen.c +++ b/userland/libc/stdio/fopen.c @@ -18,7 +18,7 @@ FILE *fopen(const char *pathname, const char *mode) { flag |= O_READ; break; case 'w': - flag |= O_WRITE; + flag |= O_WRITE | O_TRUNC; break; case 'a': flag |= O_APPEND; @@ -36,9 +36,6 @@ FILE *fopen(const char *pathname, const char *mode) { close(fd); return NULL; } - if(flag & O_WRITE) { - ftruncate(fd, 0); - } r->has_control_over_the_fd = 1; return r; } |