1 /* Implement runtime actions for CHILL.
2 Copyright (C) 1992,1993 Free Software Foundation, Inc.
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)
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. */
35 /* predefined associations, accesses, and text for stdin, stdout, stderr */
37 #define STDIO_TEXT_LENGTH 1024
38 #define STDIN_TEXT_LENGTH STDIO_TEXT_LENGTH
40 static Access_Mode stdin_access
;
43 #define STDIN_FILENO 0
47 Association_Mode stdin_association
=
49 IO_EXISTING
| IO_READABLE
| IO_SEQUENCIBLE
| IO_ISASSOCIATED
,
58 static Access_Mode stdin_access
=
61 STDIN_TEXT_LENGTH
+ 2,
71 VARYING_STRING(STDIN_TEXT_LENGTH
) stdin_text_record
;
73 Text_Mode chill_stdin
=
76 (VarString
*)&stdin_text_record
,
82 #define STDOUT_TEXT_LENGTH STDIO_TEXT_LENGTH
84 #define STDOUT_FILENO 1
87 static Access_Mode stdout_access
;
90 Association_Mode stdout_association
=
92 IO_EXISTING
| IO_WRITEABLE
| IO_SEQUENCIBLE
| IO_ISASSOCIATED
,
101 static Access_Mode stdout_access
=
104 STDOUT_TEXT_LENGTH
+ 2,
114 VARYING_STRING(STDOUT_TEXT_LENGTH
) stdout_text_record
;
116 Text_Mode chill_stdout
=
119 (VarString
*)&stdout_text_record
,
125 #define STDERR_TEXT_LENGTH STDIO_TEXT_LENGTH
126 #ifndef STDERR_FILENO
127 #define STDERR_FILENO 2
130 static Access_Mode stderr_access
;
133 Association_Mode stderr_association
=
135 IO_EXISTING
| IO_WRITEABLE
| IO_SEQUENCIBLE
| IO_ISASSOCIATED
,
144 static Access_Mode stderr_access
=
147 STDERR_TEXT_LENGTH
+ 2,
157 VARYING_STRING(STDIN_TEXT_LENGTH
) stderr_text_record
;
159 Text_Mode chill_stderr
=
162 (VarString
*)&stderr_text_record
,
168 * function __xmalloc_
171 * size number of bytes to allocate
177 * This is the general allocation routine for libchill
185 void *tmp
= malloc (size
);
189 fprintf (stderr
, "ChillLib: Out of heap space.\n");
197 newstring (char *str
)
199 char *tmp
= __xmalloc_ (strlen (str
) + 1);
204 static void setup_stdinout (void) __attribute__((constructor
));
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
));