123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #include "_stdio.h"
- #ifndef __DO_LARGEFILE
- # define FILEDES_ARG (-1)
- #endif
- FILE *freopen(const char * __restrict filename, const char * __restrict mode,
- register FILE * __restrict stream)
- {
-
- unsigned short dynmode;
- register FILE *fp;
- __STDIO_AUTO_THREADLOCK_VAR;
- __STDIO_AUTO_THREADLOCK(stream);
- __STDIO_STREAM_VALIDATE(stream);
- __STDIO_OPENLIST_INC_USE;
-
-
- dynmode = (stream->__modeflags & (__FLAG_FREEBUF|__FLAG_FREEFILE));
- stream->__modeflags &= ~(__FLAG_FREEBUF|__FLAG_FREEFILE);
-
- if ((stream->__modeflags & (__FLAG_READONLY|__FLAG_WRITEONLY))
- != (__FLAG_READONLY|__FLAG_WRITEONLY)
- ) {
- fclose(stream);
-
- __STDIO_OPENLIST_DEC_DEL_CNT;
- }
- fp = _stdio_fopen(((intptr_t) filename), mode, stream, FILEDES_ARG);
- if (!fp) {
-
- stream->__modeflags = __FLAG_READONLY|__FLAG_WRITEONLY|__FLAG_FAILED_FREOPEN;
- }
-
- stream->__modeflags |= dynmode;
- __STDIO_OPENLIST_DEC_USE;
- __STDIO_AUTO_THREADUNLOCK(stream);
- return fp;
- }
|