From: cpg Date: Thu, 16 May 2002 15:25:48 +0000 (+0000) Subject: amode_to_bmode fixes: support "a", be more restrictive about the position X-Git-Tag: V2.12.0~2350 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e79d28567157e28b2a7076b9ac4b21ebee6dd091;p=cc65 amode_to_bmode fixes: support "a", be more restrictive about the position of the char (r, w, and a must appear as the first char only) git-svn-id: svn://svn.cc65.org/cc65/trunk@1271 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/libsrc/common/_fopen.c b/libsrc/common/_fopen.c index 3ae53a59b..88d01e7e3 100644 --- a/libsrc/common/_fopen.c +++ b/libsrc/common/_fopen.c @@ -19,23 +19,33 @@ static unsigned char amode_to_bmode (const char* mode) char flag = 0; unsigned char binmode = 0; + c = *mode++; + switch(c) { + case 'w': + binmode = O_WRONLY; + break; + case 'r': + binmode = O_RDONLY; + break; + case 'a': + binmode = O_WRONLY | O_APPEND; + break; + default: + return 0; /* invalid char */ + } + while (c = *mode++) { switch(c) { - case 'w': - binmode = O_WRONLY; - break; - case 'r': - binmode = O_RDONLY; - break; case '+': - binmode = O_RDWR; + binmode = (binmode & ~15) | O_RDWR; break; - /* a,b missing */ + case 'b': + /* currently ignored */ + break; + default: + return 0; /* invalid char */ } } - if (binmode == 0) { - _errno = EINVAL; - } return binmode; } @@ -50,7 +60,8 @@ FILE* _fopen (const char* name, const char* mode, FILE* f) /* Convert ASCII mode to binary mode */ if ((binmode = amode_to_bmode (mode)) == 0) { - /* Invalid mode, _errno already set */ + /* Invalid mode */ + _errno = EINVAL; return 0; }