stdio.in.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. /* A GNU-like <stdio.h>.
  2. Copyright (C) 2004, 2007-2008 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software Foundation,
  13. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  14. #if __GNUC__ >= 3
  15. @PRAGMA_SYSTEM_HEADER@
  16. #endif
  17. #if defined __need_FILE || defined __need___FILE
  18. /* Special invocation convention inside glibc header files. */
  19. #@INCLUDE_NEXT@ @NEXT_STDIO_H@
  20. #else
  21. /* Normal invocation convention. */
  22. #ifndef _GL_STDIO_H
  23. /* The include_next requires a split double-inclusion guard. */
  24. #@INCLUDE_NEXT@ @NEXT_STDIO_H@
  25. #ifndef _GL_STDIO_H
  26. #define _GL_STDIO_H
  27. #include <stdarg.h>
  28. #include <stddef.h>
  29. #if (@GNULIB_FSEEKO@ && @REPLACE_FSEEKO@) \
  30. || (@GNULIB_FTELLO@ && @REPLACE_FTELLO@) \
  31. || (@GNULIB_GETDELIM@ && !@HAVE_DECL_GETDELIM@) \
  32. || (@GNULIB_GETLINE@ && (!@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@))
  33. /* Get off_t and ssize_t. */
  34. # include <sys/types.h>
  35. #endif
  36. #ifndef __attribute__
  37. /* This feature is available in gcc versions 2.5 and later. */
  38. # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
  39. # define __attribute__(Spec) /* empty */
  40. # endif
  41. /* The __-protected variants of `format' and `printf' attributes
  42. are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
  43. # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
  44. # define __format__ format
  45. # define __printf__ printf
  46. # endif
  47. #endif
  48. /* The definition of GL_LINK_WARNING is copied here. */
  49. #ifdef __cplusplus
  50. extern "C" {
  51. #endif
  52. #if @GNULIB_FPRINTF_POSIX@
  53. # if @REPLACE_FPRINTF@
  54. # define fprintf rpl_fprintf
  55. extern int fprintf (FILE *fp, const char *format, ...)
  56. __attribute__ ((__format__ (__printf__, 2, 3)));
  57. # endif
  58. #elif @GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
  59. # define fprintf rpl_fprintf
  60. extern int fprintf (FILE *fp, const char *format, ...)
  61. __attribute__ ((__format__ (__printf__, 2, 3)));
  62. #elif defined GNULIB_POSIXCHECK
  63. # undef fprintf
  64. # define fprintf \
  65. (GL_LINK_WARNING ("fprintf is not always POSIX compliant - " \
  66. "use gnulib module fprintf-posix for portable " \
  67. "POSIX compliance"), \
  68. fprintf)
  69. #endif
  70. #if @GNULIB_VFPRINTF_POSIX@
  71. # if @REPLACE_VFPRINTF@
  72. # define vfprintf rpl_vfprintf
  73. extern int vfprintf (FILE *fp, const char *format, va_list args)
  74. __attribute__ ((__format__ (__printf__, 2, 0)));
  75. # endif
  76. #elif @GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
  77. # define vfprintf rpl_vfprintf
  78. extern int vfprintf (FILE *fp, const char *format, va_list args)
  79. __attribute__ ((__format__ (__printf__, 2, 0)));
  80. #elif defined GNULIB_POSIXCHECK
  81. # undef vfprintf
  82. # define vfprintf(s,f,a) \
  83. (GL_LINK_WARNING ("vfprintf is not always POSIX compliant - " \
  84. "use gnulib module vfprintf-posix for portable " \
  85. "POSIX compliance"), \
  86. vfprintf (s, f, a))
  87. #endif
  88. #if @GNULIB_PRINTF_POSIX@
  89. # if @REPLACE_PRINTF@
  90. /* Don't break __attribute__((format(printf,M,N))). */
  91. # define printf __printf__
  92. extern int printf (const char *format, ...)
  93. __attribute__ ((__format__ (__printf__, 1, 2)));
  94. # endif
  95. #elif @GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
  96. /* Don't break __attribute__((format(printf,M,N))). */
  97. # define printf __printf__
  98. extern int printf (const char *format, ...)
  99. __attribute__ ((__format__ (__printf__, 1, 2)));
  100. #elif defined GNULIB_POSIXCHECK
  101. # undef printf
  102. # define printf \
  103. (GL_LINK_WARNING ("printf is not always POSIX compliant - " \
  104. "use gnulib module printf-posix for portable " \
  105. "POSIX compliance"), \
  106. printf)
  107. /* Don't break __attribute__((format(printf,M,N))). */
  108. # define format(kind,m,n) format (__##kind##__, m, n)
  109. # define __format__(kind,m,n) __format__ (__##kind##__, m, n)
  110. # define ____printf____ __printf__
  111. # define ____scanf____ __scanf__
  112. # define ____strftime____ __strftime__
  113. # define ____strfmon____ __strfmon__
  114. #endif
  115. #if @GNULIB_VPRINTF_POSIX@
  116. # if @REPLACE_VPRINTF@
  117. # define vprintf rpl_vprintf
  118. extern int vprintf (const char *format, va_list args)
  119. __attribute__ ((__format__ (__printf__, 1, 0)));
  120. # endif
  121. #elif @GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
  122. # define vprintf rpl_vprintf
  123. extern int vprintf (const char *format, va_list args)
  124. __attribute__ ((__format__ (__printf__, 1, 0)));
  125. #elif defined GNULIB_POSIXCHECK
  126. # undef vprintf
  127. # define vprintf(f,a) \
  128. (GL_LINK_WARNING ("vprintf is not always POSIX compliant - " \
  129. "use gnulib module vprintf-posix for portable " \
  130. "POSIX compliance"), \
  131. vprintf (f, a))
  132. #endif
  133. #if @GNULIB_SNPRINTF@
  134. # if @REPLACE_SNPRINTF@
  135. # define snprintf rpl_snprintf
  136. # endif
  137. # if @REPLACE_SNPRINTF@ || !@HAVE_DECL_SNPRINTF@
  138. extern int snprintf (char *str, size_t size, const char *format, ...)
  139. __attribute__ ((__format__ (__printf__, 3, 4)));
  140. # endif
  141. #elif defined GNULIB_POSIXCHECK
  142. # undef snprintf
  143. # define snprintf \
  144. (GL_LINK_WARNING ("snprintf is unportable - " \
  145. "use gnulib module snprintf for portability"), \
  146. snprintf)
  147. #endif
  148. #if @GNULIB_VSNPRINTF@
  149. # if @REPLACE_VSNPRINTF@
  150. # define vsnprintf rpl_vsnprintf
  151. # endif
  152. # if @REPLACE_VSNPRINTF@ || !@HAVE_DECL_VSNPRINTF@
  153. extern int vsnprintf (char *str, size_t size, const char *format, va_list args)
  154. __attribute__ ((__format__ (__printf__, 3, 0)));
  155. # endif
  156. #elif defined GNULIB_POSIXCHECK
  157. # undef vsnprintf
  158. # define vsnprintf(b,s,f,a) \
  159. (GL_LINK_WARNING ("vsnprintf is unportable - " \
  160. "use gnulib module vsnprintf for portability"), \
  161. vsnprintf (b, s, f, a))
  162. #endif
  163. #if @GNULIB_SPRINTF_POSIX@
  164. # if @REPLACE_SPRINTF@
  165. # define sprintf rpl_sprintf
  166. extern int sprintf (char *str, const char *format, ...)
  167. __attribute__ ((__format__ (__printf__, 2, 3)));
  168. # endif
  169. #elif defined GNULIB_POSIXCHECK
  170. # undef sprintf
  171. # define sprintf \
  172. (GL_LINK_WARNING ("sprintf is not always POSIX compliant - " \
  173. "use gnulib module sprintf-posix for portable " \
  174. "POSIX compliance"), \
  175. sprintf)
  176. #endif
  177. #if @GNULIB_VSPRINTF_POSIX@
  178. # if @REPLACE_VSPRINTF@
  179. # define vsprintf rpl_vsprintf
  180. extern int vsprintf (char *str, const char *format, va_list args)
  181. __attribute__ ((__format__ (__printf__, 2, 0)));
  182. # endif
  183. #elif defined GNULIB_POSIXCHECK
  184. # undef vsprintf
  185. # define vsprintf(b,f,a) \
  186. (GL_LINK_WARNING ("vsprintf is not always POSIX compliant - " \
  187. "use gnulib module vsprintf-posix for portable " \
  188. "POSIX compliance"), \
  189. vsprintf (b, f, a))
  190. #endif
  191. #if @GNULIB_VASPRINTF@
  192. # if @REPLACE_VASPRINTF@
  193. # define asprintf rpl_asprintf
  194. # define vasprintf rpl_vasprintf
  195. # endif
  196. # if @REPLACE_VASPRINTF@ || !@HAVE_VASPRINTF@
  197. /* Write formatted output to a string dynamically allocated with malloc().
  198. If the memory allocation succeeds, store the address of the string in
  199. *RESULT and return the number of resulting bytes, excluding the trailing
  200. NUL. Upon memory allocation error, or some other error, return -1. */
  201. extern int asprintf (char **result, const char *format, ...)
  202. __attribute__ ((__format__ (__printf__, 2, 3)));
  203. extern int vasprintf (char **result, const char *format, va_list args)
  204. __attribute__ ((__format__ (__printf__, 2, 0)));
  205. # endif
  206. #endif
  207. #if @GNULIB_OBSTACK_PRINTF@
  208. # if @REPLACE_OBSTACK_PRINTF@
  209. # define obstack_printf rpl_osbtack_printf
  210. # define obstack_vprintf rpl_obstack_vprintf
  211. # endif
  212. # if @REPLACE_OBSTACK_PRINTF@ || !@HAVE_DECL_OBSTACK_PRINTF@
  213. struct obstack;
  214. /* Grow an obstack with formatted output. Return the number of
  215. bytes added to OBS. No trailing nul byte is added, and the
  216. object should be closed with obstack_finish before use. Upon
  217. memory allocation error, call obstack_alloc_failed_handler. Upon
  218. other error, return -1. */
  219. extern int obstack_printf (struct obstack *obs, const char *format, ...)
  220. __attribute__ ((__format__ (__printf__, 2, 3)));
  221. extern int obstack_vprintf (struct obstack *obs, const char *format,
  222. va_list args)
  223. __attribute__ ((__format__ (__printf__, 2, 0)));
  224. # endif
  225. #endif
  226. #if @GNULIB_FOPEN@
  227. # if @REPLACE_FOPEN@
  228. # undef fopen
  229. # define fopen rpl_fopen
  230. extern FILE * fopen (const char *filename, const char *mode);
  231. # endif
  232. #elif defined GNULIB_POSIXCHECK
  233. # undef fopen
  234. # define fopen(f,m) \
  235. (GL_LINK_WARNING ("fopen on Win32 platforms is not POSIX compatible - " \
  236. "use gnulib module fopen for portability"), \
  237. fopen (f, m))
  238. #endif
  239. #if @GNULIB_FREOPEN@
  240. # if @REPLACE_FREOPEN@
  241. # undef freopen
  242. # define freopen rpl_freopen
  243. extern FILE * freopen (const char *filename, const char *mode, FILE *stream);
  244. # endif
  245. #elif defined GNULIB_POSIXCHECK
  246. # undef freopen
  247. # define freopen(f,m,s) \
  248. (GL_LINK_WARNING ("freopen on Win32 platforms is not POSIX compatible - " \
  249. "use gnulib module freopen for portability"), \
  250. freopen (f, m, s))
  251. #endif
  252. #if @GNULIB_FSEEKO@
  253. # if @REPLACE_FSEEKO@
  254. /* Provide fseek, fseeko functions that are aware of a preceding
  255. fflush(), and which detect pipes. */
  256. # define fseeko rpl_fseeko
  257. extern int fseeko (FILE *fp, off_t offset, int whence);
  258. # define fseek(fp, offset, whence) fseeko (fp, (off_t)(offset), whence)
  259. # endif
  260. #elif defined GNULIB_POSIXCHECK
  261. # undef fseeko
  262. # define fseeko(f,o,w) \
  263. (GL_LINK_WARNING ("fseeko is unportable - " \
  264. "use gnulib module fseeko for portability"), \
  265. fseeko (f, o, w))
  266. #endif
  267. #if @GNULIB_FSEEK@ && @REPLACE_FSEEK@
  268. extern int rpl_fseek (FILE *fp, long offset, int whence);
  269. # undef fseek
  270. # if defined GNULIB_POSIXCHECK
  271. # define fseek(f,o,w) \
  272. (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
  273. "on 32-bit platforms - " \
  274. "use fseeko function for handling of large files"), \
  275. rpl_fseek (f, o, w))
  276. # else
  277. # define fseek rpl_fseek
  278. # endif
  279. #elif defined GNULIB_POSIXCHECK
  280. # ifndef fseek
  281. # define fseek(f,o,w) \
  282. (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
  283. "on 32-bit platforms - " \
  284. "use fseeko function for handling of large files"), \
  285. fseek (f, o, w))
  286. # endif
  287. #endif
  288. #if @GNULIB_FTELLO@
  289. # if @REPLACE_FTELLO@
  290. # define ftello rpl_ftello
  291. extern off_t ftello (FILE *fp);
  292. # define ftell(fp) ftello (fp)
  293. # endif
  294. #elif defined GNULIB_POSIXCHECK
  295. # undef ftello
  296. # define ftello(f) \
  297. (GL_LINK_WARNING ("ftello is unportable - " \
  298. "use gnulib module ftello for portability"), \
  299. ftello (f))
  300. #endif
  301. #if @GNULIB_FTELL@ && @REPLACE_FTELL@
  302. extern long rpl_ftell (FILE *fp);
  303. # undef ftell
  304. # if GNULIB_POSIXCHECK
  305. # define ftell(f) \
  306. (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
  307. "on 32-bit platforms - " \
  308. "use ftello function for handling of large files"), \
  309. rpl_ftell (f))
  310. # else
  311. # define ftell rpl_ftell
  312. # endif
  313. #elif defined GNULIB_POSIXCHECK
  314. # ifndef ftell
  315. # define ftell(f) \
  316. (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
  317. "on 32-bit platforms - " \
  318. "use ftello function for handling of large files"), \
  319. ftell (f))
  320. # endif
  321. #endif
  322. #if @GNULIB_FFLUSH@
  323. # if @REPLACE_FFLUSH@
  324. # define fflush rpl_fflush
  325. /* Flush all pending data on STREAM according to POSIX rules. Both
  326. output and seekable input streams are supported.
  327. Note! LOSS OF DATA can occur if fflush is applied on an input stream
  328. that is _not_seekable_ or on an update stream that is _not_seekable_
  329. and in which the most recent operation was input. Seekability can
  330. be tested with lseek(fileno(fp),0,SEEK_CUR). */
  331. extern int fflush (FILE *gl_stream);
  332. # endif
  333. #elif defined GNULIB_POSIXCHECK
  334. # undef fflush
  335. # define fflush(f) \
  336. (GL_LINK_WARNING ("fflush is not always POSIX compliant - " \
  337. "use gnulib module fflush for portable " \
  338. "POSIX compliance"), \
  339. fflush (f))
  340. #endif
  341. #if @GNULIB_FCLOSE@
  342. # if @REPLACE_FCLOSE@
  343. # define fclose rpl_fclose
  344. /* Close STREAM and its underlying file descriptor. */
  345. extern int fclose (FILE *stream);
  346. # endif
  347. #elif defined GNULIB_POSIXCHECK
  348. # undef fclose
  349. # define fclose(f) \
  350. (GL_LINK_WARNING ("fclose is not always POSIX compliant - " \
  351. "use gnulib module fclose for portable " \
  352. "POSIX compliance"), \
  353. fclose (f))
  354. #endif
  355. #if @GNULIB_FPUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
  356. # undef fputc
  357. # define fputc rpl_fputc
  358. extern int fputc (int c, FILE *stream);
  359. #endif
  360. #if @GNULIB_PUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
  361. # undef putc
  362. # define putc rpl_fputc
  363. extern int putc (int c, FILE *stream);
  364. #endif
  365. #if @GNULIB_PUTCHAR@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
  366. # undef putchar
  367. # define putchar rpl_putchar
  368. extern int putchar (int c);
  369. #endif
  370. #if @GNULIB_FPUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
  371. # undef fputs
  372. # define fputs rpl_fputs
  373. extern int fputs (const char *string, FILE *stream);
  374. #endif
  375. #if @GNULIB_PUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
  376. # undef puts
  377. # define puts rpl_puts
  378. extern int puts (const char *string);
  379. #endif
  380. #if @GNULIB_FWRITE@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
  381. # undef fwrite
  382. # define fwrite rpl_fwrite
  383. extern size_t fwrite (const void *ptr, size_t s, size_t n, FILE *stream);
  384. #endif
  385. #if @GNULIB_GETDELIM@
  386. # if !@HAVE_DECL_GETDELIM@
  387. /* Read input, up to (and including) the next occurrence of DELIMITER, from
  388. STREAM, store it in *LINEPTR (and NUL-terminate it).
  389. *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
  390. bytes of space. It is realloc'd as necessary.
  391. Return the number of bytes read and stored at *LINEPTR (not including the
  392. NUL terminator), or -1 on error or EOF. */
  393. extern ssize_t getdelim (char **lineptr, size_t *linesize, int delimiter,
  394. FILE *stream);
  395. # endif
  396. #elif defined GNULIB_POSIXCHECK
  397. # undef getdelim
  398. # define getdelim(l, s, d, f) \
  399. (GL_LINK_WARNING ("getdelim is unportable - " \
  400. "use gnulib module getdelim for portability"), \
  401. getdelim (l, s, d, f))
  402. #endif
  403. #if @GNULIB_GETLINE@
  404. # if @REPLACE_GETLINE@
  405. # undef getline
  406. # define getline rpl_getline
  407. # endif
  408. # if !@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@
  409. /* Read a line, up to (and including) the next newline, from STREAM, store it
  410. in *LINEPTR (and NUL-terminate it).
  411. *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
  412. bytes of space. It is realloc'd as necessary.
  413. Return the number of bytes read and stored at *LINEPTR (not including the
  414. NUL terminator), or -1 on error or EOF. */
  415. extern ssize_t getline (char **lineptr, size_t *linesize, FILE *stream);
  416. # endif
  417. #elif defined GNULIB_POSIXCHECK
  418. # undef getline
  419. # define getline(l, s, f) \
  420. (GL_LINK_WARNING ("getline is unportable - " \
  421. "use gnulib module getline for portability"), \
  422. getline (l, s, f))
  423. #endif
  424. #if @GNULIB_PERROR@
  425. # if @REPLACE_PERROR@
  426. # define perror rpl_perror
  427. /* Print a message to standard error, describing the value of ERRNO,
  428. (if STRING is not NULL and not empty) prefixed with STRING and ": ",
  429. and terminated with a newline. */
  430. extern void perror (const char *string);
  431. # endif
  432. #elif defined GNULIB_POSIXCHECK
  433. # undef perror
  434. # define perror(s) \
  435. (GL_LINK_WARNING ("perror is not always POSIX compliant - " \
  436. "use gnulib module perror for portability"), \
  437. perror (s))
  438. #endif
  439. #ifdef __cplusplus
  440. }
  441. #endif
  442. #endif /* _GL_STDIO_H */
  443. #endif /* _GL_STDIO_H */
  444. #endif