From c4e1aa01152f5b0b9637b965604273a52f040323 Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Tue, 23 May 2000 23:51:54 +0000 Subject: * libc/stdio/stdio.c (__stextmode): new, see if file is text mode (__sread): always read in binary mode (__swrite): always write in binary mode * libc/include/stdio.h: no getc/putc macros for cygwin; causes compatibility issues with different dll versions * libc/stdio/fopen.c: use __stextmode * libc/stdio/fdopen.c: ditto * libc/stdio/freopen.c: ditto * libc/stdio/findfp.c: set up __SCLE for std{in,out,err} * libc/stdio/local.h: declare __stextmode --- newlib/libc/stdio/stdio.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'newlib/libc/stdio/stdio.c') diff --git a/newlib/libc/stdio/stdio.c b/newlib/libc/stdio/stdio.c index c06f51aa0..abb7c2335 100644 --- a/newlib/libc/stdio/stdio.c +++ b/newlib/libc/stdio/stdio.c @@ -37,8 +37,19 @@ __sread (cookie, buf, n) register FILE *fp = (FILE *) cookie; register int ret; +#ifdef __SCLE + int oldmode = 0; + if (fp->_flags & __SCLE) + oldmode = setmode(fp->_file, O_BINARY); +#endif + ret = _read_r (fp->_data, fp->_file, buf, n); +#ifdef __SCLE + if (oldmode) + setmode(fp->_file, oldmode); +#endif + /* If the read succeeded, update the current offset. */ if (ret >= 0) @@ -55,11 +66,25 @@ __swrite (cookie, buf, n) int n; { register FILE *fp = (FILE *) cookie; + int w, oldmode=0; if (fp->_flags & __SAPP) (void) _lseek_r (fp->_data, fp->_file, (off_t) 0, SEEK_END); fp->_flags &= ~__SOFF; /* in case O_APPEND mode is set */ - return _write_r (fp->_data, fp->_file, buf, n); + +#ifdef __SCLE + if (fp->_flags & __SCLE) + oldmode = setmode(fp->_file, O_BINARY); +#endif + + w = _write_r (fp->_data, fp->_file, buf, n); + +#ifdef __SCLE + if (oldmode) + setmode(fp->_file, oldmode); +#endif + + return w; } fpos_t @@ -90,3 +115,15 @@ __sclose (cookie) return _close_r (fp->_data, fp->_file); } + +#ifdef __SCLE +int +__stextmode (int fd) +{ +#ifdef __CYGWIN__ + return _cygwin_istext_for_stdio (fd); +#else + return 0; +#endif +} +#endif -- cgit v1.2.3