* gjavah.c (print_field_info): Changed how most negative number is
[official-gcc.git] / libchill / chillstdio.c
blob209151b7ceeb7cbff37ea130d29283f8e5f662a1
1 /* Implement runtime actions for CHILL.
2 Copyright (C) 1992,1993 Free Software Foundation, Inc.
3 Author: Wilfried Moser
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* As a special exception, if you link this library with other files,
22 some of which are compiled with GCC, to produce an executable,
23 this library does not by itself cause the resulting executable
24 to be covered by the GNU General Public License.
25 This exception does not however invalidate any other reasons why
26 the executable file might be covered by the GNU General Public License. */
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <errno.h>
31 #include <string.h>
33 #include "iomodes.h"
35 /* predefined associations, accesses, and text for stdin, stdout, stderr */
36 /* stdin */
37 #define STDIO_TEXT_LENGTH 1024
38 #define STDIN_TEXT_LENGTH STDIO_TEXT_LENGTH
40 static Access_Mode stdin_access;
42 #ifndef STDIN_FILENO
43 #define STDIN_FILENO 0
44 #endif
46 static
47 Association_Mode stdin_association =
49 IO_EXISTING | IO_READABLE | IO_SEQUENCIBLE | IO_ISASSOCIATED,
50 NULL,
51 &stdin_access,
52 STDIN_FILENO,
53 NULL,
55 ReadOnly
58 static Access_Mode stdin_access =
60 IO_TEXTIO,
61 STDIN_TEXT_LENGTH + 2,
64 &stdin_association,
66 NULL,
67 VaryingChars
70 static
71 VARYING_STRING(STDIN_TEXT_LENGTH) stdin_text_record;
73 Text_Mode chill_stdin =
75 IO_TEXTLOCATION,
76 (VarString *)&stdin_text_record,
77 &stdin_access,
81 /* stdout */
82 #define STDOUT_TEXT_LENGTH STDIO_TEXT_LENGTH
83 #ifndef STDOUT_FILENO
84 #define STDOUT_FILENO 1
85 #endif
87 static Access_Mode stdout_access;
89 static
90 Association_Mode stdout_association =
92 IO_EXISTING | IO_WRITEABLE | IO_SEQUENCIBLE | IO_ISASSOCIATED,
93 NULL,
94 &stdout_access,
95 STDOUT_FILENO,
96 NULL,
98 WriteOnly
101 static Access_Mode stdout_access =
103 IO_TEXTIO,
104 STDOUT_TEXT_LENGTH + 2,
107 &stdout_association,
109 NULL,
110 VaryingChars
113 static
114 VARYING_STRING(STDOUT_TEXT_LENGTH) stdout_text_record;
116 Text_Mode chill_stdout =
118 IO_TEXTLOCATION,
119 (VarString *)&stdout_text_record,
120 &stdout_access,
124 /* stderr */
125 #define STDERR_TEXT_LENGTH STDIO_TEXT_LENGTH
126 #ifndef STDERR_FILENO
127 #define STDERR_FILENO 2
128 #endif
130 static Access_Mode stderr_access;
132 static
133 Association_Mode stderr_association =
135 IO_EXISTING | IO_WRITEABLE | IO_SEQUENCIBLE | IO_ISASSOCIATED,
136 NULL,
137 &stderr_access,
138 STDERR_FILENO,
139 NULL,
141 WriteOnly
144 static Access_Mode stderr_access =
146 IO_TEXTIO,
147 STDERR_TEXT_LENGTH + 2,
150 &stderr_association,
152 NULL,
153 VaryingChars
156 static
157 VARYING_STRING(STDIN_TEXT_LENGTH) stderr_text_record;
159 Text_Mode chill_stderr =
161 IO_TEXTLOCATION,
162 (VarString *)&stderr_text_record,
163 &stderr_access,
168 * function __xmalloc_
170 * parameter:
171 * size number of bytes to allocate
173 * returns:
174 * void*
176 * abstract:
177 * This is the general allocation routine for libchill
181 void *
182 __xmalloc_ (size)
183 int size;
185 void *tmp = malloc (size);
187 if (!tmp)
189 fprintf (stderr, "ChillLib: Out of heap space.\n");
190 fflush (stderr);
191 exit (ENOMEM);
193 return (tmp);
194 } /* __xmalloc_ */
196 static char *
197 newstring (char *str)
199 char *tmp = __xmalloc_ (strlen (str) + 1);
200 strcpy (tmp, str);
201 return tmp;
204 static void setup_stdinout (void) __attribute__((constructor));
206 static void
207 setup_stdinout ()
209 /* allocate the names */
210 stdin_association.pathname = newstring ("stdin");
211 stdout_association.pathname = newstring ("stdout");
212 stderr_association.pathname = newstring ("stderr");
214 /* stdin needs a readbuffer */
215 stdin_association.bufptr = __xmalloc_ (sizeof (readbuf_t));
216 memset (stdin_association.bufptr, 0, sizeof (readbuf_t));