* 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
This commit is contained in:
parent
98c6450eaa
commit
c4e1aa0115
|
@ -1,3 +1,16 @@
|
|||
2000-05-19 DJ Delorie <dj@cygnus.com>
|
||||
|
||||
* 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
|
||||
|
||||
2000-05-18 DJ Delorie <dj@cygnus.com>
|
||||
|
||||
* libc/stdio/fgets.c (fgets): perform CRLF conversions if __SCLE
|
||||
|
|
|
@ -318,10 +318,12 @@ static __inline int __sputc(int _c, FILE *_p) {
|
|||
#define fileno(p) __sfileno(p)
|
||||
#endif
|
||||
|
||||
#ifndef __CYGWIN__
|
||||
#ifndef lint
|
||||
#define getc(fp) __sgetc(fp)
|
||||
#define putc(x, fp) __sputc(x, fp)
|
||||
#endif /* lint */
|
||||
#endif /* __CYGWIN__ */
|
||||
|
||||
#define getchar() getc(stdin)
|
||||
#define putchar(x) putc(x, stdout)
|
||||
|
|
|
@ -102,7 +102,7 @@ _DEFUN (_fdopen_r, (ptr, fd, mode),
|
|||
fp->_close = __sclose;
|
||||
|
||||
#ifdef __SCLE
|
||||
if (setmode(fp->_file, O_BINARY) == O_TEXT)
|
||||
if (__stextmode(fp->_file))
|
||||
fp->_flags |= __SCLE;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include "local.h"
|
||||
|
||||
static void
|
||||
|
@ -44,6 +45,11 @@ std (ptr, flags, file, data)
|
|||
ptr->_seek = __sseek;
|
||||
ptr->_close = __sclose;
|
||||
ptr->_data = data;
|
||||
|
||||
#ifdef __SCLE
|
||||
if (__stextmode(ptr->_file))
|
||||
ptr->_flags |= __SCLE;
|
||||
#endif
|
||||
}
|
||||
|
||||
struct _glue *
|
||||
|
|
|
@ -153,7 +153,7 @@ _DEFUN (_fopen_r, (ptr, file, mode),
|
|||
fseek (fp, 0, SEEK_END);
|
||||
|
||||
#ifdef __SCLE
|
||||
if (setmode(fp->_file, O_BINARY) == O_TEXT)
|
||||
if (__stextmode (fp->_file))
|
||||
fp->_flags |= __SCLE;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ _DEFUN (freopen, (file, mode, fp),
|
|||
fp->_close = __sclose;
|
||||
|
||||
#ifdef __SCLE
|
||||
if (setmode(fp->_file, O_BINARY) == O_TEXT)
|
||||
if (__stextmode(fp->_file))
|
||||
fp->_flags |= __SCLE;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ extern int _EXFUN(__sread,(void *, char *, int));
|
|||
extern int _EXFUN(__swrite,(void *, char const *, int));
|
||||
extern fpos_t _EXFUN(__sseek,(void *, fpos_t, int));
|
||||
extern int _EXFUN(__sclose,(void *));
|
||||
extern int _EXFUN(__stextmode,(int));
|
||||
extern void _EXFUN(__sinit,(struct _reent *));
|
||||
extern void _EXFUN(_cleanup_r,(struct _reent *));
|
||||
extern void _EXFUN(__smakebuf,(FILE *));
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue