aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc/stdio
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2000-05-03 03:57:19 +0000
committerJeff Johnston <jjohnstn@redhat.com>2000-05-03 03:57:19 +0000
commit49d64538cd20abeabd5678b28db05da6fda5e17a (patch)
tree4414b704fdc406f7dd2a51bd436591ae10888b99 /newlib/libc/stdio
parenta939e045e7c300f401dd96596122d34511be289a (diff)
downloadnewlib-49d64538cd20abeabd5678b28db05da6fda5e17a.zip
newlib-49d64538cd20abeabd5678b28db05da6fda5e17a.tar.gz
newlib-49d64538cd20abeabd5678b28db05da6fda5e17a.tar.bz2
Tue May 02 23:45:48 2000 DJ Delorie <dj@cygnus.com>
* libc/include/stdio.h (FILE): define __SCLE for "convert line endings" for Cygwin. (__sgetc): convert line endings if needed (__sputc): ditto * libc/stdio/fdopen.c (_fdopen_r): Remember if we opened in text mode * libc/stdio/fopen.c (_fopen_r): ditto * libc/stdio/freopen.c (freopen): ditto * libc/stdio/fread.c (fread): perform CRLF conversions if __SCLE * libc/stdio/fvwrite.c (__sfvwrite): ditto
Diffstat (limited to 'newlib/libc/stdio')
-rw-r--r--newlib/libc/stdio/fdopen.c6
-rw-r--r--newlib/libc/stdio/fopen.c8
-rw-r--r--newlib/libc/stdio/fread.c58
-rw-r--r--newlib/libc/stdio/freopen.c6
-rw-r--r--newlib/libc/stdio/fvwrite.c21
5 files changed, 99 insertions, 0 deletions
diff --git a/newlib/libc/stdio/fdopen.c b/newlib/libc/stdio/fdopen.c
index 50698cb..65763b2 100644
--- a/newlib/libc/stdio/fdopen.c
+++ b/newlib/libc/stdio/fdopen.c
@@ -100,6 +100,12 @@ _DEFUN (_fdopen_r, (ptr, fd, mode),
fp->_write = __swrite;
fp->_seek = __sseek;
fp->_close = __sclose;
+
+#ifdef __SCLE
+ if (setmode(fp->_file, O_BINARY) == O_TEXT)
+ fp->_flags |= __SCLE;
+#endif
+
return fp;
}
diff --git a/newlib/libc/stdio/fopen.c b/newlib/libc/stdio/fopen.c
index 30aa54e..d54f46a 100644
--- a/newlib/libc/stdio/fopen.c
+++ b/newlib/libc/stdio/fopen.c
@@ -116,6 +116,9 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#include <stdio.h>
#include <errno.h>
#include "local.h"
+#ifdef __CYGWIN__
+#include <fcntl.h>
+#endif
FILE *
_DEFUN (_fopen_r, (ptr, file, mode),
@@ -149,6 +152,11 @@ _DEFUN (_fopen_r, (ptr, file, mode),
if (fp->_flags & __SAPP)
fseek (fp, 0, SEEK_END);
+#ifdef __SCLE
+ if (setmode(fp->_file, O_BINARY) == O_TEXT)
+ fp->_flags |= __SCLE;
+#endif
+
return fp;
}
diff --git a/newlib/libc/stdio/fread.c b/newlib/libc/stdio/fread.c
index 4de7ce2..c4c66b4 100644
--- a/newlib/libc/stdio/fread.c
+++ b/newlib/libc/stdio/fread.c
@@ -59,6 +59,55 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
#include <string.h>
#include "local.h"
+#ifdef __SCLE
+static size_t
+_DEFUN (crlf, (fp, buf, count, eof),
+ FILE * fp _AND
+ char * buf _AND
+ size_t count _AND
+ int eof)
+{
+ int newcount = 0, r;
+ char *s, *d, *e;
+
+ if (count == 0)
+ return 0;
+
+ e = buf + count;
+ for (s=d=buf; s<e-1; s++)
+ {
+ if (*s == '\r' && s[1] == '\n')
+ s++;
+ *d++ = *s;
+ }
+ if (s < e)
+ {
+ if (*s == '\r')
+ {
+ int c = __sgetc_raw(fp);
+ if (c == '\n')
+ *s = '\n';
+ else
+ ungetc(c, fp);
+ }
+ *d++ = *s++;
+ }
+
+
+ while (d < e)
+ {
+ r = getc(fp);
+ if (r == EOF)
+ return count - (e-d);
+ *d++ = r;
+ }
+
+ return count;
+
+}
+
+#endif
+
size_t
_DEFUN (fread, (buf, size, count, fp),
_PTR buf _AND
@@ -77,6 +126,7 @@ _DEFUN (fread, (buf, size, count, fp),
fp->_r = 0;
total = resid;
p = buf;
+
while (resid > (r = fp->_r))
{
(void) memcpy ((void *) p, (void *) fp->_p, (size_t) r);
@@ -87,11 +137,19 @@ _DEFUN (fread, (buf, size, count, fp),
if (__srefill (fp))
{
/* no more input: return partial result */
+#ifdef __SCLE
+ if (fp->_flags & __SCLE)
+ return crlf(fp, buf, total-resid, 1) / size;
+#endif
return (total - resid) / size;
}
}
(void) memcpy ((void *) p, (void *) fp->_p, resid);
fp->_r -= resid;
fp->_p += resid;
+#ifdef __SCLE
+ if (fp->_flags & __SCLE)
+ return crlf(fp, buf, total, 0) / size;
+#endif
return count;
}
diff --git a/newlib/libc/stdio/freopen.c b/newlib/libc/stdio/freopen.c
index a4ab965..a23b08a 100644
--- a/newlib/libc/stdio/freopen.c
+++ b/newlib/libc/stdio/freopen.c
@@ -147,5 +147,11 @@ _DEFUN (freopen, (file, mode, fp),
fp->_write = __swrite;
fp->_seek = __sseek;
fp->_close = __sclose;
+
+#ifdef __SCLE
+ if (setmode(fp->_file, O_BINARY) == O_TEXT)
+ fp->_flags |= __SCLE;
+#endif
+
return fp;
}
diff --git a/newlib/libc/stdio/fvwrite.c b/newlib/libc/stdio/fvwrite.c
index 00e758a..8e7d316 100644
--- a/newlib/libc/stdio/fvwrite.c
+++ b/newlib/libc/stdio/fvwrite.c
@@ -62,6 +62,27 @@ __sfvwrite (fp, uio)
iov = uio->uio_iov;
len = 0;
+
+#ifdef __SCLE
+ if (fp->_flags & __SCLE) /* text mode */
+ {
+ do
+ {
+ GETIOV (;);
+ while (len > 0)
+ {
+ if (putc(*p, fp) == EOF)
+ return EOF;
+ p++;
+ len--;
+ uio->uio_resid--;
+ }
+ }
+ while (uio->uio_resid > 0);
+ return 0;
+ }
+#endif
+
if (fp->_flags & __SNBF)
{
/*