Update.
[glibc.git] / sysdeps / posix / defs.c
blob7fe19085312490a00fee559cab239eb4b3fd559b
1 /* Definitions of global stdio data structures.
2 Copyright (C) 1991, 1993, 1997 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <stddef.h>
21 #include <stdio.h>
22 #include <unistd.h>
24 /* This file defines all the global internal variables for stdio. */
26 /* Standard streams. */
27 #define READ 1, 0
28 #define WRITE 0, 1
29 #define BUFFERED 0
30 #define UNBUFFERED 1
31 #define stdstream(name, next, fd, readwrite, unbuffered) \
32 { \
33 _IOMAGIC, \
34 NULL, NULL, NULL, NULL, 0, \
35 (void *) fd, \
36 { readwrite, /* ... */ }, \
37 { NULL, NULL, NULL, NULL, NULL }, \
38 { NULL, NULL }, \
39 -1, -1, \
40 (next), \
41 NULL, '\0', 0, \
42 0, 0, unbuffered, 0, 0, 0, 0 \
44 static FILE stdstreams[3] =
46 stdstream (&stdstreams[0], &stdstreams[1], STDIN_FILENO, READ, BUFFERED),
47 stdstream (&stdstreams[1], &stdstreams[2], STDOUT_FILENO, WRITE, BUFFERED),
48 stdstream (&stdstreams[2], NULL, STDERR_FILENO, WRITE, UNBUFFERED),
50 FILE *stdin = &stdstreams[0];
51 FILE *stdout = &stdstreams[1];
52 FILE *stderr = &stdstreams[2];
54 /* Pointer to the first stream in the list. */
55 FILE *__stdio_head = &stdstreams[0];
57 /* This function MUST be in this file!
58 This is because we want _cleanup to go into the __libc_atexit set
59 when any stdio code is used (and to use any stdio code, one must reference
60 something defined in this file), and since only local symbols can be made
61 set elements, having the set element stab entry here and _cleanup elsewhere
62 loses; and having them both elsewhere loses because there is no reference
63 to cause _cleanup to be linked in. */
65 void
66 _cleanup (void)
68 __fcloseall ();
72 #ifdef HAVE_GNU_LD
73 text_set_element(__libc_atexit, _cleanup);
74 #endif