diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2004-04-08 22:26:50 +0000 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2004-04-08 22:26:50 +0000 |
commit | 47dcaf565d2d1001f7644e4f619ffc06fe753f1d (patch) | |
tree | 990ab07dbe60414e36d2bce99e2e5de94544c0c2 /newlib/libc/stdio/fwalk.c | |
parent | 4121d8cf68e69c4569be2be0fb31c68ab0e6f847 (diff) | |
download | newlib-47dcaf565d2d1001f7644e4f619ffc06fe753f1d.zip newlib-47dcaf565d2d1001f7644e4f619ffc06fe753f1d.tar.gz newlib-47dcaf565d2d1001f7644e4f619ffc06fe753f1d.tar.bz2 |
2004-04-08 Artem B. Bityuckiy <abitytsky@softminecorp.com>
* libc/stdio/fclose.c (_fclose_r): New function.
* libc/stdio/freopen.c (_freopen_r): Call _fclose_r.
* libc/stdio/fcloseall.c (_fcloseall_r): Call _fwalk_reent.
* libc/stdio64/freopen64.c (_freopen64_r): Use _fclose_r.
* libc/include/stdio.h (_fclose_r): New prototype.
* libc/stdio/fopen.c: Fix typo in comment.
2004-04-08 Jeff Johnston <jjohnstn@redhat.com>
* libc/stdio/fwalk.c (_fwalk_reent): New version of _fwalk
to handle _r reentrant functions.
Diffstat (limited to 'newlib/libc/stdio/fwalk.c')
-rw-r--r-- | newlib/libc/stdio/fwalk.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/newlib/libc/stdio/fwalk.c b/newlib/libc/stdio/fwalk.c index 566fa4a..02a8970 100644 --- a/newlib/libc/stdio/fwalk.c +++ b/newlib/libc/stdio/fwalk.c @@ -48,6 +48,30 @@ __fwalk (ptr, function) return ret; } +/* Special version of __fwalk where the function pointer is a reentrant + I/O function (e.g. _fclose_r). */ +static int +__fwalk_reent (ptr, reent_function) + struct _reent *ptr; + register int (*reent_function) (); +{ + register FILE *fp; + register int n, ret = 0; + register struct _glue *g; + + for (g = &ptr->__sglue; g != NULL; g = g->_next) + for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++) + if (fp->_flags != 0) + { + _flockfile (fp); + if (fp->_flags != 0 && fp->_file != -1) + ret |= (*reent_function) (ptr, fp); + _funlockfile (fp); + } + + return ret; +} + int _fwalk (ptr, function) struct _reent *ptr; @@ -68,3 +92,26 @@ _fwalk (ptr, function) return ret; } + +/* Special version of _fwalk which handles a function pointer to a + reentrant I/O function (e.g. _fclose_r). */ +int +_fwalk_reent (ptr, reent_function) + struct _reent *ptr; + register int (*reent_function) (); +{ + register int ret = 0; + + __sfp_lock_acquire (); + + /* Must traverse given list for std streams. */ + if (ptr != _GLOBAL_REENT) + ret |= __fwalk_reent (ptr, reent_function); + + /* Must traverse global list for all other streams. */ + ret |= __fwalk_reent (_GLOBAL_REENT, reent_function); + + __sfp_lock_release (); + + return ret; +} |