Closed pfusik closed 3 months ago
Looking at the code:
static unsigned filemode(const char *const mode) { unsigned rc = 0; switch (mode[0]) { case 'r': rc |= FREAD; break; case 'w': rc |= FWRITE; break; case 'a': rc |= FAPPEND | FWRITE; break; }
static signed char stdio_open(const char *const filename, unsigned int mode) { int osmode; if (mode & FRW) osmode = O_RDWR; else if (mode & FREAD) osmode = O_RDONLY; else osmode = O_WRONLY; if (mode & (FWRITE | FAPPEND)) osmode |= O_CREAT; if (mode & FWRITE) osmode |= mode & FEXCL ? O_EXCL : O_TRUNC; else if (mode & FAPPEND) osmode |= O_APPEND;
"a" will set O_TRUNC i.e. truncate an existing file. I think we should either not set FWRITE or reorganize the logic in stdio_open.
"a"
O_TRUNC
FWRITE
stdio_open
Looking at the code:
"a"
will setO_TRUNC
i.e. truncate an existing file. I think we should either not setFWRITE
or reorganize the logic instdio_open
.