summaryrefslogtreecommitdiffstats
path: root/newlib/libc/include
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2007-06-04 18:10:17 +0000
committerEric Blake <eblake@redhat.com>2007-06-04 18:10:17 +0000
commit17c61d6a2c4868260c1ef3043e03f86de14f6a08 (patch)
treec795768b8f7d0fa0048f5bd77f6dad9c5ce069e1 /newlib/libc/include
parent6a3b4eb69a7d2b1e1c19a8baef42ce6dc3d61a86 (diff)
downloadcygnal-17c61d6a2c4868260c1ef3043e03f86de14f6a08.tar.gz
cygnal-17c61d6a2c4868260c1ef3043e03f86de14f6a08.tar.bz2
cygnal-17c61d6a2c4868260c1ef3043e03f86de14f6a08.zip
Implement funopen, fopencookie.
* libc/include/sys/reent.h (struct __sFILE, struct __sFILE64): Switch to reentrant callbacks. * libc/include/stdio.h (funopen): Fix declaration. (fopencookie): Declare. * libc/stdio/local.h (__sread, __swrite, __sseek, __sclose) (__sseek64, __swrite64): Fix prototypes. [__SCLE]: Pull in setmode declaration. * libc/stdio/stdio.c (__sread, __swrite, __sseek, __sclose): Fix reentrancy. * libc/stdio64/stdio64.c (__sseek64_r, __swrite64_r): Delete. (__sseek64, __swrite64): Fix reentrancy. * libc/stdio/fseek.c (_fseek_r): Account for overflow, and fix reentrancy. * libc/stdio/ftell.c (_ftell_r): Likewise. * libc/stdio/flags.c (__sflags): Don't lose __SAPP on "a+". * libc/stdio/fclose.c (_fclose_r): Fix reentrancy. * libc/stdio/freopen.c (_freopen_r): Likewise. * libc/stdio/fvwrite.c (__sfvwrite_r): Likewise. * libc/stdio/refill.c (__srefill_r): Likewise. * libc/stdio/siscanf.c (eofread): Likewise. * libc/stdio/sscanf.c (eofread): Likewise. * libc/stdio/vsiscanf.c (eofread1): Likewise. * libc/stdio/vsscanf.c (eofread1): Likewise. * libc/stdio64/freopen64.c (_freopen64_r): Likewise. * libc/stdio64/fseeko64.c (_fseeko64_r): Likewise. * libc/stdio64/ftello64.c (_ftello64_r): Likewise. * libc/stdio/fflush.c (fflush): Improve reentrancy, although more could be fixed. * libc/stdio/fopencookie.c (_fopencookie_r, fopencookie): New file. * libc/stdio/funopen.c (_funopen_r, funopen): New file. * libc/stdio/Makefile.am (ELIX_4_SOURCES, CHEWOUT_FILES): Build new files. * libc/stdio/Makefile.in: Regenerate.
Diffstat (limited to 'newlib/libc/include')
-rw-r--r--newlib/libc/include/stdio.h52
-rw-r--r--newlib/libc/include/sys/reent.h26
2 files changed, 57 insertions, 21 deletions
diff --git a/newlib/libc/include/stdio.h b/newlib/libc/include/stdio.h
index 7c5247021..babb1c3c5 100644
--- a/newlib/libc/include/stdio.h
+++ b/newlib/libc/include/stdio.h
@@ -467,7 +467,7 @@ int _EXFUN(_fsetpos64_r, (struct _reent *, FILE *, const _fpos64_t *));
FILE * _EXFUN(_tmpfile64_r, (struct _reent *));
#endif /* !__CYGWIN__ */
#endif /* __LARGE64_FILES */
-
+
/*
* Routines internal to the implementation.
*/
@@ -480,15 +480,47 @@ int _EXFUN(__swbuf_r, (struct _reent *, int, FILE *));
*/
#ifndef __STRICT_ANSI__
-FILE *_EXFUN(funopen,(const _PTR _cookie,
- int (*readfn)(_PTR _cookie, char *_buf, int _n),
- int (*writefn)(_PTR _cookie, const char *_buf, int _n),
- fpos_t (*seekfn)(_PTR _cookie, fpos_t _off, int _whence),
- int (*closefn)(_PTR _cookie)));
-
-#define fropen(cookie, fn) funopen(cookie, fn, (int (*)())0, (fpos_t (*)())0, (int (*)())0)
-#define fwopen(cookie, fn) funopen(cookie, (int (*)())0, fn, (fpos_t (*)())0, (int (*)())0)
-#endif
+# 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),
+ _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),
+ fpos_t (*__seekfn)(_PTR __cookie, fpos_t __off, int __whence),
+ int (*__closefn)(_PTR __cookie)));
+# endif /* !__LARGE64_FILES */
+
+# define fropen(__cookie, __fn) funopen(__cookie, __fn, (int (*)())0, \
+ (fpos_t (*)())0, (int (*)())0)
+# define fwopen(__cookie, __fn) funopen(__cookie, (int (*)())0, __fn, \
+ (fpos_t (*)())0, (int (*)())0)
+
+typedef ssize_t cookie_read_function_t(void *__cookie, char *__buf, size_t __n);
+typedef ssize_t cookie_write_function_t(void *__cookie, const char *__buf,
+ size_t __n);
+# ifdef __LARGE64_FILES
+typedef int cookie_seek_function_t(void *__cookie, _off64_t *__off,
+ int __whence);
+# else
+typedef int cookie_seek_function_t(void *__cookie, off_t *__off, int __whence);
+# endif /* !__LARGE64_FILES */
+typedef int cookie_close_function_t(void *__cookie);
+typedef struct
+{
+ /* These four struct member names are dictated by Linux; hopefully,
+ they don't conflict with any macros. */
+ cookie_read_function_t *read;
+ cookie_write_function_t *write;
+ cookie_seek_function_t *seek;
+ cookie_close_function_t *close;
+} cookie_io_functions_t;
+FILE *_EXFUN(fopencookie,(void *__cookie, const char *__mode,
+ cookie_io_functions_t __functions));
+#endif /* ! __STRICT_ANSI__ */
#ifndef __CUSTOM_FILE_IO__
/*
diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h
index 93c79ffc7..06d025bb5 100644
--- a/newlib/libc/include/sys/reent.h
+++ b/newlib/libc/include/sys/reent.h
@@ -34,6 +34,8 @@ typedef unsigned __Long __ULong;
typedef __uint32_t __ULong;
#endif
+struct _reent;
+
/*
* If _REENT_SMALL is defined, we make struct _reent as small as possible,
* by having nearly everything possible allocated at first use.
@@ -181,11 +183,12 @@ struct __sFILE {
/* operations */
_PTR _cookie; /* cookie passed to io functions */
- _READ_WRITE_RETURN_TYPE _EXFUN((*_read),(_PTR _cookie, char *_buf, int _n));
- _READ_WRITE_RETURN_TYPE _EXFUN((*_write),(_PTR _cookie, const char *_buf,
- int _n));
- _fpos_t _EXFUN((*_seek),(_PTR _cookie, _fpos_t _offset, int _whence));
- int _EXFUN((*_close),(_PTR _cookie));
+ _READ_WRITE_RETURN_TYPE _EXFUN((*_read),(struct _reent *, _PTR,
+ char *, int));
+ _READ_WRITE_RETURN_TYPE _EXFUN((*_write),(struct _reent *, _PTR,
+ const char *, int));
+ _fpos_t _EXFUN((*_seek),(struct _reent *, _PTR, _fpos_t, int));
+ int _EXFUN((*_close),(struct _reent *, _PTR));
/* separate buffer for long sequences of ungetc() */
struct __sbuf _ub; /* ungetc buffer */
@@ -233,11 +236,12 @@ struct __sFILE64 {
/* operations */
_PTR _cookie; /* cookie passed to io functions */
- _READ_WRITE_RETURN_TYPE _EXFUN((*_read),(_PTR _cookie, char *_buf, int _n));
- _READ_WRITE_RETURN_TYPE _EXFUN((*_write),(_PTR _cookie, const char *_buf,
- int _n));
- _fpos_t _EXFUN((*_seek),(_PTR _cookie, _fpos_t _offset, int _whence));
- int _EXFUN((*_close),(_PTR _cookie));
+ _READ_WRITE_RETURN_TYPE _EXFUN((*_read),(struct _reent *, _PTR,
+ char *, int));
+ _READ_WRITE_RETURN_TYPE _EXFUN((*_write),(struct _reent *, _PTR,
+ const char *, int));
+ _fpos_t _EXFUN((*_seek),(struct _reent *, _PTR, _fpos_t, int));
+ int _EXFUN((*_close),(struct _reent *, _PTR));
/* separate buffer for long sequences of ungetc() */
struct __sbuf _ub; /* ungetc buffer */
@@ -256,7 +260,7 @@ struct __sFILE64 {
int _flags2; /* for future use */
_off64_t _offset; /* current lseek offset */
- _fpos64_t _EXFUN((*_seek64),(_PTR _cookie, _fpos64_t _offset, int _whence));
+ _fpos64_t _EXFUN((*_seek64),(struct _reent *, _PTR, _fpos64_t, int));
#ifndef __SINGLE_THREAD__
_flock_t _lock; /* for thread-safety locking */