scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 04c2a5d9a2b8473046e076f810ff087af02e9ef6
parent 3a48fd7f02df7f7d660beb7b4227c07cc7bf6c89
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Mon, 26 Feb 2018 13:48:24 +0100

libc: fopen(), allow for example r+b and rb+

Diffstat:
Mlib/c/_fpopen.c | 25++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/lib/c/_fpopen.c b/lib/c/_fpopen.c @@ -14,15 +14,26 @@ _fpopen(const char * restrict fname, flags = rw = bin = 0; - if (mode[0] == '\0) - goto einval; - if (mode[i = 1] == '+') - i++, rw = 1; - if (mode[i] == 'b') - i++, bin = 1; - if (mode[i] != '\0') + if (mode[0] == '\0') goto einval; + for (i = 1; mode[i]; ++i) { + switch (mode[i]) { + case '+': + if (rw) + goto einval; + rw = 1; + break; + case 'b': + if (bin) + goto einval; + bin = 1; + break; + default: + goto einval; + } + } + switch (mode[0]) { case 'a': flags |= O_APPEND | O_CREAT;