New files:
[deliverable/binutils-gdb.git] / sim / common / sim-io.c
1 /* This file is part of the program psim.
2
3 Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program 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
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 */
20
21
22 #ifndef _SIM_IO_C_
23 #define _SIM_IO_C_
24
25 #include "engine.h"
26
27 /* See the file include/callbacks.h for a description */
28
29
30 INLINE_SIM_IO(int)
31 sim_io_init(engine *system)
32 {
33 return system->callback->init (system->callback);
34 }
35
36
37 INLINE_SIM_IO(int)
38 sim_io_shutdown(engine *system)
39 {
40 return system->callback->shutdown (system->callback);
41 }
42
43
44 INLINE_SIM_IO(int)
45 sim_io_unlink(engine *system,
46 const char *f1)
47 {
48 return system->callback->unlink (system->callback, f1);
49 }
50
51
52 INLINE_SIM_IO(long)
53 sim_io_time(engine *system,
54 long *t)
55 {
56 return system->callback->time (system->callback, t);
57 }
58
59
60 INLINE_SIM_IO(int)
61 sim_io_system(engine *system, const char *s)
62 {
63 return system->callback->system (system->callback, s);
64 }
65
66
67 INLINE_SIM_IO(int)
68 sim_io_rename(engine *system,
69 const char *f1,
70 const char *f2)
71 {
72 return system->callback->rename (system->callback, f1, f2);
73 }
74
75
76 INLINE_SIM_IO(int)
77 sim_io_write_stdout(engine *system,
78 const char *buf,
79 int len)
80 {
81 switch (CURRENT_STDIO) {
82 case DO_USE_STDIO:
83 return system->callback->write_stdout (system->callback, buf, len);
84 break;
85 case DONT_USE_STDIO:
86 return system->callback->write (system->callback, 1, buf, len);
87 break;
88 default:
89 sim_io_error (system, "sim_io_write_stdout: unaccounted switch\n");
90 break;
91 }
92 return 0;
93 }
94
95
96 INLINE_SIM_IO(int)
97 sim_io_flush_stdout(engine *system)
98 {
99 switch (CURRENT_STDIO) {
100 case DO_USE_STDIO:
101 return system->callback->flush_stdout (system->callback);
102 break;
103 case DONT_USE_STDIO:
104 break;
105 default:
106 sim_io_error (system, "sim_io_flush_stdout: unaccounted switch\n");
107 break;
108 }
109 }
110
111
112 INLINE_SIM_IO(int)
113 sim_io_write_stderr(engine *system,
114 const char *buf,
115 int len)
116 {
117 switch (CURRENT_STDIO) {
118 case DO_USE_STDIO:
119 return system->callback->write_stderr (system->callback, buf, len);
120 break;
121 case DONT_USE_STDIO:
122 return system->callback->write (system->callback, 2, buf, len);
123 break;
124 default:
125 sim_io_error (system, "sim_io_write_stderr: unaccounted switch\n");
126 break;
127 }
128 return 0;
129 }
130
131
132 INLINE_SIM_IO(int)
133 sim_io_flush_stderr(engine *system)
134 {
135 switch (CURRENT_STDIO) {
136 case DO_USE_STDIO:
137 return system->callback->flush_stderr (system->callback);
138 break;
139 case DONT_USE_STDIO:
140 break;
141 default:
142 sim_io_error (system, "sim_io_flush_stderr: unaccounted switch\n");
143 break;
144 }
145 }
146
147
148 INLINE_SIM_IO(int)
149 sim_io_write(engine *system,
150 int fd,
151 const char *buf,
152 int len)
153 {
154 return system->callback->write (system->callback, fd, buf, len);
155 }
156
157
158 INLINE_SIM_IO(int)
159 sim_io_read_stdin(engine *system,
160 char *buf,
161 int len)
162 {
163 switch (CURRENT_STDIO) {
164 case DO_USE_STDIO:
165 return system->callback->read_stdin (system->callback, buf, len);
166 break;
167 case DONT_USE_STDIO:
168 return system->callback->read (system->callback, 0, buf, len);
169 break;
170 default:
171 sim_io_error (system, "sim_io_read_stdin: unaccounted switch\n");
172 break;
173 }
174 return 0;
175 }
176
177
178 INLINE_SIM_IO(int)
179 sim_io_read(engine *system, int fd,
180 char *buf,
181 int len)
182 {
183 return system->callback->read(system->callback, fd, buf, len);
184 }
185
186
187 INLINE_SIM_IO(int)
188 sim_io_open(engine *system,
189 const char *name,
190 int flags)
191 {
192 return system->callback->open (system->callback, name, flags);
193 }
194
195
196 INLINE_SIM_IO(int)
197 sim_io_lseek(engine *system,
198 int fd,
199 long off,
200 int way)
201 {
202 return system->callback->lseek (system->callback, fd, off, way);
203 }
204
205
206 INLINE_SIM_IO(int)
207 sim_io_isatty(engine *system,
208 int fd)
209 {
210 return system->callback->isatty (system->callback, fd);
211 }
212
213
214 INLINE_SIM_IO(int)
215 sim_io_get_errno(engine *system)
216 {
217 return system->callback->get_errno (system->callback);
218 }
219
220
221 INLINE_SIM_IO(int)
222 sim_io_close(engine *system,
223 int fd)
224 {
225 return system->callback->close (system->callback, fd);
226 }
227
228
229 INLINE_SIM_IO(void)
230 sim_io_printf(engine *system,
231 const char *fmt,
232 ...)
233 {
234 va_list ap;
235 va_start(ap, fmt);
236 system->callback->vprintf_filtered (system->callback, fmt, ap);
237 va_end(ap);
238 }
239
240
241 INLINE_SIM_IO(void)
242 sim_io_vprintf(engine *system,
243 const char *fmt,
244 va_list ap)
245 {
246 system->callback->vprintf_filtered (system->callback, fmt, ap);
247 }
248
249
250 INLINE_SIM_IO(void)
251 sim_io_eprintf(engine *system,
252 const char *fmt,
253 ...)
254 {
255 va_list ap;
256 va_start(ap, fmt);
257 system->callback->evprintf_filtered (system->callback, fmt, ap);
258 va_end(ap);
259 }
260
261
262 INLINE_SIM_IO(void)
263 sim_io_evprintf(engine *system,
264 const char *fmt,
265 va_list ap)
266 {
267 system->callback->evprintf_filtered (system->callback, fmt, ap);
268 }
269
270
271 INLINE_SIM_IO(void)
272 sim_io_error(engine *system,
273 const char *fmt,
274 ...)
275 {
276 char buf[1000];
277 va_list ap;
278 va_start(ap, fmt);
279 vsprintf(buf, fmt, ap);
280 va_end(ap);
281
282 if (strlen(buf) >= sizeof(buf))
283 abort();
284
285 system->callback->error (system->callback, "%s", buf);
286 }
287
288
289
290 #endif
This page took 0.036298 seconds and 5 git commands to generate.