OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [newlib-1.18.0/] [newlib/] [libc/] [stdio/] [fwalk.c] - Blame information for rev 829

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/*
2
 * Copyright (c) 1990 The Regents of the University of California.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms are permitted
6
 * provided that the above copyright notice and this paragraph are
7
 * duplicated in all such forms and that any documentation,
8
 * advertising materials, and other materials related to such
9
 * distribution and use acknowledge that the software was developed
10
 * by the University of California, Berkeley.  The name of the
11
 * University may not be used to endorse or promote products derived
12
 * from this software without specific prior written permission.
13
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16
 */
17
/* No user fns here.  Pesch 15apr92. */
18
 
19
#if defined(LIBC_SCCS) && !defined(lint)
20
static char sccsid[] = "%W% (Berkeley) %G%";
21
#endif /* LIBC_SCCS and not lint */
22
 
23
#include <_ansi.h>
24
#include <reent.h>
25
#include <stdio.h>
26
#include <stdlib.h>
27
#include <errno.h>
28
#include "local.h"
29
 
30
static int
31
_DEFUN(__fwalk, (ptr, function),
32
       struct _reent *ptr _AND
33
       register int (*function) (FILE *))
34
{
35
  register FILE *fp;
36
  register int n, ret = 0;
37
  register struct _glue *g;
38
 
39
  for (g = &ptr->__sglue; g != NULL; g = g->_next)
40
    for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++)
41
      if (fp->_flags != 0)
42
        {
43
          if (fp->_flags != 0 && fp->_file != -1)
44
            ret |= (*function) (fp);
45
        }
46
 
47
  return ret;
48
}
49
 
50
/* Special version of __fwalk where the function pointer is a reentrant
51
   I/O function (e.g. _fclose_r).  */
52
static int
53
_DEFUN(__fwalk_reent, (ptr, reent_function),
54
       struct _reent *ptr _AND
55
       register int (*reent_function) (struct _reent *, FILE *))
56
{
57
  register FILE *fp;
58
  register int n, ret = 0;
59
  register struct _glue *g;
60
 
61
  for (g = &ptr->__sglue; g != NULL; g = g->_next)
62
    for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++)
63
      if (fp->_flags != 0)
64
        {
65
          if (fp->_flags != 0 && fp->_file != -1)
66
            ret |= (*reent_function) (ptr, fp);
67
        }
68
 
69
  return ret;
70
}
71
 
72
int
73
_DEFUN(_fwalk, (ptr, function),
74
       struct _reent *ptr _AND
75
       register int (*function)(FILE *))
76
{
77
  register int ret = 0;
78
 
79
  __sfp_lock_acquire ();
80
 
81
  /* Must traverse given list for streams.  Note that _GLOBAL_REENT
82
     only walked once in exit().  */
83
  ret |= __fwalk (ptr, function);
84
 
85
  __sfp_lock_release ();
86
 
87
  return ret;
88
}
89
 
90
/* Special version of _fwalk which handles a function pointer to a
91
   reentrant I/O function (e.g. _fclose_r).  */
92
int
93
_DEFUN(_fwalk_reent, (ptr, reent_function),
94
       struct _reent *ptr _AND
95
       register int (*reent_function) (struct _reent *, FILE *))
96
{
97
  register int ret = 0;
98
 
99
  __sfp_lock_acquire ();
100
 
101
  /* Must traverse given list for streams.  Note that _GLOBAL_REENT
102
     only walked once in exit().  */
103
  ret |= __fwalk_reent (ptr, reent_function);
104
 
105
  __sfp_lock_release ();
106
 
107
  return ret;
108
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.