From a3c83367251b814e394748bbdfd684f52e7c7f64 Mon Sep 17 00:00:00 2001 From: cuz Date: Fri, 15 Nov 2002 23:52:39 +0000 Subject: [PATCH] Fix open flags, minor optimization git-svn-id: svn://svn.cc65.org/cc65/trunk@1526 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/common/_fopen.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/libsrc/common/_fopen.c b/libsrc/common/_fopen.c index 88d01e7e3..a81c2358a 100644 --- a/libsrc/common/_fopen.c +++ b/libsrc/common/_fopen.c @@ -15,14 +15,11 @@ static unsigned char amode_to_bmode (const char* mode) /* Convert ASCII mode (like for fopen) to binary mode (for open) */ { - char c; - char flag = 0; - unsigned char binmode = 0; + unsigned char binmode; - c = *mode++; - switch(c) { + switch (*mode++) { case 'w': - binmode = O_WRONLY; + binmode = O_WRONLY | O_CREAT | O_TRUNC; break; case 'r': binmode = O_RDONLY; @@ -34,19 +31,23 @@ static unsigned char amode_to_bmode (const char* mode) return 0; /* invalid char */ } - while (c = *mode++) { - switch(c) { + while (1) { + switch (*mode++) { case '+': - binmode = (binmode & ~15) | O_RDWR; + /* always to r/w in addition to anything already set */ + binmode |= O_RDWR; break; case 'b': /* currently ignored */ break; + case '\0': + /* end of mode string reached */ + return binmode; default: - return 0; /* invalid char */ + /* invalid char in mode string */ + return 0; } } - return binmode; } -- 2.39.5