source: trunk/libs/newlib/src/newlib/libc/stdio/fwalk.c @ 471

Last change on this file since 471 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.5 KB
Line 
1/*
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)
20static 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
30int
31_fwalk (struct _reent *ptr,
32       register int (*function) (FILE *))
33{
34  register FILE *fp;
35  register int n, ret = 0;
36  register struct _glue *g;
37
38  /*
39   * It should be safe to walk the list without locking it;
40   * new nodes are only added to the end and none are ever
41   * removed.
42   *
43   * Avoid locking this list while walking it or else you will
44   * introduce a potential deadlock in [at least] refill.c.
45   */
46  for (g = &ptr->__sglue; g != NULL; g = g->_next)
47    for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++)
48      if (fp->_flags != 0 && fp->_flags != 1 && fp->_file != -1)
49        ret |= (*function) (fp);
50
51  return ret;
52}
53
54/* Special version of __fwalk where the function pointer is a reentrant
55   I/O function (e.g. _fclose_r).  */
56int
57_fwalk_reent (struct _reent *ptr,
58       register int (*reent_function) (struct _reent *, FILE *))
59{
60  register FILE *fp;
61  register int n, ret = 0;
62  register struct _glue *g;
63
64  /*
65   * It should be safe to walk the list without locking it;
66   * new nodes are only added to the end and none are ever
67   * removed.
68   *
69   * Avoid locking this list while walking it or else you will
70   * introduce a potential deadlock in [at least] refill.c.
71   */
72  for (g = &ptr->__sglue; g != NULL; g = g->_next)
73    for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++)
74      if (fp->_flags != 0 && fp->_flags != 1 && fp->_file != -1)
75        ret |= (*reent_function) (ptr, fp);
76
77  return ret;
78}
Note: See TracBrowser for help on using the repository browser.