diff options
author | Manuel Novoa III <mjn3@codepoet.org> | 2004-01-02 09:21:33 +0000 |
---|---|---|
committer | Manuel Novoa III <mjn3@codepoet.org> | 2004-01-02 09:21:33 +0000 |
commit | be5aabf5344c5f797fffa3c3ae9347d02ad6cd2e (patch) | |
tree | d4cb2a9ce62d27a69ccd607701d5276fd4482fb0 /libc/stdio | |
parent | 95a70af5e7511d09d525487aa8f4cb417865ba7d (diff) |
Fix __freadable and __fwritable... were using '~' instead of '!'. (ugh)
Fix (hopefully) a potential problem with failed freopen() calls. The
fix isn't tested since I've been working on the replacement stdio
core code which will go in after the next release.
Diffstat (limited to 'libc/stdio')
-rw-r--r-- | libc/stdio/stdio.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/libc/stdio/stdio.c b/libc/stdio/stdio.c index 281dc5bf5..1bdccbfe9 100644 --- a/libc/stdio/stdio.c +++ b/libc/stdio/stdio.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002 Manuel Novoa III +/* Copyright (C) 2002,2003,2004 Manuel Novoa III * My stdio library for linux and (soon) elks. * * This library is free software; you can redistribute it and/or @@ -80,6 +80,12 @@ * * Nov 17, 2003 * Fix the return value for fputs when passed an empty string. + * + * Jan 1, 2004 + * Fix __freadable and __fwritable... were using '~' instead of '!'. (ugh) + * Fix (hopefully) a potential problem with failed freopen() calls. The + * fix isn't tested since I've been working on the replacement stdio + * core code which will go in after the next release. */ /* Before we include anything, convert L_ctermid to L_ctermid_function @@ -984,7 +990,7 @@ int __fwriting(FILE * __restrict stream) int __freadable(FILE * __restrict stream) { - return ~(stream->modeflags & __FLAG_WRITEONLY); + return !(stream->modeflags & __FLAG_WRITEONLY); } #endif @@ -995,7 +1001,7 @@ int __freadable(FILE * __restrict stream) int __fwritable(FILE * __restrict stream) { - return ~(stream->modeflags & __FLAG_READONLY); + return !(stream->modeflags & __FLAG_READONLY); } #endif @@ -2352,9 +2358,6 @@ FILE *_stdio_fopen(const char * __restrict filename, open_mode = (O_WRONLY | O_CREAT | O_APPEND); if (*mode != 'a') { /* not write (create or append) */ __set_errno(EINVAL); /* then illegal mode */ - if (stream) { /* If this is freopen, free the stream. */ - goto FREE_STREAM; - } return NULL; } } @@ -2450,7 +2453,6 @@ FILE *_stdio_fopen(const char * __restrict filename, } if (stream->filedes < 0) { - FREE_STREAM: #ifdef __STDIO_BUFFERS if (stream->modeflags & __FLAG_FREEBUF) { free(stream->bufstart); @@ -2543,8 +2545,8 @@ FILE *freopen(const char * __restrict filename, const char * __restrict mode, * supports this, so we don't here. * * NOTE: Whether or not the stream is free'd on failure is unclear - * w.r.t. ANSI/ISO. This implementation chooses to free the - * stream and associated buffer if they were dynamically + * w.r.t. ANSI/ISO. This implementation chooses to NOT free + * the stream and associated buffer if they were dynamically * allocated. * TODO: Check the above. * TODO: Apparently linux allows setting append mode. Implement? @@ -2564,10 +2566,11 @@ FILE *freopen(const char * __restrict filename, const char * __restrict mode, stream->modeflags &= ~(__FLAG_FREEBUF|__FLAG_FREEFILE); fclose(stream); /* Failures are ignored. */ - stream->modeflags = dynmode; fp = _stdio_fopen(filename, mode, stream, -1); + stream->modeflags |= dynmode; + __STDIO_THREADUNLOCK(stream); return fp; |