diff options
Diffstat (limited to 'newlib/libc/stdio/findfp.c')
-rw-r--r-- | newlib/libc/stdio/findfp.c | 148 |
1 files changed, 36 insertions, 112 deletions
diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c index e3270af38..0ea7e31a2 100644 --- a/newlib/libc/stdio/findfp.c +++ b/newlib/libc/stdio/findfp.c @@ -1,3 +1,5 @@ +/* No user fns here. Pesch 15apr92. */ + /* * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. @@ -14,10 +16,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -/* No user fns here. Pesch 15apr92. */ -#include <_ansi.h> -#include <reent.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> @@ -26,12 +25,12 @@ #include <sys/lock.h> #include "local.h" -static _VOID -_DEFUN(std, (ptr, flags, file, data), - FILE *ptr _AND - int flags _AND - int file _AND - struct _reent *data) +static void +std (ptr, flags, file, data) + FILE *ptr; + int flags; + int file; + struct _reent *data; { ptr->_p = 0; ptr->_r = 0; @@ -46,24 +45,20 @@ _DEFUN(std, (ptr, flags, file, data), ptr->_write = __swrite; ptr->_seek = __sseek; ptr->_close = __sclose; -#if !defined(__SINGLE_THREAD__) && !defined(_REENT_SMALL) - __lock_init_recursive (ptr->_lock); - /* - * #else - * lock is already initialized in __sfp - */ +#ifndef __SINGLE_THREAD__ + __lock_init_recursive (*(_LOCK_RECURSIVE_T *)&ptr->_lock); #endif #ifdef __SCLE - if (__stextmode (ptr->_file)) + if (__stextmode(ptr->_file)) ptr->_flags |= __SCLE; #endif } struct _glue * -_DEFUN(__sfmoreglue, (d, n), - struct _reent *d _AND - register int n) +__sfmoreglue (d, n) + struct _reent *d; + register int n; { struct _glue *g; FILE *p; @@ -84,14 +79,18 @@ _DEFUN(__sfmoreglue, (d, n), */ FILE * -_DEFUN(__sfp, (d), - struct _reent *d) +__sfp (d) + struct _reent *d; { FILE *fp; int n; struct _glue *g; - __sfp_lock_acquire (); +#ifndef __SINGLE_THREAD__ + __LOCK_INIT(static, lock); + + __lock_acquire(lock); +#endif if (!_GLOBAL_REENT->__sdidinit) __sinit (_GLOBAL_REENT); @@ -104,24 +103,24 @@ _DEFUN(__sfp, (d), (g->_next = __sfmoreglue (d, NDYNAMIC)) == NULL) break; } - __sfp_lock_release (); +#ifndef __SINGLE_THREAD__ + __lock_release(lock); +#endif d->_errno = ENOMEM; return NULL; found: - fp->_file = -1; /* no file */ fp->_flags = 1; /* reserve this slot; caller sets real flags */ #ifndef __SINGLE_THREAD__ - __lock_init_recursive (fp->_lock); + __lock_release(lock); #endif - __sfp_lock_release (); - fp->_p = NULL; /* no current pointer */ fp->_w = 0; /* nothing to read or write */ fp->_r = 0; fp->_bf._base = NULL; /* no buffer */ fp->_bf._size = 0; fp->_lbfsize = 0; /* not line buffered */ + fp->_file = -1; /* no file */ /* fp->_cookie = <any>; */ /* caller sets cookie, _read/_write etc */ fp->_ub._base = NULL; /* no ungetc buffer */ fp->_ub._size = 0; @@ -139,17 +138,17 @@ found: * The name `_cleanup' is, alas, fairly well known outside stdio. */ -_VOID -_DEFUN(_cleanup_r, (ptr), - struct _reent *ptr) +void +_cleanup_r (ptr) + struct _reent *ptr; { - _CAST_VOID _fwalk(ptr, fclose); - /* _CAST_VOID _fwalk (ptr, fflush); */ /* `cheating' */ + /* (void) _fwalk(fclose); */ + (void) _fwalk (ptr, fflush); /* `cheating' */ } #ifndef _REENT_ONLY -_VOID -_DEFUN_VOID(_cleanup) +void +_cleanup () { _cleanup_r (_GLOBAL_REENT); } @@ -159,18 +158,10 @@ _DEFUN_VOID(_cleanup) * __sinit() is called whenever stdio's internal variables must be set up. */ -_VOID -_DEFUN(__sinit, (s), - struct _reent *s) +void +__sinit (s) + struct _reent *s; { - __sinit_lock_acquire (); - - if (s->__sdidinit) - { - __sinit_lock_release (); - return; - } - /* make sure we clean up on exit */ s->__cleanup = _cleanup_r; /* conservative */ s->__sdidinit = 1; @@ -200,71 +191,4 @@ _DEFUN(__sinit, (s), std (s->_stderr, __SWR | __SNBF, 2, s); - __sinit_lock_release (); -} - -#ifndef __SINGLE_THREAD__ - -__LOCK_INIT_RECURSIVE(static, __sfp_lock); -__LOCK_INIT_RECURSIVE(static, __sinit_lock); - -_VOID -_DEFUN_VOID(__sfp_lock_acquire) -{ - __lock_acquire_recursive (__sfp_lock); -} - -_VOID -_DEFUN_VOID(__sfp_lock_release) -{ - __lock_release_recursive (__sfp_lock); -} - -_VOID -_DEFUN_VOID(__sinit_lock_acquire) -{ - __lock_acquire_recursive (__sinit_lock); -} - -_VOID -_DEFUN_VOID(__sinit_lock_release) -{ - __lock_release_recursive (__sinit_lock); -} - -/* Walkable file locking routine. */ -static int -_DEFUN(__fp_lock, (ptr), - FILE * ptr) -{ - _flockfile (ptr); - - return 0; -} - -/* Walkable file unlocking routine. */ -static int -_DEFUN(__fp_unlock, (ptr), - FILE * ptr) -{ - _funlockfile (ptr); - - return 0; -} - -_VOID -_DEFUN_VOID(__fp_lock_all) -{ - __sfp_lock_acquire (); - - _CAST_VOID _fwalk (_REENT, __fp_lock); -} - -_VOID -_DEFUN_VOID(__fp_unlock_all) -{ - _CAST_VOID _fwalk (_REENT, __fp_unlock); - - __sfp_lock_release (); } -#endif |