Mon May 6 09:51:05 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[glibc.git] / sysdeps / posix / defs.c
blobfcbaf16f69e60ac5c088bd1f44dc4416286c9fdc
1 /* Definitions of global stdio data structures.
3 Copyright (C) 1991, 1993 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. */
21 #include <ansidecl.h>
22 #include <stddef.h>
23 #include <stdio.h>
24 #include <unistd.h>
26 /* This file defines all the global internal variables for stdio. */
28 /* Standard streams. */
29 #define READ 1, 0
30 #define WRITE 0, 1
31 #define BUFFERED 0
32 #define UNBUFFERED 1
33 #define stdstream(name, next, fd, readwrite, unbuffered) \
34 { \
35 _IOMAGIC, \
36 NULL, NULL, NULL, NULL, 0, \
37 (PTR) fd, \
38 { readwrite, /* ... */ }, \
39 { NULL, NULL, NULL, NULL, NULL }, \
40 { NULL, NULL }, \
41 -1, -1, \
42 (next), \
43 NULL, '\0', 0, \
44 0, 0, unbuffered, 0, 0, 0, 0 \
46 static FILE stdstreams[3] =
48 stdstream (&stdstreams[0], &stdstreams[1], STDIN_FILENO, READ, BUFFERED),
49 stdstream (&stdstreams[1], &stdstreams[2], STDOUT_FILENO, WRITE, BUFFERED),
50 stdstream (&stdstreams[2], NULL, STDERR_FILENO, WRITE, UNBUFFERED),
52 FILE *stdin = &stdstreams[0];
53 FILE *stdout = &stdstreams[1];
54 FILE *stderr = &stdstreams[2];
56 /* Pointer to the first stream in the list. */
57 FILE *__stdio_head = &stdstreams[0];
59 /* This function MUST be in this file!
60 This is because we want _cleanup to go into the __libc_atexit set
61 when any stdio code is used (and to use any stdio code, one must reference
62 something defined in this file), and since only local symbols can be made
63 set elements, having the set element stab entry here and _cleanup elsewhere
64 loses; and having them both elsewhere loses because there is no reference
65 to cause _cleanup to be linked in. */
67 void
68 DEFUN_VOID(_cleanup)
70 (void) fclose((FILE *) NULL);
74 #ifdef HAVE_GNU_LD
75 text_set_element(__libc_atexit, _cleanup);
76 #endif