stdio.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. /*
  2. * stdio.h
  3. *
  4. * Definitions of types and prototypes of functions for standard input and
  5. * output.
  6. *
  7. * NOTE: The file manipulation functions provided by Microsoft seem to
  8. * work with either slash (/) or backslash (\) as the path separator.
  9. *
  10. * This file is part of the Mingw32 package.
  11. *
  12. * Contributors:
  13. * Created by Colin Peters <[email protected]>
  14. *
  15. * THIS SOFTWARE IS NOT COPYRIGHTED
  16. *
  17. * This source code is offered for use in the public domain. You may
  18. * use, modify or distribute it freely.
  19. *
  20. * This code is distributed in the hope that it will be useful but
  21. * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
  22. * DISCLAIMED. This includes but is not limited to warranties of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  24. *
  25. * $Revision: 1.2 $
  26. * $Author: bellard $
  27. * $Date: 2005/04/17 13:14:29 $
  28. *
  29. */
  30. #ifndef _STDIO_H_
  31. #define _STDIO_H_
  32. /* All the headers include this file. */
  33. #include <_mingw.h>
  34. #define __need_size_t
  35. #define __need_NULL
  36. #define __need_wchar_t
  37. #define __need_wint_t
  38. #ifndef RC_INVOKED
  39. #include <stddef.h>
  40. #endif /* Not RC_INVOKED */
  41. /* Flags for the iobuf structure */
  42. #define _IOREAD 1
  43. #define _IOWRT 2
  44. #define _IORW 0x0080 /* opened as "r+w" */
  45. /*
  46. * The three standard file pointers provided by the run time library.
  47. * NOTE: These will go to the bit-bucket silently in GUI applications!
  48. */
  49. #define STDIN_FILENO 0
  50. #define STDOUT_FILENO 1
  51. #define STDERR_FILENO 2
  52. /* Returned by various functions on end of file condition or error. */
  53. #define EOF (-1)
  54. /*
  55. * The maximum length of a file name. You should use GetVolumeInformation
  56. * instead of this constant. But hey, this works.
  57. *
  58. * NOTE: This is used in the structure _finddata_t (see io.h) so changing it
  59. * is probably not a good idea.
  60. */
  61. #define FILENAME_MAX (260)
  62. /*
  63. * The maximum number of files that may be open at once. I have set this to
  64. * a conservative number. The actual value may be higher.
  65. */
  66. #define FOPEN_MAX (20)
  67. /* After creating this many names, tmpnam and tmpfile return NULL */
  68. #define TMP_MAX 32767
  69. /*
  70. * Tmpnam, tmpfile and, sometimes, _tempnam try to create
  71. * temp files in the root directory of the current drive
  72. * (not in pwd, as suggested by some older MS doc's).
  73. * Redefining these macros does not effect the CRT functions.
  74. */
  75. #define _P_tmpdir "\\"
  76. #define _wP_tmpdir L"\\"
  77. /*
  78. * The maximum size of name (including NUL) that will be put in the user
  79. * supplied buffer caName for tmpnam.
  80. * Inferred from the size of the static buffer returned by tmpnam
  81. * when passed a NULL argument. May actually be smaller.
  82. */
  83. #define L_tmpnam (16)
  84. #define _IOFBF 0x0000
  85. #define _IOLBF 0x0040
  86. #define _IONBF 0x0004
  87. /*
  88. * The buffer size as used by setbuf such that it is equivalent to
  89. * (void) setvbuf(fileSetBuffer, caBuffer, _IOFBF, BUFSIZ).
  90. */
  91. #define BUFSIZ 512
  92. /* Constants for nOrigin indicating the position relative to which fseek
  93. * sets the file position. Enclosed in ifdefs because io.h could also
  94. * define them. (Though not anymore since io.h includes this file now.) */
  95. #ifndef SEEK_SET
  96. #define SEEK_SET (0)
  97. #endif
  98. #ifndef SEEK_CUR
  99. #define SEEK_CUR (1)
  100. #endif
  101. #ifndef SEEK_END
  102. #define SEEK_END (2)
  103. #endif
  104. #ifndef RC_INVOKED
  105. /*
  106. * I used to include stdarg.h at this point, in order to allow for the
  107. * functions later on in the file which use va_list. That conflicts with
  108. * using stdio.h and varargs.h in the same file, so I do the typedef myself.
  109. */
  110. #ifndef _VA_LIST
  111. #define _VA_LIST
  112. #if defined __GNUC__ && __GNUC__ >= 3
  113. typedef __builtin_va_list va_list;
  114. #else
  115. typedef char* va_list;
  116. #endif
  117. #endif
  118. /*
  119. * The structure underlying the FILE type.
  120. *
  121. * I still believe that nobody in their right mind should make use of the
  122. * internals of this structure. Provided by Pedro A. Aranda Gutiirrez
  123. * <[email protected]>.
  124. */
  125. #ifndef _FILE_DEFINED
  126. #define _FILE_DEFINED
  127. typedef struct _iobuf
  128. {
  129. char* _ptr;
  130. int _cnt;
  131. char* _base;
  132. int _flag;
  133. int _file;
  134. int _charbuf;
  135. int _bufsiz;
  136. char* _tmpfname;
  137. } FILE;
  138. #endif /* Not _FILE_DEFINED */
  139. /*
  140. * The standard file handles
  141. */
  142. #ifndef __DECLSPEC_SUPPORTED
  143. extern FILE (*__imp__iob)[]; /* A pointer to an array of FILE */
  144. #define _iob (*__imp__iob) /* An array of FILE */
  145. #else /* __DECLSPEC_SUPPORTED */
  146. __MINGW_IMPORT FILE _iob[]; /* An array of FILE imported from DLL. */
  147. #endif /* __DECLSPEC_SUPPORTED */
  148. #define stdin (&_iob[STDIN_FILENO])
  149. #define stdout (&_iob[STDOUT_FILENO])
  150. #define stderr (&_iob[STDERR_FILENO])
  151. #ifdef __cplusplus
  152. extern "C" {
  153. #endif
  154. /*
  155. * File Operations
  156. */
  157. FILE* fopen (const char*, const char*);
  158. FILE* freopen (const char*, const char*, FILE*);
  159. int fflush (FILE*);
  160. int fclose (FILE*);
  161. /* MS puts remove & rename (but not wide versions) in io.h also */
  162. int remove (const char*);
  163. int rename (const char*, const char*);
  164. FILE* tmpfile (void);
  165. char* tmpnam (char*);
  166. char* _tempnam (const char*, const char*);
  167. #ifndef NO_OLDNAMES
  168. char* tempnam (const char*, const char*);
  169. #endif
  170. int setvbuf (FILE*, char*, int, size_t);
  171. void setbuf (FILE*, char*);
  172. /*
  173. * Formatted Output
  174. */
  175. int fprintf (FILE*, const char*, ...);
  176. int printf (const char*, ...);
  177. int sprintf (char*, const char*, ...);
  178. int _snprintf (char*, size_t, const char*, ...);
  179. int vfprintf (FILE*, const char*, va_list);
  180. int vprintf (const char*, va_list);
  181. int vsprintf (char*, const char*, va_list);
  182. int _vsnprintf (char*, size_t, const char*, va_list);
  183. #ifndef __NO_ISOCEXT /* externs in libmingwex.a */
  184. int snprintf(char* s, size_t n, const char* format, ...);
  185. extern inline int vsnprintf (char* s, size_t n, const char* format,
  186. va_list arg)
  187. { return _vsnprintf ( s, n, format, arg); }
  188. #endif
  189. /*
  190. * Formatted Input
  191. */
  192. int fscanf (FILE*, const char*, ...);
  193. int scanf (const char*, ...);
  194. int sscanf (const char*, const char*, ...);
  195. /*
  196. * Character Input and Output Functions
  197. */
  198. int fgetc (FILE*);
  199. char* fgets (char*, int, FILE*);
  200. int fputc (int, FILE*);
  201. int fputs (const char*, FILE*);
  202. int getc (FILE*);
  203. int getchar (void);
  204. char* gets (char*);
  205. int putc (int, FILE*);
  206. int putchar (int);
  207. int puts (const char*);
  208. int ungetc (int, FILE*);
  209. /*
  210. * Direct Input and Output Functions
  211. */
  212. size_t fread (void*, size_t, size_t, FILE*);
  213. size_t fwrite (const void*, size_t, size_t, FILE*);
  214. /*
  215. * File Positioning Functions
  216. */
  217. int fseek (FILE*, long, int);
  218. long ftell (FILE*);
  219. void rewind (FILE*);
  220. #ifdef __USE_MINGW_FSEEK /* These are in libmingwex.a */
  221. /*
  222. * Workaround for limitations on win9x where a file contents are
  223. * not zero'd out if you seek past the end and then write.
  224. */
  225. int __mingw_fseek (FILE *, long, int);
  226. int __mingw_fwrite (const void*, size_t, size_t, FILE*);
  227. #define fseek(fp, offset, whence) __mingw_fseek(fp, offset, whence)
  228. #define fwrite(buffer, size, count, fp) __mingw_fwrite(buffer, size, count, fp)
  229. #endif /* __USE_MINGW_FSEEK */
  230. /*
  231. * An opaque data type used for storing file positions... The contents of
  232. * this type are unknown, but we (the compiler) need to know the size
  233. * because the programmer using fgetpos and fsetpos will be setting aside
  234. * storage for fpos_t structres. Actually I tested using a byte array and
  235. * it is fairly evident that the fpos_t type is a long (in CRTDLL.DLL).
  236. * Perhaps an unsigned long? TODO? It's definitely a 64-bit number in
  237. * MSVCRT however, and for now `long long' will do.
  238. */
  239. #ifdef __MSVCRT__
  240. typedef long long fpos_t;
  241. #else
  242. typedef long fpos_t;
  243. #endif
  244. int fgetpos (FILE*, fpos_t*);
  245. int fsetpos (FILE*, const fpos_t*);
  246. /*
  247. * Error Functions
  248. */
  249. void clearerr (FILE*);
  250. int feof (FILE*);
  251. int ferror (FILE*);
  252. void perror (const char*);
  253. #ifndef __STRICT_ANSI__
  254. /*
  255. * Pipes
  256. */
  257. FILE* _popen (const char*, const char*);
  258. int _pclose (FILE*);
  259. #ifndef NO_OLDNAMES
  260. FILE* popen (const char*, const char*);
  261. int pclose (FILE*);
  262. #endif
  263. /*
  264. * Other Non ANSI functions
  265. */
  266. int _flushall (void);
  267. int _fgetchar (void);
  268. int _fputchar (int);
  269. FILE* _fdopen (int, const char*);
  270. int _fileno (FILE*);
  271. #ifndef _NO_OLDNAMES
  272. int fgetchar (void);
  273. int fputchar (int);
  274. FILE* fdopen (int, const char*);
  275. int fileno (FILE*);
  276. #endif /* Not _NO_OLDNAMES */
  277. #endif /* Not __STRICT_ANSI__ */
  278. /* Wide versions */
  279. #ifndef _WSTDIO_DEFINED
  280. /* also in wchar.h - keep in sync */
  281. int fwprintf (FILE*, const wchar_t*, ...);
  282. int wprintf (const wchar_t*, ...);
  283. int swprintf (wchar_t*, const wchar_t*, ...);
  284. int _snwprintf (wchar_t*, size_t, const wchar_t*, ...);
  285. int vfwprintf (FILE*, const wchar_t*, va_list);
  286. int vwprintf (const wchar_t*, va_list);
  287. int vswprintf (wchar_t*, const wchar_t*, va_list);
  288. int _vsnwprintf (wchar_t*, size_t, const wchar_t*, va_list);
  289. int fwscanf (FILE*, const wchar_t*, ...);
  290. int wscanf (const wchar_t*, ...);
  291. int swscanf (const wchar_t*, const wchar_t*, ...);
  292. wint_t fgetwc (FILE*);
  293. wint_t fputwc (wchar_t, FILE*);
  294. wint_t ungetwc (wchar_t, FILE*);
  295. #ifdef __MSVCRT__
  296. wchar_t* fgetws (wchar_t*, int, FILE*);
  297. int fputws (const wchar_t*, FILE*);
  298. wint_t getwc (FILE*);
  299. wint_t getwchar (void);
  300. wchar_t* _getws (wchar_t*);
  301. wint_t putwc (wint_t, FILE*);
  302. int _putws (const wchar_t*);
  303. wint_t putwchar (wint_t);
  304. FILE* _wfopen (const wchar_t*, const wchar_t*);
  305. FILE* _wfreopen (const wchar_t*, const wchar_t*, FILE*);
  306. FILE* _wfsopen (const wchar_t*, const wchar_t*, int);
  307. wchar_t* _wtmpnam (wchar_t*);
  308. wchar_t* _wtempnam (const wchar_t*, const wchar_t*);
  309. int _wrename (const wchar_t*, const wchar_t*);
  310. int _wremove (const wchar_t*);
  311. void _wperror (const wchar_t*);
  312. FILE* _wpopen (const wchar_t*, const wchar_t*);
  313. #endif /* __MSVCRT__ */
  314. #ifndef __NO_ISOCEXT /* externs in libmingwex.a */
  315. int snwprintf(wchar_t* s, size_t n, const wchar_t* format, ...);
  316. extern inline int vsnwprintf (wchar_t* s, size_t n, const wchar_t* format,
  317. va_list arg)
  318. { return _vsnwprintf ( s, n, format, arg); }
  319. #endif
  320. #define _WSTDIO_DEFINED
  321. #endif /* _WSTDIO_DEFINED */
  322. #ifndef __STRICT_ANSI__
  323. #ifdef __MSVCRT__
  324. #ifndef NO_OLDNAMES
  325. FILE* wpopen (const wchar_t*, const wchar_t*);
  326. #endif /* not NO_OLDNAMES */
  327. #endif /* MSVCRT runtime */
  328. /*
  329. * Other Non ANSI wide functions
  330. */
  331. wint_t _fgetwchar (void);
  332. wint_t _fputwchar (wint_t);
  333. int _getw (FILE*);
  334. int _putw (int, FILE*);
  335. #ifndef _NO_OLDNAMES
  336. wint_t fgetwchar (void);
  337. wint_t fputwchar (wint_t);
  338. int getw (FILE*);
  339. int putw (int, FILE*);
  340. #endif /* Not _NO_OLDNAMES */
  341. #endif /* __STRICT_ANSI */
  342. #ifdef __cplusplus
  343. }
  344. #endif
  345. #endif /* Not RC_INVOKED */
  346. #endif /* _STDIO_H_ */