home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / programacao / cwin / c.exe / $INSTDIR / include / stdio.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-12-15  |  10.4 KB  |  421 lines

  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 directory separator.
  9.  *
  10.  * This file is part of the Mingw32 package.
  11.  *
  12.  * Contributors:
  13.  *  Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
  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.10 $
  26.  * $Author: earnie $
  27.  * $Date: 2002/11/12 15:29:39 $
  28.  *
  29.  */
  30.  
  31. #ifndef _STDIO_H_
  32. #define    _STDIO_H_
  33.  
  34. /* All the headers include this file. */
  35. #include <_mingw.h>
  36.  
  37. #ifndef RC_INVOKED
  38. #define __need_size_t
  39. #define __need_NULL
  40. #define __need_wchar_t
  41. #define    __need_wint_t
  42. #include <stddef.h>
  43. #define __need___va_list
  44. #include <stdarg.h>
  45. #endif    /* Not RC_INVOKED */
  46.  
  47.  
  48. /* Flags for the iobuf structure  */
  49. #define    _IOREAD    1 /* currently reading */
  50. #define    _IOWRT    2 /* currently writing */
  51. #define    _IORW    0x0080 /* opened as "r+w" */
  52.  
  53.  
  54. /*
  55.  * The three standard file pointers provided by the run time library.
  56.  * NOTE: These will go to the bit-bucket silently in GUI applications!
  57.  */
  58. #define    STDIN_FILENO    0
  59. #define    STDOUT_FILENO    1
  60. #define    STDERR_FILENO    2
  61.  
  62. /* Returned by various functions on end of file condition or error. */
  63. #define    EOF    (-1)
  64.  
  65. /*
  66.  * The maximum length of a file name. You should use GetVolumeInformation
  67.  * instead of this constant. But hey, this works.
  68.  *
  69.  * NOTE: This is used in the structure _finddata_t (see io.h) so changing it
  70.  *       is probably not a good idea.
  71.  */
  72. #define    FILENAME_MAX    (260)
  73.  
  74. /*
  75.  * The maximum number of files that may be open at once. I have set this to
  76.  * a conservative number. The actual value may be higher.
  77.  */
  78. #define FOPEN_MAX    (20)
  79.  
  80. /* After creating this many names, tmpnam and tmpfile return NULL */
  81. #define TMP_MAX    32767
  82. /*
  83.  * Tmpnam, tmpfile and, sometimes, _tempnam try to create
  84.  * temp files in the root directory of the current drive
  85.  * (not in pwd, as suggested by some older MS doc's).
  86.  * Redefining these macros does not effect the CRT functions.
  87.  */
  88. #define _P_tmpdir   "\\"
  89. #define _wP_tmpdir  L"\\"
  90.  
  91. /*
  92.  * The maximum size of name (including NUL) that will be put in the user
  93.  * supplied buffer caName for tmpnam.
  94.  * Inferred from the size of the static buffer returned by tmpnam
  95.  * when passed a NULL argument. May actually be smaller.
  96.  */
  97. #define L_tmpnam (16)
  98.  
  99. #define _IOFBF    0x0000  /* full buffered */
  100. #define _IOLBF    0x0040  /* line buffered */
  101. #define _IONBF    0x0004  /* not buffered */
  102.  
  103. #define _IOMYBUF  0x0008  /* stdio malloc()'d buffer */
  104. #define _IOEOF    0x0010  /* EOF reached on read */
  105. #define _IOERR    0x0020  /* I/O error from system */
  106. #define _IOSTRG   0x0040  /* Strange or no file descriptor */
  107. #ifdef _POSIX_SOURCE
  108. # define _IOAPPEND 0x0200
  109. #endif
  110. /*
  111.  * The buffer size as used by setbuf such that it is equivalent to
  112.  * (void) setvbuf(fileSetBuffer, caBuffer, _IOFBF, BUFSIZ).
  113.  */
  114. #define    BUFSIZ    512
  115.  
  116. /* Constants for nOrigin indicating the position relative to which fseek
  117.  * sets the file position. Enclosed in ifdefs because io.h could also
  118.  * define them. (Though not anymore since io.h includes this file now.) */
  119. #ifndef    SEEK_SET
  120. #define SEEK_SET    (0)
  121. #endif
  122.  
  123. #ifndef    SEEK_CUR
  124. #define    SEEK_CUR    (1)
  125. #endif
  126.  
  127. #ifndef    SEEK_END
  128. #define SEEK_END    (2)
  129. #endif
  130.  
  131.  
  132. #ifndef    RC_INVOKED
  133.  
  134. #ifdef __GNUC__
  135. #define __VALIST __gnuc_va_list
  136. #else
  137. #define __VALIST char*
  138. #endif
  139.  
  140. /*
  141.  * The structure underlying the FILE type.
  142.  *
  143.  * I still believe that nobody in their right mind should make use of the
  144.  * internals of this structure. Provided by Pedro A. Aranda Gutiirrez
  145.  * <paag@tid.es>.
  146.  */
  147. #ifndef _FILE_DEFINED
  148. #define    _FILE_DEFINED
  149. typedef struct _iobuf
  150. {
  151.     char*    _ptr;
  152.     int    _cnt;
  153.     char*    _base;
  154.     int    _flag;
  155.     int    _file;
  156.     int    _charbuf;
  157.     int    _bufsiz;
  158.     char*    _tmpfname;
  159. } FILE;
  160. #endif    /* Not _FILE_DEFINED */
  161.  
  162.  
  163. /*
  164.  * The standard file handles
  165.  */
  166. #ifndef __DECLSPEC_SUPPORTED
  167.  
  168. extern FILE (*_imp___iob)[];    /* A pointer to an array of FILE */
  169.  
  170. #define _iob    (*_imp___iob)    /* An array of FILE */
  171.  
  172. #else /* __DECLSPEC_SUPPORTED */
  173.  
  174. __MINGW_IMPORT FILE _iob[];    /* An array of FILE imported from DLL. */
  175.  
  176. #endif /* __DECLSPEC_SUPPORTED */
  177.  
  178. #define stdin    (&_iob[STDIN_FILENO])
  179. #define stdout    (&_iob[STDOUT_FILENO])
  180. #define stderr    (&_iob[STDERR_FILENO])
  181.  
  182. #ifdef __cplusplus
  183. extern "C" {
  184. #endif
  185.  
  186. /*
  187.  * File Operations
  188.  */
  189. FILE*    fopen (const char*, const char*);
  190. FILE*    freopen (const char*, const char*, FILE*);
  191. int    fflush (FILE*);
  192. int    fclose (FILE*);
  193. /* MS puts remove & rename (but not wide versions) in io.h  also */
  194. int    remove (const char*);
  195. int    rename (const char*, const char*);
  196. FILE*    tmpfile (void);
  197. char*    tmpnam (char*);
  198. char*    _tempnam (const char*, const char*);
  199.  
  200. #ifndef    NO_OLDNAMES
  201. char*    tempnam (const char*, const char*);
  202. #endif
  203.  
  204. int    setvbuf (FILE*, char*, int, size_t);
  205.  
  206. void    setbuf (FILE*, char*);
  207.  
  208. /*
  209.  * Formatted Output
  210.  */
  211.  
  212. int    fprintf (FILE*, const char*, ...);
  213. int    printf (const char*, ...);
  214. int    sprintf (char*, const char*, ...);
  215. int    _snprintf (char*, size_t, const char*, ...);
  216. int    vfprintf (FILE*, const char*, __VALIST);
  217. int    vprintf (const char*, __VALIST);
  218. int    vsprintf (char*, const char*, __VALIST);
  219. int    _vsnprintf (char*, size_t, const char*, __VALIST);
  220.  
  221. #ifndef __NO_ISOCEXT  /* externs in libmingwex.a */
  222. int snprintf(char* s, size_t n, const char*  format, ...);
  223. extern __inline__ int vsnprintf (char* s, size_t n, const char* format,
  224.                __VALIST arg)
  225.   { return _vsnprintf ( s, n, format, arg); }
  226. #endif
  227.  
  228. /*
  229.  * Formatted Input
  230.  */
  231.  
  232. int    fscanf (FILE*, const char*, ...);
  233. int    scanf (const char*, ...);
  234. int    sscanf (const char*, const char*, ...);
  235. /*
  236.  * Character Input and Output Functions
  237.  */
  238.  
  239. int    fgetc (FILE*);
  240. char*    fgets (char*, int, FILE*);
  241. int    fputc (int, FILE*);
  242. int    fputs (const char*, FILE*);
  243. int    getc (FILE*);
  244. int    getchar (void);
  245. char*    gets (char*);
  246. int    putc (int, FILE*);
  247. int    putchar (int);
  248. int    puts (const char*);
  249. int    ungetc (int, FILE*);
  250.  
  251. /*
  252.  * Direct Input and Output Functions
  253.  */
  254.  
  255. size_t    fread (void*, size_t, size_t, FILE*);
  256. size_t    fwrite (const void*, size_t, size_t, FILE*);
  257.  
  258. /*
  259.  * File Positioning Functions
  260.  */
  261.  
  262. int    fseek (FILE*, long, int);
  263. long    ftell (FILE*);
  264. void    rewind (FILE*);
  265.  
  266. #ifdef __USE_MINGW_FSEEK  /* These are in libmingwex.a */
  267. /*
  268.  * Workaround for limitations on win9x where a file contents are
  269.  * not zero'd out if you seek past the end and then write.
  270.  */
  271.  
  272. int __mingw_fseek (FILE *, long, int);
  273. int __mingw_fwrite (const void*, size_t, size_t, FILE*);
  274. #define fseek(fp, offset, whence)  __mingw_fseek(fp, offset, whence)
  275. #define fwrite(buffer, size, count, fp)  __mingw_fwrite(buffer, size, count, fp)
  276. #endif /* __USE_MINGW_FSEEK */
  277.  
  278. /*
  279.  * An opaque data type used for storing file positions... The contents of
  280.  * this type are unknown, but we (the compiler) need to know the size
  281.  * because the programmer using fgetpos and fsetpos will be setting aside
  282.  * storage for fpos_t structres. Actually I tested using a byte array and
  283.  * it is fairly evident that the fpos_t type is a long (in CRTDLL.DLL).
  284.  * Perhaps an unsigned long? TODO? It's definitely a 64-bit number in
  285.  * MSVCRT however, and for now `long long' will do.
  286.  */
  287. #ifdef __MSVCRT__
  288. typedef long long fpos_t;
  289. #else
  290. typedef long    fpos_t;
  291. #endif
  292.  
  293. int    fgetpos    (FILE*, fpos_t*);
  294. int    fsetpos (FILE*, const fpos_t*);
  295.  
  296. /*
  297.  * Error Functions
  298.  */
  299.  
  300. void    clearerr (FILE*);
  301. int    feof (FILE*);
  302. int    ferror (FILE*);
  303. void    perror (const char*);
  304.  
  305.  
  306. #ifndef __STRICT_ANSI__
  307. /*
  308.  * Pipes
  309.  */
  310. FILE*    _popen (const char*, const char*);
  311. int    _pclose (FILE*);
  312.  
  313. #ifndef NO_OLDNAMES
  314. FILE*    popen (const char*, const char*);
  315. int    pclose (FILE*);
  316. #endif
  317.  
  318. /*
  319.  * Other Non ANSI functions
  320.  */
  321. int    _flushall (void);
  322. int    _fgetchar (void);
  323. int    _fputchar (int);
  324. FILE*    _fdopen (int, const char*);
  325. int    _fileno (FILE*);
  326. int    _fcloseall(void);
  327. #ifdef __MSVCRT__
  328. int    _getmaxstdio(void);
  329. int    _setmaxstdio(int);
  330. #endif
  331.  
  332. #ifndef _NO_OLDNAMES
  333. int    fgetchar (void);
  334. int    fputchar (int);
  335. FILE*    fdopen (int, const char*);
  336. int    fileno (FILE*);
  337. #endif    /* Not _NO_OLDNAMES */
  338.  
  339. #endif    /* Not __STRICT_ANSI__ */
  340.  
  341. /* Wide  versions */
  342.  
  343. #ifndef _WSTDIO_DEFINED
  344. /*  also in wchar.h - keep in sync */
  345. int    fwprintf (FILE*, const wchar_t*, ...);
  346. int    wprintf (const wchar_t*, ...);
  347. int    swprintf (wchar_t*, const wchar_t*, ...);
  348. int    _snwprintf (wchar_t*, size_t, const wchar_t*, ...);
  349. int    vfwprintf (FILE*, const wchar_t*, __VALIST);
  350. int    vwprintf (const wchar_t*, __VALIST);
  351. int    vswprintf (wchar_t*, const wchar_t*, __VALIST);
  352. int    _vsnwprintf (wchar_t*, size_t, const wchar_t*, __VALIST);
  353. int    fwscanf (FILE*, const wchar_t*, ...);
  354. int    wscanf (const wchar_t*, ...);
  355. int    swscanf (const wchar_t*, const wchar_t*, ...);
  356. wint_t    fgetwc (FILE*);
  357. wint_t    fputwc (wchar_t, FILE*);
  358. wint_t    ungetwc (wchar_t, FILE*);
  359. #ifdef __MSVCRT__ 
  360. wchar_t* fgetws (wchar_t*, int, FILE*);
  361. int    fputws (const wchar_t*, FILE*);
  362. wint_t    getwc (FILE*);
  363. wint_t    getwchar (void);
  364. wchar_t* _getws (wchar_t*);
  365. wint_t    putwc (wint_t, FILE*);
  366. int    _putws (const wchar_t*);
  367. wint_t    putwchar (wint_t);
  368. FILE*    _wfdopen(int, wchar_t *);
  369. FILE*    _wfopen (const wchar_t*, const wchar_t*);
  370. FILE*    _wfreopen (const wchar_t*, const wchar_t*, FILE*);
  371. FILE*    _wfsopen (const wchar_t*, const wchar_t*, int);
  372. wchar_t* _wtmpnam (wchar_t*);
  373. wchar_t* _wtempnam (const wchar_t*, const wchar_t*);
  374. int    _wrename (const wchar_t*, const wchar_t*);
  375. int    _wremove (const wchar_t*);
  376. void    _wperror (const wchar_t*);
  377. FILE*    _wpopen (const wchar_t*, const wchar_t*);
  378. #endif    /* __MSVCRT__ */
  379.  
  380. #ifndef __NO_ISOCEXT  /* externs in libmingwex.a */
  381. int snwprintf(wchar_t* s, size_t n, const wchar_t*  format, ...);
  382. extern __inline__ int
  383. vsnwprintf (wchar_t* s, size_t n, const wchar_t* format, __VALIST arg)
  384.   { return _vsnwprintf ( s, n, format, arg);}
  385. #endif
  386.  
  387. #define _WSTDIO_DEFINED
  388. #endif /* _WSTDIO_DEFINED */
  389.  
  390. #ifndef __STRICT_ANSI__
  391. #ifdef __MSVCRT__
  392. #ifndef NO_OLDNAMES
  393. FILE*    wpopen (const wchar_t*, const wchar_t*);
  394. #endif /* not NO_OLDNAMES */
  395. #endif /* MSVCRT runtime */
  396.  
  397. /*
  398.  * Other Non ANSI wide functions
  399.  */
  400. wint_t    _fgetwchar (void);
  401. wint_t    _fputwchar (wint_t);
  402. int    _getw (FILE*);
  403. int    _putw (int, FILE*);
  404.  
  405. #ifndef _NO_OLDNAMES
  406. wint_t    fgetwchar (void);
  407. wint_t    fputwchar (wint_t);
  408. int    getw (FILE*);
  409. int    putw (int, FILE*);
  410. #endif    /* Not _NO_OLDNAMES */
  411.  
  412. #endif /* __STRICT_ANSI */
  413.  
  414. #ifdef __cplusplus
  415. }
  416. #endif
  417.  
  418. #endif    /* Not RC_INVOKED */
  419.  
  420. #endif /* _STDIO_H_ */
  421.