summaryrefslogtreecommitdiff
path: root/src/user/lib/file.c
diff options
context:
space:
mode:
authordzwdz2022-07-29 19:06:23 +0200
committerdzwdz2022-07-29 19:06:23 +0200
commit2cdc815322af6c7c22b9ceb371d9c7b2a4853c0e (patch)
tree98023777a62a533a3ac1d68ef99bcdd8bbee685e /src/user/lib/file.c
parenta658e1068eb2f849736931d2b99bcb6290c7ec0a (diff)
syscall/write: WRITE_TRUNCATE
Diffstat (limited to 'src/user/lib/file.c')
-rw-r--r--src/user/lib/file.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/user/lib/file.c b/src/user/lib/file.c
index b7e70e6..bd8cb76 100644
--- a/src/user/lib/file.c
+++ b/src/user/lib/file.c
@@ -17,13 +17,16 @@ FILE *fopen(const char *path, const char *mode) {
int flags = 0;
if (mode[0] == 'w' || mode[0] == 'a')
flags |= OPEN_CREATE;
- // TODO truncate on w
h = _syscall_open(path, strlen(path), flags);
if (h < 0) {
errno = -h;
return NULL;
}
+
+ if (mode[0] == 'w')
+ _syscall_write(h, NULL, 0, 0, WRITE_TRUNCATE);
+
f = fdopen(h, mode);
if (!f) close(h);
return f;