Update.
[glibc.git] / sysdeps / posix / defs.c
blobbc0d34bf15a8bea79603e8410623710e84180451
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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 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 ()
68 __fcloseall ();
72 #ifdef HAVE_GNU_LD
73 text_set_element(__libc_atexit, _cleanup);
74 #endif