1 /* Definitions of global stdio data structures.
3 Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If
18 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19 Cambridge, MA 02139, USA. */
26 FILE *stdin
, *stdout
, *stderr
;
28 /* Pointer to the first stream in the list. */
29 FILE *__stdio_head
= NULL
;
34 inline void init (FILE **streamptr
, int fd
)
36 /* We want to use the existing FILE object if one has been allocated.
37 (This will only be the case if our image came from something like
38 Emacs's unexec, where we were called in the first run.) */
39 FILE *s
= *streamptr
?: __newstream ();
40 struct hurd_fd
*d
= _hurd_fd_get (fd
);
43 /* There is no file descriptor allocated. We want the standard
44 streams to always refer to their standard file descriptors, even
45 if those descriptors are not set up until later. So allocate
46 the descriptor structure with no ports and store it in the
47 stream. Operations will fail until ports are installed in the
49 if (d
= _hurd_alloc_fd (NULL
, fd
))
50 __spin_unlock (&d
->port
.lock
);
56 #define S(NAME, FD, MODE) \
57 init (&NAME, FD); if (NAME) NAME->__mode.__##MODE = 1;
59 S (stdin
, STDIN_FILENO
, read
);
60 S (stdout
, STDOUT_FILENO
, write
);
61 S (stderr
, STDERR_FILENO
, write
);
66 stderr
->__userbuf
= 1; /* stderr is always unbuffered. */
68 (void) &init_stdio
; /* Avoid "defined but not used" warning. */
70 text_set_element (_hurd_fd_subinit
, init_stdio
);
72 /* This function MUST be in this file!
73 This is because we want _cleanup to go into the __libc_atexit set
74 when any stdio code is used (and to use any stdio code, one must reference
75 something defined in this file), and since only local symbols can be made
76 set elements, having the set element stab entry here and _cleanup elsewhere
77 loses; and having them both elsewhere loses because there is no reference
78 to cause _cleanup to be linked in. */
83 (void) fclose ((FILE *) NULL
);
85 text_set_element (__libc_atexit
, _cleanup
);