Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDJ Delorie <dj@redhat.com>2000-05-24 03:51:54 +0400
committerDJ Delorie <dj@redhat.com>2000-05-24 03:51:54 +0400
commitc4e1aa01152f5b0b9637b965604273a52f040323 (patch)
treec96b9c34d59d4aee60caf3a9e671130bf2fa7b39 /newlib/libc
parent98c6450eaa8cec6ea0243f3305143d77dfcb3d07 (diff)
* 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
Diffstat (limited to 'newlib/libc')
-rw-r--r--newlib/libc/include/stdio.h2
-rw-r--r--newlib/libc/stdio/fdopen.c2
-rw-r--r--newlib/libc/stdio/findfp.c6
-rw-r--r--newlib/libc/stdio/fopen.c2
-rw-r--r--newlib/libc/stdio/freopen.c2
-rw-r--r--newlib/libc/stdio/local.h1
-rw-r--r--newlib/libc/stdio/stdio.c39
7 files changed, 50 insertions, 4 deletions
diff --git a/newlib/libc/include/stdio.h b/newlib/libc/include/stdio.h
index 44c8d3c14..2a14f90b8 100644
--- a/newlib/libc/include/stdio.h
+++ b/newlib/libc/include/stdio.h
@@ -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)
diff --git a/newlib/libc/stdio/fdopen.c b/newlib/libc/stdio/fdopen.c
index 65763b221..a335c3fa1 100644
--- a/newlib/libc/stdio/fdopen.c
+++ b/newlib/libc/stdio/fdopen.c
@@ -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
diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
index 9dd18996d..64abb1c6b 100644
--- a/newlib/libc/stdio/findfp.c
+++ b/newlib/libc/stdio/findfp.c
@@ -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 *
diff --git a/newlib/libc/stdio/fopen.c b/newlib/libc/stdio/fopen.c
index d54f46af6..e4708785d 100644
--- a/newlib/libc/stdio/fopen.c
+++ b/newlib/libc/stdio/fopen.c
@@ -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
diff --git a/newlib/libc/stdio/freopen.c b/newlib/libc/stdio/freopen.c
index a23b08ad5..63f583375 100644
--- a/newlib/libc/stdio/freopen.c
+++ b/newlib/libc/stdio/freopen.c
@@ -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
diff --git a/newlib/libc/stdio/local.h b/newlib/libc/stdio/local.h
index 71e80cc09..24e02e8e4 100644
--- a/newlib/libc/stdio/local.h
+++ b/newlib/libc/stdio/local.h
@@ -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 *));
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