From 2cdc815322af6c7c22b9ceb371d9c7b2a4853c0e Mon Sep 17 00:00:00 2001 From: dzwdz Date: Fri, 29 Jul 2022 19:06:23 +0200 Subject: syscall/write: WRITE_TRUNCATE --- src/user/lib/file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/user/lib/file.c') 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; -- cgit v1.2.3