Mercurial > projects > ldc
comparison druntime/import/core/stdc/stdio.d @ 1458:e0b2d67cfe7c
Added druntime (this should be removed once it works).
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Tue, 02 Jun 2009 17:43:06 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1456:7b218ec1044f | 1458:e0b2d67cfe7c |
---|---|
1 /** | |
2 * D header file for C99. | |
3 * | |
4 * Copyright: Copyright Sean Kelly 2005 - 2009. | |
5 * License: <a href="http://www.boost.org/LICENSE_1_0.txt>Boost License 1.0</a>. | |
6 * Authors: Sean Kelly | |
7 * Standards: ISO/IEC 9899:1999 (E) | |
8 * | |
9 * Copyright Sean Kelly 2005 - 2009. | |
10 * Distributed under the Boost Software License, Version 1.0. | |
11 * (See accompanying file LICENSE_1_0.txt or copy at | |
12 * http://www.boost.org/LICENSE_1_0.txt) | |
13 */ | |
14 module core.stdc.stdio; | |
15 | |
16 private | |
17 { | |
18 import core.stdc.config; | |
19 import core.stdc.stddef; // for size_t | |
20 import core.stdc.stdarg; // for va_list | |
21 } | |
22 | |
23 extern (C): | |
24 | |
25 version( Windows ) | |
26 { | |
27 enum | |
28 { | |
29 BUFSIZ = 0x4000, | |
30 EOF = -1, | |
31 FOPEN_MAX = 20, | |
32 FILENAME_MAX = 256, // 255 plus NULL | |
33 TMP_MAX = 32767, | |
34 SYS_OPEN = 20, // non-standard | |
35 } | |
36 | |
37 enum int _NFILE = 60; // non-standard | |
38 enum string _P_tmpdir = "\\"; // non-standard | |
39 enum wstring _wP_tmpdir = "\\"; // non-standard | |
40 enum int L_tmpnam = _P_tmpdir.length + 12; | |
41 } | |
42 else version( linux ) | |
43 { | |
44 enum | |
45 { | |
46 BUFSIZ = 8192, | |
47 EOF = -1, | |
48 FOPEN_MAX = 16, | |
49 FILENAME_MAX = 4095, | |
50 TMP_MAX = 238328, | |
51 L_tmpnam = 20 | |
52 } | |
53 } | |
54 else version( OSX ) | |
55 { | |
56 enum | |
57 { | |
58 BUFSIZ = 1024, | |
59 EOF = -1, | |
60 FOPEN_MAX = 20, | |
61 FILENAME_MAX = 1024, | |
62 TMP_MAX = 308915776, | |
63 L_tmpnam = 1024, | |
64 } | |
65 | |
66 private | |
67 { | |
68 struct __sbuf | |
69 { | |
70 ubyte* _base; | |
71 int _size; | |
72 } | |
73 | |
74 struct __sFILEX | |
75 { | |
76 | |
77 } | |
78 } | |
79 } | |
80 else version ( FreeBSD ) | |
81 { | |
82 enum | |
83 { | |
84 EOF = -1, | |
85 FOPEN_MAX = 20, | |
86 FILENAME_MAX = 1024, | |
87 TMP_MAX = 308915776, | |
88 L_tmpnam = 1024 | |
89 } | |
90 | |
91 private | |
92 { | |
93 struct __sbuf | |
94 { | |
95 ubyte *_base; | |
96 int _size; | |
97 } | |
98 struct __sFILEX | |
99 { | |
100 | |
101 } | |
102 } | |
103 } | |
104 else | |
105 { | |
106 static assert( false ); | |
107 } | |
108 | |
109 enum | |
110 { | |
111 SEEK_SET, | |
112 SEEK_CUR, | |
113 SEEK_END | |
114 } | |
115 | |
116 struct _iobuf | |
117 { | |
118 align (1): | |
119 version( Windows ) | |
120 { | |
121 char* _ptr; | |
122 int _cnt; | |
123 char* _base; | |
124 int _flag; | |
125 int _file; | |
126 int _charbuf; | |
127 int _bufsiz; | |
128 int __tmpnum; | |
129 } | |
130 else version( linux ) | |
131 { | |
132 char* _read_ptr; | |
133 char* _read_end; | |
134 char* _read_base; | |
135 char* _write_base; | |
136 char* _write_ptr; | |
137 char* _write_end; | |
138 char* _buf_base; | |
139 char* _buf_end; | |
140 char* _save_base; | |
141 char* _backup_base; | |
142 char* _save_end; | |
143 void* _markers; | |
144 _iobuf* _chain; | |
145 int _fileno; | |
146 int _blksize; | |
147 int _old_offset; | |
148 ushort _cur_column; | |
149 byte _vtable_offset; | |
150 char[1] _shortbuf; | |
151 void* _lock; | |
152 } | |
153 else version( OSX ) | |
154 { | |
155 ubyte* _p; | |
156 int _r; | |
157 int _w; | |
158 short _flags; | |
159 short _file; | |
160 __sbuf _bf; | |
161 int _lbfsize; | |
162 | |
163 int* function(void*) _close; | |
164 int* function(void*, char*, int) _read; | |
165 fpos_t* function(void*, fpos_t, int) _seek; | |
166 int* function(void*, char *, int) _write; | |
167 | |
168 __sbuf _ub; | |
169 __sFILEX* _extra; | |
170 int _ur; | |
171 | |
172 ubyte[3] _ubuf; | |
173 ubyte[1] _nbuf; | |
174 | |
175 __sbuf _lb; | |
176 | |
177 int _blksize; | |
178 fpos_t _offset; | |
179 } | |
180 else version( FreeBSD ) | |
181 { | |
182 ubyte* _p; | |
183 int _r; | |
184 int _w; | |
185 short _flags; | |
186 short _file; | |
187 __sbuf _bf; | |
188 int _lbfsize; | |
189 | |
190 void* function() _cookie; | |
191 int* function(void*) _close; | |
192 int* function(void*, char*, int) _read; | |
193 fpos_t* function(void*, fpos_t, int) _seek; | |
194 int* function(void*, char *, int) _write; | |
195 | |
196 __sbuf _ub; | |
197 __sFILEX* _extra; | |
198 int _ur; | |
199 | |
200 ubyte[3] _ubuf; | |
201 ubyte[1] _nbuf; | |
202 | |
203 __sbuf _lb; | |
204 | |
205 int _blksize; | |
206 fpos_t _offset; | |
207 } | |
208 else | |
209 { | |
210 static assert( false ); | |
211 } | |
212 } | |
213 | |
214 alias shared(_iobuf) FILE; | |
215 | |
216 enum | |
217 { | |
218 _F_RDWR = 0x0003, // non-standard | |
219 _F_READ = 0x0001, // non-standard | |
220 _F_WRIT = 0x0002, // non-standard | |
221 _F_BUF = 0x0004, // non-standard | |
222 _F_LBUF = 0x0008, // non-standard | |
223 _F_ERR = 0x0010, // non-standard | |
224 _F_EOF = 0x0020, // non-standard | |
225 _F_BIN = 0x0040, // non-standard | |
226 _F_IN = 0x0080, // non-standard | |
227 _F_OUT = 0x0100, // non-standard | |
228 _F_TERM = 0x0200, // non-standard | |
229 } | |
230 | |
231 version( Windows ) | |
232 { | |
233 enum | |
234 { | |
235 _IOFBF = 0, | |
236 _IOLBF = 0x40, | |
237 _IONBF = 4, | |
238 _IOREAD = 1, // non-standard | |
239 _IOWRT = 2, // non-standard | |
240 _IOMYBUF = 8, // non-standard | |
241 _IOEOF = 0x10, // non-standard | |
242 _IOERR = 0x20, // non-standard | |
243 _IOSTRG = 0x40, // non-standard | |
244 _IORW = 0x80, // non-standard | |
245 _IOTRAN = 0x100, // non-standard | |
246 _IOAPP = 0x200, // non-standard | |
247 } | |
248 | |
249 extern shared void function() _fcloseallp; | |
250 | |
251 private extern shared FILE[_NFILE] _iob; | |
252 | |
253 shared stdin = &_iob[0]; | |
254 shared stdout = &_iob[1]; | |
255 shared stderr = &_iob[2]; | |
256 shared stdaux = &_iob[3]; | |
257 shared stdprn = &_iob[4]; | |
258 } | |
259 else version( linux ) | |
260 { | |
261 enum | |
262 { | |
263 _IOFBF = 0, | |
264 _IOLBF = 1, | |
265 _IONBF = 2, | |
266 } | |
267 | |
268 extern shared FILE* stdin; | |
269 extern shared FILE* stdout; | |
270 extern shared FILE* stderr; | |
271 } | |
272 else version( OSX ) | |
273 { | |
274 enum | |
275 { | |
276 _IOFBF = 0, | |
277 _IOLBF = 1, | |
278 _IONBF = 2, | |
279 } | |
280 | |
281 private extern shared FILE* __stdinp; | |
282 private extern shared FILE* __stdoutp; | |
283 private extern shared FILE* __stderrp; | |
284 | |
285 alias __stdinp stdin; | |
286 alias __stdoutp stdout; | |
287 alias __stderrp stderr; | |
288 } | |
289 else version( FreeBSD ) | |
290 { | |
291 private extern shared FILE[3] __sF; | |
292 | |
293 shared stdin = &__sF[0]; | |
294 shared stdout = &__sF[1]; | |
295 shared stderr = &__sF[2]; | |
296 } | |
297 else | |
298 { | |
299 static assert( false ); | |
300 } | |
301 | |
302 alias int fpos_t; | |
303 | |
304 int remove(in char* filename); | |
305 int rename(in char* from, in char* to); | |
306 | |
307 FILE* tmpfile(); | |
308 char* tmpnam(char* s); | |
309 | |
310 int fclose(FILE* stream); | |
311 int fflush(FILE* stream); | |
312 FILE* fopen(in char* filename, in char* mode); | |
313 FILE* freopen(in char* filename, in char* mode, FILE* stream); | |
314 | |
315 void setbuf(FILE* stream, char* buf); | |
316 int setvbuf(FILE* stream, char* buf, int mode, size_t size); | |
317 | |
318 int fprintf(FILE* stream, in char* format, ...); | |
319 int fscanf(FILE* stream, in char* format, ...); | |
320 int sprintf(char* s, in char* format, ...); | |
321 int sscanf(in char* s, in char* format, ...); | |
322 int vfprintf(FILE* stream, in char* format, va_list arg); | |
323 int vfscanf(FILE* stream, in char* format, va_list arg); | |
324 int vsprintf(char* s, in char* format, va_list arg); | |
325 int vsscanf(in char* s, in char* format, va_list arg); | |
326 int vprintf(in char* format, va_list arg); | |
327 int vscanf(in char* format, va_list arg); | |
328 int printf(in char* format, ...); | |
329 int scanf(in char* format, ...); | |
330 | |
331 int fgetc(FILE* stream); | |
332 int fputc(int c, FILE* stream); | |
333 | |
334 char* fgets(char* s, int n, FILE* stream); | |
335 int fputs(in char* s, FILE* stream); | |
336 char* gets(char* s); | |
337 int puts(in char* s); | |
338 | |
339 extern (D) | |
340 { | |
341 int getchar() { return getc(stdin); } | |
342 int putchar(int c) { return putc(c,stdout); } | |
343 int getc(FILE* stream) { return fgetc(stream); } | |
344 int putc(int c, FILE* stream) { return fputc(c,stream); } | |
345 } | |
346 | |
347 int ungetc(int c, FILE* stream); | |
348 | |
349 size_t fread(void* ptr, size_t size, size_t nmemb, FILE* stream); | |
350 size_t fwrite(in void* ptr, size_t size, size_t nmemb, FILE* stream); | |
351 | |
352 int fgetpos(FILE* stream, fpos_t * pos); | |
353 int fsetpos(FILE* stream, in fpos_t* pos); | |
354 | |
355 int fseek(FILE* stream, c_long offset, int whence); | |
356 c_long ftell(FILE* stream); | |
357 | |
358 version( Windows ) | |
359 { | |
360 extern (D) | |
361 { | |
362 void rewind(FILE* stream) { fseek(stream,0L,SEEK_SET); stream._flag&=~_IOERR; } | |
363 void clearerr(FILE* stream) { stream._flag &= ~(_IOERR|_IOEOF); } | |
364 int feof(FILE* stream) { return stream._flag&_IOEOF; } | |
365 int ferror(FILE* stream) { return stream._flag&_IOERR; } | |
366 } | |
367 int _snprintf(char* s, size_t n, in char* fmt, ...); | |
368 alias _snprintf snprintf; | |
369 | |
370 int _vsnprintf(char* s, size_t n, in char* format, va_list arg); | |
371 alias _vsnprintf vsnprintf; | |
372 } | |
373 else version( linux ) | |
374 { | |
375 void rewind(FILE* stream); | |
376 void clearerr(FILE* stream); | |
377 int feof(FILE* stream); | |
378 int ferror(FILE* stream); | |
379 int fileno(FILE *); | |
380 | |
381 int snprintf(char* s, size_t n, in char* format, ...); | |
382 int vsnprintf(char* s, size_t n, in char* format, va_list arg); | |
383 } | |
384 else version( OSX ) | |
385 { | |
386 void rewind(FILE*); | |
387 void clearerr(FILE*); | |
388 int feof(FILE*); | |
389 int ferror(FILE*); | |
390 int fileno(FILE*); | |
391 | |
392 int snprintf(char* s, size_t n, in char* format, ...); | |
393 int vsnprintf(char* s, size_t n, in char* format, va_list arg); | |
394 } | |
395 else version( FreeBSD ) | |
396 { | |
397 void rewind(FILE*); | |
398 void clearerr(FILE*); | |
399 int feof(FILE*); | |
400 int ferror(FILE*); | |
401 int fileno(FILE*); | |
402 | |
403 int snprintf(char* s, size_t n, in char* format, ...); | |
404 int vsnprintf(char* s, size_t n, in char* format, va_list arg); | |
405 } | |
406 else | |
407 { | |
408 static assert( false ); | |
409 } | |
410 | |
411 void perror(in char* s); |