132
|
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 tango.stdc.stdio;
|
|
10
|
|
11 private
|
|
12 {
|
|
13 import tango.stdc.stdarg;
|
|
14 import tango.stdc.stddef;
|
|
15 import tango.stdc.config;
|
|
16 }
|
|
17
|
|
18 extern (C):
|
|
19
|
|
20 version( Win32 )
|
|
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
|
|
67 {
|
|
68 static assert( false );
|
|
69 }
|
|
70
|
|
71 enum
|
|
72 {
|
|
73 SEEK_SET,
|
|
74 SEEK_CUR,
|
|
75 SEEK_END
|
|
76 }
|
|
77
|
|
78 struct _iobuf
|
|
79 {
|
|
80 align (1):
|
|
81 version( Win32 )
|
|
82 {
|
|
83 char* _ptr;
|
|
84 int _cnt;
|
|
85 char* _base;
|
|
86 int _flag;
|
|
87 int _file;
|
|
88 int _charbuf;
|
|
89 int _bufsiz;
|
|
90 int __tmpnum;
|
|
91 }
|
|
92 else version( linux )
|
|
93 {
|
|
94 char* _read_ptr;
|
|
95 char* _read_end;
|
|
96 char* _read_base;
|
|
97 char* _write_base;
|
|
98 char* _write_ptr;
|
|
99 char* _write_end;
|
|
100 char* _buf_base;
|
|
101 char* _buf_end;
|
|
102 char* _save_base;
|
|
103 char* _backup_base;
|
|
104 char* _save_end;
|
|
105 void* _markers;
|
|
106 _iobuf* _chain;
|
|
107 int _fileno;
|
|
108 int _blksize;
|
|
109 int _old_offset;
|
|
110 ushort _cur_column;
|
|
111 byte _vtable_offset;
|
|
112 char[1] _shortbuf;
|
|
113 void* _lock;
|
|
114 }
|
|
115 else version( darwin )
|
|
116 {
|
|
117 ubyte* _p;
|
|
118 int _r;
|
|
119 int _w;
|
|
120 short _flags;
|
|
121 short _file;
|
|
122 __sbuf _bf;
|
|
123 int _lbfsize;
|
|
124
|
|
125 int* function(void*) _close;
|
|
126 int* function(void*, char*, int) _read;
|
|
127 fpos_t* function(void*, fpos_t, int) _seek;
|
|
128 int* function(void*, char *, int) _write;
|
|
129
|
|
130 __sbuf _ub;
|
|
131 __sFILEX* _extra;
|
|
132 int _ur;
|
|
133
|
|
134 ubyte[3] _ubuf;
|
|
135 ubyte[1] _nbuf;
|
|
136
|
|
137 __sbuf _lb;
|
|
138
|
|
139 int _blksize;
|
|
140 fpos_t _offset;
|
|
141 }
|
|
142 }
|
|
143
|
|
144 alias _iobuf FILE;
|
|
145
|
|
146 enum
|
|
147 {
|
|
148 _F_RDWR = 0x0003,
|
|
149 _F_READ = 0x0001,
|
|
150 _F_WRIT = 0x0002,
|
|
151 _F_BUF = 0x0004,
|
|
152 _F_LBUF = 0x0008,
|
|
153 _F_ERR = 0x0010,
|
|
154 _F_EOF = 0x0020,
|
|
155 _F_BIN = 0x0040,
|
|
156 _F_IN = 0x0080,
|
|
157 _F_OUT = 0x0100,
|
|
158 _F_TERM = 0x0200,
|
|
159 }
|
|
160
|
|
161 version( Win32 )
|
|
162 {
|
|
163 enum
|
|
164 {
|
|
165 _IOFBF = 0,
|
|
166 _IOREAD = 1,
|
|
167 _IOWRT = 2,
|
|
168 _IONBF = 4,
|
|
169 _IOMYBUF = 8,
|
|
170 _IOEOF = 0x10,
|
|
171 _IOERR = 0x20,
|
|
172 _IOLBF = 0x40,
|
|
173 _IOSTRG = 0x40,
|
|
174 _IORW = 0x80,
|
|
175 _IOTRAN = 0x100,
|
|
176 _IOAPP = 0x200,
|
|
177 }
|
|
178
|
|
179 extern void function() _fcloseallp;
|
|
180
|
|
181 version (GNU) {
|
|
182 extern FILE[_NFILE]* _imp___iob;
|
|
183
|
|
184 const FILE* stdin;
|
|
185 const FILE* stdout;
|
|
186 const FILE* stderr;
|
|
187 const FILE* stdaux;
|
|
188 const FILE* stdprn;
|
|
189
|
|
190 static this() {
|
|
191 stdin = &(*_imp___iob)[0];
|
|
192 stdout = &(*_imp___iob)[1];
|
|
193 stderr = &(*_imp___iob)[2];
|
|
194 stdaux = &(*_imp___iob)[3];
|
|
195 stdprn = &(*_imp___iob)[4];
|
|
196 }
|
|
197 } else {
|
|
198 extern FILE[_NFILE] _iob;
|
|
199
|
|
200 const FILE* stdin = &_iob[0];
|
|
201 const FILE* stdout = &_iob[1];
|
|
202 const FILE* stderr = &_iob[2];
|
|
203 const FILE* stdaux = &_iob[3];
|
|
204 const FILE* stdprn = &_iob[4];
|
|
205 }
|
|
206 }
|
|
207 else version( linux )
|
|
208 {
|
|
209 enum
|
|
210 {
|
|
211 _IOFBF = 0,
|
|
212 _IOLBF = 1,
|
|
213 _IONBF = 2,
|
|
214 }
|
|
215
|
|
216 extern FILE* stdin;
|
|
217 extern FILE* stdout;
|
|
218 extern FILE* stderr;
|
|
219 }
|
|
220 else version( darwin )
|
|
221 {
|
|
222 extern FILE[3] __sF;
|
|
223 const FILE* stdin = &__sF[0];
|
|
224 const FILE* stdout = &__sF[1];
|
|
225 const FILE* stderr = &__sF[2];
|
|
226 }
|
|
227 else
|
|
228 {
|
|
229 static assert( false );
|
|
230 }
|
|
231
|
|
232 alias int fpos_t;
|
|
233
|
|
234 int remove(char* filename);
|
|
235 int rename(char* from, char* to);
|
|
236
|
|
237 FILE* tmpfile();
|
|
238 char* tmpnam(char* s);
|
|
239
|
|
240 int fclose(FILE* stream);
|
|
241 int fflush(FILE* stream);
|
|
242 FILE* fopen(char* filename, char* mode);
|
|
243 FILE* freopen(char* filename, char* mode, FILE* stream);
|
|
244
|
|
245 void setbuf(FILE* stream, char* buf);
|
|
246 int setvbuf(FILE* stream, char* buf, int mode, size_t size);
|
|
247
|
|
248 int fprintf(FILE* stream, char* format, ...);
|
|
249 int fscanf(FILE* stream, char* format, ...);
|
|
250 int sprintf(char* s, char* format, ...);
|
|
251 int sscanf(char* s, char* format, ...);
|
|
252 int vfprintf(FILE* stream, char* format, va_list arg);
|
|
253 int vfscanf(FILE* stream, char* format, va_list arg);
|
|
254 int vsprintf(char* s, char* format, va_list arg);
|
|
255 int vsscanf(char* s, char* format, va_list arg);
|
|
256 int vprintf(char* format, va_list arg);
|
|
257 int vscanf(char* format, va_list arg);
|
|
258 int printf(char* format, ...);
|
|
259 int scanf(char* format, ...);
|
|
260
|
|
261 int fgetc(FILE* stream);
|
|
262 int fputc(int c, FILE* stream);
|
|
263
|
|
264 char* fgets(char* s, int n, FILE* stream);
|
|
265 int fputs(char* s, FILE* stream);
|
|
266 char* gets(char* s);
|
|
267 int puts(char* s);
|
|
268
|
|
269 extern (D)
|
|
270 {
|
|
271 int getchar() { return getc(stdin); }
|
|
272 int putchar(int c) { return putc(c,stdout); }
|
|
273 int getc(FILE* stream) { return fgetc(stream); }
|
|
274 int putc(int c, FILE* stream) { return fputc(c,stream); }
|
|
275 }
|
|
276
|
|
277 int ungetc(int c, FILE* stream);
|
|
278
|
|
279 size_t fread(void* ptr, size_t size, size_t nmemb, FILE* stream);
|
|
280 size_t fwrite(void* ptr, size_t size, size_t nmemb, FILE* stream);
|
|
281
|
|
282 int fgetpos(FILE* stream, fpos_t * pos);
|
|
283 int fsetpos(FILE* stream, fpos_t* pos);
|
|
284
|
|
285 int fseek(FILE* stream, c_long offset, int whence);
|
|
286 c_long ftell(FILE* stream);
|
|
287
|
|
288 version( Win32 )
|
|
289 {
|
|
290 extern (D)
|
|
291 {
|
|
292 void rewind(FILE* stream) { fseek(stream,0L,SEEK_SET); stream._flag&=~_IOERR; }
|
|
293 void clearerr(FILE* stream) { stream._flag &= ~(_IOERR|_IOEOF); }
|
|
294 int feof(FILE* stream) { return stream._flag&_IOEOF; }
|
|
295 int ferror(FILE* stream) { return stream._flag&_IOERR; }
|
|
296 }
|
|
297 int _snprintf(char*,size_t,char*,...);
|
|
298 alias _snprintf snprintf;
|
|
299
|
|
300 int _vsnprintf(char* s, size_t n, char* format, va_list arg);
|
|
301 alias _vsnprintf vsnprintf;
|
|
302 }
|
|
303 else version( linux )
|
|
304 {
|
|
305 void rewind(FILE* stream);
|
|
306 void clearerr(FILE* stream);
|
|
307 int feof(FILE* stream);
|
|
308 int ferror(FILE* stream);
|
|
309 int fileno(FILE *);
|
|
310
|
|
311 int snprintf(char* s, size_t n, char* format, ...);
|
|
312 int vsnprintf(char* s, size_t n, char* format, va_list arg);
|
|
313 }
|
|
314 else version( darwin )
|
|
315 {
|
|
316 void rewind(FILE*);
|
|
317 void clearerr(FILE*);
|
|
318 int feof(FILE*);
|
|
319 int ferror(FILE*);
|
|
320 int fileno(FILE*);
|
|
321
|
|
322 int snprintf(char*, size_t, char*, ...);
|
|
323 int vsnprintf(char*, size_t, char*, va_list);
|
|
324 }
|
|
325 else
|
|
326 {
|
|
327 static assert( false );
|
|
328 }
|
|
329
|
|
330 void perror(char* s);
|
|
331
|
|
332 int fwprintf(FILE* stream, wchar_t* format, ...);
|
|
333 int fwscanf(FILE* stream, wchar_t* format, ...);
|
|
334 int swprintf(wchar_t* s, size_t n, wchar_t* format, ...);
|
|
335 int swscanf(wchar_t* s, wchar_t* format, ...);
|
|
336 int vfwprintf(FILE* stream, wchar_t* format, va_list arg);
|
|
337 int vfwscanf(FILE* stream, wchar_t* format, va_list arg);
|
|
338 int vswprintf(wchar_t* s, size_t n, wchar_t* format, va_list arg);
|
|
339 int vswscanf(wchar_t* s, wchar_t* format, va_list arg);
|
|
340 int vwprintf(wchar_t* format, va_list arg);
|
|
341 int vwscanf(wchar_t* format, va_list arg);
|
|
342 int wprintf(wchar_t* format, ...);
|
|
343 int wscanf(wchar_t* format, ...);
|
|
344
|
|
345 wint_t fgetwc(FILE* stream);
|
|
346 wint_t fputwc(wchar_t c, FILE* stream);
|
|
347
|
|
348 wchar_t* fgetws(wchar_t* s, int n, FILE* stream);
|
|
349 int fputws(wchar_t* s, FILE* stream);
|
|
350
|
|
351 extern (D)
|
|
352 {
|
|
353 wint_t getwchar() { return fgetwc(stdin); }
|
|
354 wint_t putwchar(wchar_t c) { return fputwc(c,stdout); }
|
|
355 wint_t getwc(FILE* stream) { return fgetwc(stream); }
|
|
356 wint_t putwc(wchar_t c, FILE* stream) { return fputwc(c, stream); }
|
|
357 }
|
|
358
|
|
359 wint_t ungetwc(wint_t c, FILE* stream);
|
|
360 int fwide(FILE* stream, int mode);
|