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