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
			
			
This commit is contained in:
		| @@ -1,3 +1,15 @@ | ||||
| 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 | ||||
|  | ||||
| Thu Apr 27 07:45:48 2000  Alexandre Oliva  <aoliva@cygnus.com> | ||||
|  | ||||
| 	* libc/machine/mn10300/setjmp.S (setjmp, longjmp): Use | ||||
|   | ||||
| @@ -66,6 +66,9 @@ typedef struct __sFILE FILE; | ||||
| #define	__SNPT	0x0800		/* do not do fseek() optimisation */ | ||||
| #define	__SOFF	0x1000		/* set iff _offset is in fact correct */ | ||||
| #define	__SMOD	0x2000		/* true => fgetline modified _p text */ | ||||
| #if defined(__CYGWIN__) || defined(__CYGWIN32__) | ||||
| #define __SCLE        0x4000          /* convert line endings CR/LF <-> NL */ | ||||
| #endif | ||||
|  | ||||
| /* | ||||
|  * The following three definitions are for ANSI C, which took them | ||||
| @@ -251,7 +254,26 @@ FILE	*_EXFUN(funopen,(const _PTR _cookie, | ||||
|  * The __sfoo macros are here so that we can  | ||||
|  * define function versions in the C library. | ||||
|  */ | ||||
| #define	__sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) | ||||
| #define       __sgetc_raw(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) | ||||
|  | ||||
| #ifdef __SCLE | ||||
| static __inline__ int __sgetc(FILE *__p) | ||||
|   { | ||||
|     int __c = __sgetc_raw(__p); | ||||
|     if ((__p->_flags & __SCLE) && (__c == '\r')) | ||||
|       { | ||||
|       int __c2 = __sgetc_raw(__p); | ||||
|       if (__c2 == '\n') | ||||
|         __c = __c2; | ||||
|       else | ||||
|         ungetc(__c2, __p); | ||||
|       } | ||||
|     return __c; | ||||
|   } | ||||
| #else | ||||
| #define __sgetc(p) __sgetc_raw(p) | ||||
| #endif | ||||
|  | ||||
| #ifdef _never /* __GNUC__ */ | ||||
| /* If this inline is actually used, then systems using coff debugging | ||||
|    info get hopelessly confused.  21sept93 rich@cygnus.com.  */ | ||||
| @@ -265,7 +287,7 @@ static __inline int __sputc(int _c, FILE *_p) { | ||||
| /* | ||||
|  * This has been tuned to generate reasonable code on the vax using pcc | ||||
|  */ | ||||
| #define	__sputc(c, p) \ | ||||
| #define       __sputc_raw(c, p) \ | ||||
| 	(--(p)->_w < 0 ? \ | ||||
| 		(p)->_w >= (p)->_lbfsize ? \ | ||||
| 			(*(p)->_p = (c)), *(p)->_p != '\n' ? \ | ||||
| @@ -273,6 +295,14 @@ static __inline int __sputc(int _c, FILE *_p) { | ||||
| 				__swbuf('\n', p) : \ | ||||
| 			__swbuf((int)(c), p) : \ | ||||
| 		(*(p)->_p = (c), (int)*(p)->_p++)) | ||||
| #ifdef __SCLE | ||||
| #define __sputc(c, p) \ | ||||
|         ((((p)->_flags & __SCLE) && ((c) == '\n')) \ | ||||
|           ? __sputc_raw('\r', (p)) : 0 , \ | ||||
|         __sputc_raw((c), (p))) | ||||
| #else | ||||
| #define __sputc(c, p) __sputc_raw(c, p) | ||||
| #endif | ||||
| #endif | ||||
|  | ||||
| #define	__sfeof(p)	(((p)->_flags & __SEOF) != 0) | ||||
|   | ||||
| @@ -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; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -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; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -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; | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
| } | ||||
|   | ||||
| @@ -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) | ||||
|     { | ||||
|       /* | ||||
|   | ||||
		Reference in New Issue
	
	Block a user