* config/xtensa/xtensa.c (xtensa_va_arg): Fix to handle arguments
[official-gcc.git] / libchill / chillstdio.c
blobd12c809625e689aeb2a44f4f1f6639b4b989c1c4
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, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* As a special exception, if you link this library with other files,
23 some of which are compiled with GCC, to produce an executable,
24 this library does not by itself cause the resulting executable
25 to be covered by the GNU General Public License.
26 This exception does not however invalidate any other reasons why
27 the executable file might be covered by the GNU General Public License. */
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <errno.h>
32 #include <string.h>
34 #include "iomodes.h"
36 /* predefined associations, accesses, and text for stdin, stdout, stderr */
37 /* stdin */
38 #define STDIO_TEXT_LENGTH 1024
39 #define STDIN_TEXT_LENGTH STDIO_TEXT_LENGTH
41 static Access_Mode stdin_access;
43 #ifndef STDIN_FILENO
44 #define STDIN_FILENO 0
45 #endif
47 static
48 Association_Mode stdin_association =
50 IO_EXISTING | IO_READABLE | IO_SEQUENCIBLE | IO_ISASSOCIATED,
51 NULL,
52 &stdin_access,
53 STDIN_FILENO,
54 NULL,
56 ReadOnly
59 static Access_Mode stdin_access =
61 IO_TEXTIO,
62 STDIN_TEXT_LENGTH + 2,
65 &stdin_association,
67 NULL,
68 VaryingChars
71 static
72 VARYING_STRING(STDIN_TEXT_LENGTH) stdin_text_record;
74 Text_Mode chill_stdin =
76 IO_TEXTLOCATION,
77 (VarString *)&stdin_text_record,
78 &stdin_access,
82 /* stdout */
83 #define STDOUT_TEXT_LENGTH STDIO_TEXT_LENGTH
84 #ifndef STDOUT_FILENO
85 #define STDOUT_FILENO 1
86 #endif
88 static Access_Mode stdout_access;
90 static
91 Association_Mode stdout_association =
93 IO_EXISTING | IO_WRITEABLE | IO_SEQUENCIBLE | IO_ISASSOCIATED,
94 NULL,
95 &stdout_access,
96 STDOUT_FILENO,
97 NULL,
99 WriteOnly
102 static Access_Mode stdout_access =
104 IO_TEXTIO,
105 STDOUT_TEXT_LENGTH + 2,
108 &stdout_association,
110 NULL,
111 VaryingChars
114 static
115 VARYING_STRING(STDOUT_TEXT_LENGTH) stdout_text_record;
117 Text_Mode chill_stdout =
119 IO_TEXTLOCATION,
120 (VarString *)&stdout_text_record,
121 &stdout_access,
125 /* stderr */
126 #define STDERR_TEXT_LENGTH STDIO_TEXT_LENGTH
127 #ifndef STDERR_FILENO
128 #define STDERR_FILENO 2
129 #endif
131 static Access_Mode stderr_access;
133 static
134 Association_Mode stderr_association =
136 IO_EXISTING | IO_WRITEABLE | IO_SEQUENCIBLE | IO_ISASSOCIATED,
137 NULL,
138 &stderr_access,
139 STDERR_FILENO,
140 NULL,
142 WriteOnly
145 static Access_Mode stderr_access =
147 IO_TEXTIO,
148 STDERR_TEXT_LENGTH + 2,
151 &stderr_association,
153 NULL,
154 VaryingChars
157 static
158 VARYING_STRING(STDIN_TEXT_LENGTH) stderr_text_record;
160 Text_Mode chill_stderr =
162 IO_TEXTLOCATION,
163 (VarString *)&stderr_text_record,
164 &stderr_access,
169 * function __xmalloc_
171 * parameter:
172 * size number of bytes to allocate
174 * returns:
175 * void*
177 * abstract:
178 * This is the general allocation routine for libchill
182 void *
183 __xmalloc_ (size)
184 int size;
186 void *tmp = malloc (size);
188 if (!tmp)
190 fprintf (stderr, "ChillLib: Out of heap space.\n");
191 fflush (stderr);
192 exit (ENOMEM);
194 return (tmp);
195 } /* __xmalloc_ */
197 static char *
198 newstring (char *str)
200 char *tmp = __xmalloc_ (strlen (str) + 1);
201 strcpy (tmp, str);
202 return tmp;
205 static void setup_stdinout (void) __attribute__((constructor));
207 static void
208 setup_stdinout ()
210 /* allocate the names */
211 stdin_association.pathname = newstring ("stdin");
212 stdout_association.pathname = newstring ("stdout");
213 stderr_association.pathname = newstring ("stderr");
215 /* stdin needs a readbuffer */
216 stdin_association.bufptr = __xmalloc_ (sizeof (readbuf_t));
217 memset (stdin_association.bufptr, 0, sizeof (readbuf_t));