diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 9b9fbb00b..1d3ce7444 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,41 @@ +2013-10-23 Corinna Vinschen + + * libc/include/stdio.h (funopen): Change prototype of + __readfn and __writefn parameter to match new definition of + FILE's _read and _write methods. + (_funopen_r): Ditto. + (funopen): Ditto. + (_funopen_r): Ditto. + * libc/include/sys/config.h (_READ_WRITE_BUFSIZE_TYPE) Define + as type int if not already defined. Add comment to explain. + * libc/include/sys/reent.h: Include stddef.h. + (struct __sFILE): Change type of last parameter in declaration + of _read and _write methods to _READ_WRITE_BUFSIZE_TYPE. + (struct __sFILE64): Ditto. + * libc/stdio/local.h (__sread): Declare with last parameter set + to _READ_WRITE_BUFSIZE_TYPE. + (__seofread): Ditto. + (__swrite): Ditto. + (__swrite64): Ditto. + * libc/stdio/fvwrite.c (__sfvwrite_r): Change type of local + variables w and s to _READ_WRITE_RETURN_TYPE. + * libc/stdio/fflush.c (__sflush_r): Change type of local variables + n and t to _READ_WRITE_BUFSIZE_TYPE and _READ_WRITE_RETURN_TYPE. + Add local variables flags to keep _flags value. + * libc/stdio/fmemopen.c (fmemreader): Align to above change. + (fmemwriter): Ditto. + * libc/stdio/fopencookie.c (fcreader): Ditto. + (fcwriter): Ditto. + * libc/stdio/funopen.c (funread): Ditto. + (funwrite): Ditto. + (funreader): Ditto. + (funwriter): Ditto. + * libc/stdio/open_memstream.c (memwriter): Ditto. + * libc/stdio/stdio.c (__sread): Ditto. + (__seofread): Ditto. + (__swrite): Ditto. + * libc/stdio64/stdio64.c (__swrite64): Ditto. + 2013-10-18 Joey Ye * configure.in (enable-newlib-global-atexit): New option. diff --git a/newlib/libc/include/stdio.h b/newlib/libc/include/stdio.h index 504e671b0..20064d17e 100644 --- a/newlib/libc/include/stdio.h +++ b/newlib/libc/include/stdio.h @@ -516,24 +516,32 @@ int _EXFUN(__swbuf_r, (struct _reent *, int, FILE *)); #ifndef __STRICT_ANSI__ # ifdef __LARGE64_FILES FILE *_EXFUN(funopen,(const _PTR __cookie, - int (*__readfn)(_PTR __c, char *__buf, int __n), - int (*__writefn)(_PTR __c, const char *__buf, int __n), + int (*__readfn)(_PTR __c, char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), + int (*__writefn)(_PTR __c, const char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), _fpos64_t (*__seekfn)(_PTR __c, _fpos64_t __off, int __whence), int (*__closefn)(_PTR __c))); FILE *_EXFUN(_funopen_r,(struct _reent *, const _PTR __cookie, - int (*__readfn)(_PTR __c, char *__buf, int __n), - int (*__writefn)(_PTR __c, const char *__buf, int __n), + int (*__readfn)(_PTR __c, char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), + int (*__writefn)(_PTR __c, const char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), _fpos64_t (*__seekfn)(_PTR __c, _fpos64_t __off, int __whence), int (*__closefn)(_PTR __c))); # else FILE *_EXFUN(funopen,(const _PTR __cookie, - int (*__readfn)(_PTR __cookie, char *__buf, int __n), - int (*__writefn)(_PTR __cookie, const char *__buf, int __n), + int (*__readfn)(_PTR __cookie, char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), + int (*__writefn)(_PTR __cookie, const char *__buf + _READ_WRITE_BUFSIZE_TYPE __n), fpos_t (*__seekfn)(_PTR __cookie, fpos_t __off, int __whence), int (*__closefn)(_PTR __cookie))); FILE *_EXFUN(_funopen_r,(struct _reent *, const _PTR __cookie, - int (*__readfn)(_PTR __cookie, char *__buf, int __n), - int (*__writefn)(_PTR __cookie, const char *__buf, int __n), + int (*__readfn)(_PTR __cookie, char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), + int (*__writefn)(_PTR __cookie, const char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), fpos_t (*__seekfn)(_PTR __cookie, fpos_t __off, int __whence), int (*__closefn)(_PTR __cookie))); # endif /* !__LARGE64_FILES */ diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h index c726e14c9..0de3ffb88 100644 --- a/newlib/libc/include/sys/config.h +++ b/newlib/libc/include/sys/config.h @@ -250,6 +250,12 @@ #ifndef _READ_WRITE_RETURN_TYPE #define _READ_WRITE_RETURN_TYPE int #endif +/* Define `count' parameter of read/write routines. In POSIX, the `count' + parameter is "size_t" but legacy newlib code has been using "int" for some + time. If not specified, "int" is defaulted. */ +#ifndef _READ_WRITE_BUFSIZE_TYPE +#define _READ_WRITE_BUFSIZE_TYPE int +#endif #ifndef __WCHAR_MAX__ #if __INT_MAX__ == 32767 || defined (_WIN32) diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h index c8ef6302f..ce5b3eda7 100644 --- a/newlib/libc/include/sys/reent.h +++ b/newlib/libc/include/sys/reent.h @@ -11,6 +11,7 @@ extern "C" { #define _SYS_REENT_H_ #include <_ansi.h> +#include #include #define _NULL 0 @@ -192,9 +193,10 @@ struct __sFILE { _PTR _cookie; /* cookie passed to io functions */ _READ_WRITE_RETURN_TYPE _EXFNPTR(_read, (struct _reent *, _PTR, - char *, int)); + char *, _READ_WRITE_BUFSIZE_TYPE)); _READ_WRITE_RETURN_TYPE _EXFNPTR(_write, (struct _reent *, _PTR, - const char *, int)); + const char *, + _READ_WRITE_BUFSIZE_TYPE)); _fpos_t _EXFNPTR(_seek, (struct _reent *, _PTR, _fpos_t, int)); int _EXFNPTR(_close, (struct _reent *, _PTR)); @@ -247,9 +249,10 @@ struct __sFILE64 { _PTR _cookie; /* cookie passed to io functions */ _READ_WRITE_RETURN_TYPE _EXFNPTR(_read, (struct _reent *, _PTR, - char *, int)); + char *, _READ_WRITE_BUFSIZE_TYPE)); _READ_WRITE_RETURN_TYPE _EXFNPTR(_write, (struct _reent *, _PTR, - const char *, int)); + const char *, + _READ_WRITE_BUFSIZE_TYPE)); _fpos_t _EXFNPTR(_seek, (struct _reent *, _PTR, _fpos_t, int)); int _EXFNPTR(_close, (struct _reent *, _PTR)); diff --git a/newlib/libc/stdio/fflush.c b/newlib/libc/stdio/fflush.c index ee24cf7ca..ea48b0126 100644 --- a/newlib/libc/stdio/fflush.c +++ b/newlib/libc/stdio/fflush.c @@ -75,10 +75,12 @@ _DEFUN(__sflush_r, (ptr, fp), register FILE * fp) { register unsigned char *p; - register int n, t; + register _READ_WRITE_BUFSIZE_TYPE n; + register _READ_WRITE_RETURN_TYPE t; + short flags; - t = fp->_flags; - if ((t & __SWR) == 0) + flags = fp->_flags; + if ((flags & __SWR) == 0) { #ifdef _FSEEK_OPTIMIZATION /* For a read stream, an fflush causes the next seek to be @@ -186,7 +188,7 @@ _DEFUN(__sflush_r, (ptr, fp), * write function. */ fp->_p = p; - fp->_w = t & (__SLBF | __SNBF) ? 0 : fp->_bf._size; + fp->_w = flags & (__SLBF | __SNBF) ? 0 : fp->_bf._size; while (n > 0) { diff --git a/newlib/libc/stdio/fmemopen.c b/newlib/libc/stdio/fmemopen.c index acfb23c1b..44b0c6d1d 100644 --- a/newlib/libc/stdio/fmemopen.c +++ b/newlib/libc/stdio/fmemopen.c @@ -87,7 +87,7 @@ _DEFUN(fmemreader, (ptr, cookie, buf, n), struct _reent *ptr _AND void *cookie _AND char *buf _AND - int n) + _READ_WRITE_BUFSIZE_TYPE n) { fmemcookie *c = (fmemcookie *) cookie; /* Can't read beyond current size, but EOF condition is not an error. */ @@ -107,7 +107,7 @@ _DEFUN(fmemwriter, (ptr, cookie, buf, n), struct _reent *ptr _AND void *cookie _AND const char *buf _AND - int n) + _READ_WRITE_BUFSIZE_TYPE n) { fmemcookie *c = (fmemcookie *) cookie; int adjust = 0; /* true if at EOF, but still need to write NUL. */ diff --git a/newlib/libc/stdio/fopencookie.c b/newlib/libc/stdio/fopencookie.c index f08d13289..588fd4879 100644 --- a/newlib/libc/stdio/fopencookie.c +++ b/newlib/libc/stdio/fopencookie.c @@ -101,7 +101,7 @@ _DEFUN(fcreader, (ptr, cookie, buf, n), struct _reent *ptr _AND void *cookie _AND char *buf _AND - int n) + _READ_WRITE_BUFSIZE_TYPE n) { int result; fccookie *c = (fccookie *) cookie; @@ -116,7 +116,7 @@ _DEFUN(fcwriter, (ptr, cookie, buf, n), struct _reent *ptr _AND void *cookie _AND const char *buf _AND - int n) + _READ_WRITE_BUFSIZE_TYPE n) { int result; fccookie *c = (fccookie *) cookie; diff --git a/newlib/libc/stdio/funopen.c b/newlib/libc/stdio/funopen.c index 065ed93d7..e71d23187 100644 --- a/newlib/libc/stdio/funopen.c +++ b/newlib/libc/stdio/funopen.c @@ -85,8 +85,9 @@ Supporting OS subroutines required: <>. #include #include "local.h" -typedef int (*funread)(void *_cookie, char *_buf, int _n); -typedef int (*funwrite)(void *_cookie, const char *_buf, int _n); +typedef int (*funread)(void *_cookie, char *_buf, _READ_WRITE_BUFSIZE_TYPE _n); +typedef int (*funwrite)(void *_cookie, const char *_buf, + _READ_WRITE_BUFSIZE_TYPE _n); #ifdef __LARGE64_FILES typedef _fpos64_t (*funseek)(void *_cookie, _fpos64_t _off, int _whence); #else @@ -107,7 +108,7 @@ _DEFUN(funreader, (ptr, cookie, buf, n), struct _reent *ptr _AND void *cookie _AND char *buf _AND - int n) + _READ_WRITE_BUFSIZE_TYPE n) { int result; funcookie *c = (funcookie *) cookie; @@ -122,7 +123,7 @@ _DEFUN(funwriter, (ptr, cookie, buf, n), struct _reent *ptr _AND void *cookie _AND const char *buf _AND - int n) + _READ_WRITE_BUFSIZE_TYPE n) { int result; funcookie *c = (funcookie *) cookie; diff --git a/newlib/libc/stdio/fvwrite.c b/newlib/libc/stdio/fvwrite.c index 384c62ce0..36a467845 100644 --- a/newlib/libc/stdio/fvwrite.c +++ b/newlib/libc/stdio/fvwrite.c @@ -52,7 +52,7 @@ _DEFUN(__sfvwrite_r, (ptr, fp, uio), register size_t len; register _CONST char *p = NULL; register struct __siov *iov; - register int w, s; + register _READ_WRITE_RETURN_TYPE w, s; char *nl; int nlknown, nldist; diff --git a/newlib/libc/stdio/local.h b/newlib/libc/stdio/local.h index 54854b49d..0bd47a46a 100644 --- a/newlib/libc/stdio/local.h +++ b/newlib/libc/stdio/local.h @@ -149,11 +149,13 @@ extern int _EXFUN(__sflags,(struct _reent *,_CONST char*, int*)); extern int _EXFUN(__sflush_r,(struct _reent *,FILE *)); extern int _EXFUN(__srefill_r,(struct _reent *,FILE *)); extern _READ_WRITE_RETURN_TYPE _EXFUN(__sread,(struct _reent *, void *, char *, - int)); + _READ_WRITE_BUFSIZE_TYPE)); extern _READ_WRITE_RETURN_TYPE _EXFUN(__seofread,(struct _reent *, void *, - char *, int)); + char *, + _READ_WRITE_BUFSIZE_TYPE)); extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite,(struct _reent *, void *, - const char *, int)); + const char *, + _READ_WRITE_BUFSIZE_TYPE)); extern _fpos_t _EXFUN(__sseek,(struct _reent *, void *, _fpos_t, int)); extern int _EXFUN(__sclose,(struct _reent *, void *)); extern int _EXFUN(__stextmode,(int)); @@ -168,7 +170,8 @@ extern int _EXFUN(__submore, (struct _reent *, FILE *)); #ifdef __LARGE64_FILES extern _fpos64_t _EXFUN(__sseek64,(struct _reent *, void *, _fpos64_t, int)); extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite64,(struct _reent *, void *, - const char *, int)); + const char *, + _READ_WRITE_BUFSIZE_TYPE)); #endif /* Called by the main entry point fns to ensure stdio has been initialized. */ diff --git a/newlib/libc/stdio/open_memstream.c b/newlib/libc/stdio/open_memstream.c index 0b58720a1..e33063b7c 100644 --- a/newlib/libc/stdio/open_memstream.c +++ b/newlib/libc/stdio/open_memstream.c @@ -97,7 +97,7 @@ _DEFUN(memwriter, (ptr, cookie, buf, n), struct _reent *ptr _AND void *cookie _AND const char *buf _AND - int n) + _READ_WRITE_BUFSIZE_TYPE n) { memstream *c = (memstream *) cookie; char *cbuf = *c->pbuf; diff --git a/newlib/libc/stdio/stdio.c b/newlib/libc/stdio/stdio.c index 31b787bf8..a6e28f5a9 100644 --- a/newlib/libc/stdio/stdio.c +++ b/newlib/libc/stdio/stdio.c @@ -34,10 +34,10 @@ _DEFUN(__sread, (ptr, cookie, buf, n), struct _reent *ptr _AND void *cookie _AND char *buf _AND - int n) + _READ_WRITE_BUFSIZE_TYPE n) { register FILE *fp = (FILE *) cookie; - register int ret; + register ssize_t ret; #ifdef __SCLE int oldmode = 0; @@ -67,7 +67,7 @@ _DEFUN(__seofread, (ptr, cookie, buf, len), struct _reent *_ptr _AND _PTR cookie _AND char *buf _AND - int len) + _READ_WRITE_BUFSIZE_TYPE len) { return 0; } @@ -77,10 +77,10 @@ _DEFUN(__swrite, (ptr, cookie, buf, n), struct _reent *ptr _AND void *cookie _AND char const *buf _AND - int n) + _READ_WRITE_BUFSIZE_TYPE n) { register FILE *fp = (FILE *) cookie; - int w; + ssize_t w; #ifdef __SCLE int oldmode=0; #endif diff --git a/newlib/libc/stdio64/stdio64.c b/newlib/libc/stdio64/stdio64.c index f33a394a7..dd3b4adc9 100644 --- a/newlib/libc/stdio64/stdio64.c +++ b/newlib/libc/stdio64/stdio64.c @@ -51,10 +51,10 @@ _DEFUN(__swrite64, (ptr, cookie, buf, n), struct _reent *ptr _AND void *cookie _AND char const *buf _AND - int n) + _READ_WRITE_BUFSIZE_TYPE n) { register FILE *fp = (FILE *) cookie; - int w; + _READ_WRITE_RETURN_TYPE w; #ifdef __SCLE int oldmode=0; #endif