home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / h.z / STDIO.H < prev    next >
C/C++ Source or Header  |  1996-07-24  |  13KB  |  335 lines

  1. /*
  2.  *  stdio.h    Standard I/O functions
  3.  *
  4.  *  Copyright by WATCOM International Corp. 1988-1996.  All rights reserved.
  5.  */
  6. #ifndef _STDIO_H_INCLUDED
  7. #define _STDIO_H_INCLUDED
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11.  
  12. #ifndef _COMDEF_H_INCLUDED
  13.  #include <_comdef.h>
  14. #endif
  15.  
  16. #if defined(_M_IX86)
  17.   #pragma pack(__push,1);
  18. #else
  19.   #pragma pack(__push,8);
  20. #endif
  21.  
  22. #ifndef _WCHAR_T_DEFINED
  23. #define _WCHAR_T_DEFINED
  24. #define _WCHAR_T_DEFINED_
  25. #ifdef __cplusplus
  26. typedef long char wchar_t;
  27. #else
  28. typedef unsigned short wchar_t;
  29. #endif
  30. #endif
  31.  
  32. #ifndef _WCTYPE_T_DEFINED
  33. #define _WCTYPE_T_DEFINED
  34. #define _WCTYPE_T_DEFINED_
  35. typedef wchar_t wint_t;
  36. typedef wchar_t wctype_t;
  37. #endif
  38.  
  39. #ifndef _SIZE_T_DEFINED
  40. #define _SIZE_T_DEFINED
  41. #define _SIZE_T_DEFINED_
  42. typedef unsigned size_t;
  43. #endif
  44.  
  45. #ifndef NULL
  46.  #if defined(__SMALL__) || defined(__MEDIUM__) || defined(__386__) || defined(__AXP__) || defined(__PPC__)
  47.   #define NULL   0
  48.  #else
  49.   #define NULL   0L
  50.  #endif
  51. #endif
  52.  
  53. #ifndef _VA_LIST_DEFINED
  54. #define _VA_LIST_DEFINED
  55. #if defined(__PPC__)
  56.  #if defined(__NT__)
  57.     typedef char * __va_list;
  58.  #else
  59.     typedef struct {
  60.       char  __gpr;
  61.       char  __fpr;
  62.       char  __reserved[2];
  63.       char *__input_arg_area;
  64.       char *__reg_save_area;
  65.     } __va_list;
  66.   #endif
  67. #elif defined(__AXP__)
  68.   typedef struct {
  69.     char *__base;
  70.     int   __offset;
  71.   } __va_list;
  72. #elif defined(__HUGE__) || defined(__SW_ZU)
  73.   typedef char _WCFAR *__va_list[1];
  74. #else
  75.   typedef char *__va_list[1];
  76. #endif
  77. #endif
  78.  
  79. #if defined(__386__) || defined(__AXP__) || defined(__PPC__)
  80.  #define BUFSIZ     4096
  81. #else
  82.  #define BUFSIZ     512
  83. #endif
  84. #define _NFILES     20    /* number of files that can be handled */
  85. #define FILENAME_MAX    80
  86.  
  87. struct __stream_link;
  88. typedef struct    __iobuf {
  89.     unsigned char     *_ptr;        /* next character position */
  90.     int              _cnt;        /* number of characters left */
  91.     struct __stream_link *_link;     /* location of associated struct */
  92.     unsigned          _flag;    /* mode of file access */
  93.     int              _handle;    /* file handle */
  94.     unsigned          _bufsize;    /* size of buffer */
  95.     unsigned short      _ungotten;    /* used by ungetc and ungetwc */
  96. } FILE;
  97.  
  98. typedef long    fpos_t;
  99.  
  100. #if !defined(NO_EXT_KEYS) /* extensions enabled */
  101.  #define FOPEN_MAX    _NFILES
  102.  #define OPEN_MAX    FOPEN_MAX
  103.  #if defined(__OS2__) || defined(__NT__)
  104.   #define PATH_MAX    259 /* maximum length of full pathname excl. '\0' */
  105.  #else
  106.   #define PATH_MAX    143 /* maximum length of full pathname excl. '\0' */
  107.  #endif
  108. #else            /* extensions not enabled */
  109.  #define FOPEN_MAX    (_NFILES-2)
  110. #endif
  111.  
  112. #if defined(__SW_BR) || defined(_RTDLL) 
  113.  #define __iob __iob_br
  114. #endif
  115. #ifdef __SW_ND
  116.  _WCRTLINK extern FILE __iob[];
  117. #else
  118.  _WCRTLINK extern FILE _WCNEAR __iob[];
  119. #endif
  120. /*
  121.  *  Define macros to access the three default file pointer (and descriptors)
  122.  *  provided to each process by default.  They will always occupy the
  123.  *  first three file pointers in each processes' table.
  124.  */
  125. #define stdin    ((FILE *)&__iob[0])    /* standard input file    */
  126. #define stdout    ((FILE *)&__iob[1])    /* standard output file */
  127. #define stderr    ((FILE *)&__iob[2])    /* standard error file    */
  128. #ifndef NO_EXT_KEYS    /* extensions enabled */
  129. #if !defined(__NT__)
  130. #define stdaux    ((FILE *)&__iob[3])    /* standard auxiliary file  */
  131. #define stdprn    ((FILE *)&__iob[4])    /* standard printer file  */
  132. #endif
  133. #endif
  134.  
  135. /* values for _flag field in FILE struct and _iomode array */
  136.  
  137. #define _READ    0x0001    /* file opened for reading */
  138. #define _WRITE    0x0002    /* file opened for writing */
  139. #define _UNGET    0x0004    /* ungetc has been done */
  140. #define _BIGBUF 0x0008    /* big buffer allocated */
  141. #define _EOF    0x0010    /* EOF has occurred */
  142. #define _SFERR    0x0020    /* error has occurred on this file */
  143. #define _APPEND 0x0080    /* file opened for append */
  144. #define _BINARY 0x0040    /* file is binary, skip CRLF processing */
  145. #define _IOFBF    0x0100    /* full buffering */
  146. #define _IOLBF    0x0200    /* line buffering */
  147. #define _IONBF    0x0400    /* no buffering */
  148. #define _TMPFIL 0x0800    /* this is a temporary file */
  149. #define _DIRTY    0x1000    /* buffer has been modified */
  150. #define _ISTTY    0x2000    /* is console device */
  151. #define _DYNAMIC 0x4000 /* FILE is dynamically allocated   */
  152. #define _FILEEXT 0x8000 /* lseek with positive offset has been done */
  153. #define _COMMIT 0x0001    /* extended flag: commit OS buffers on flush */
  154.  
  155. #define EOF        (-1)        /*  End of File/Error return code   */
  156. #define WEOF        ((wint_t)(-1))    /*  EOF equivalent for wide chars   */
  157.  
  158. #define SEEK_SET    0            /*  Seek relative to start of file  */
  159. #define SEEK_CUR    1            /*  Seek relative to current positn */
  160. #define SEEK_END    2            /*  Seek relative to end of file    */
  161.  
  162. #define _NOT_ORIENTED    0        /* stream not yet oriented */
  163. #define _BYTE_ORIENTED    1        /* byte-oriented stream */
  164. #define _WIDE_ORIENTED    2        /* wide-oriented stream */
  165.  
  166. #define L_tmpnam    13
  167. #define _P_tmpdir   "\\"        /* used by _tempnam */
  168. #define _wP_tmpdir  L"\\"        /* used by _wtempnam */
  169. #define TMP_MAX     (26*26*26)        /*  Max times tmpnam can be called  */
  170.  
  171. _WCRTLINK extern void    clearerr( FILE *__fp );
  172. _WCRTLINK extern int    fclose( FILE *__fp );
  173. _WCRTLINK extern int    feof( FILE *__fp );
  174. _WCRTLINK extern int    ferror( FILE *__fp );
  175. _WCRTLINK extern int    fflush( FILE *__fp );
  176. _WCRTLINK extern int    fgetc( FILE *__fp );
  177. _WCRTLINK extern int    fgetpos( FILE *__fp, fpos_t *__pos );
  178. _WCRTLINK extern char    *fgets( char *__s, int __n, FILE *__fp );
  179. _WCRTLINK extern FILE    *fopen( const char *__filename, const char *__mode );
  180. _WCRTLINK extern int    fprintf( FILE *__fp, const char *__format, ... );
  181. _WCRTLINK extern int    fputc( int __c, FILE *__fp );
  182. _WCRTLINK extern int    fputs( const char *__s, FILE *__fp );
  183. _WCRTLINK extern size_t    fread( void *__ptr, size_t __size, size_t __n, 
  184.                    FILE *__fp );
  185. _WCRTLINK extern FILE    *freopen( const char *__filename, const char *__mode, 
  186.                   FILE *__fp );
  187. _WCRTLINK extern int    fscanf( FILE*__fp, const char *__format, ... );
  188. _WCRTLINK extern int    fseek( FILE *__fp, long int __offset, int __whence );
  189. _WCRTLINK extern int    fsetpos( FILE *__fp, const fpos_t *__pos );
  190. _WCRTLINK extern long int ftell( FILE *__fp );
  191. _WCRTLINK extern size_t    fwrite( const void *__ptr, size_t __size, size_t __n, 
  192.                     FILE *__fp );
  193. _WCRTLINK extern int    getc( FILE *__fp );
  194. _WCRTLINK extern int    getchar( void );
  195. _WCRTLINK extern int    _getw( FILE *__fp );
  196. _WCRTLINK extern char    *gets( char *__s );
  197. _WCRTLINK extern void    perror( const char *__s );
  198. _WCRTLINK extern FILE *    _popen( const char *__command, const char *__mode );
  199. _WCRTLINK extern int    _pclose( FILE *__fp );
  200. _WCRTLINK extern int    printf( const char *__format, ... );
  201. _WCRTLINK extern int    putc( int __c, FILE *__fp );
  202. _WCRTLINK extern int    putchar( int __c );
  203. _WCRTLINK extern int    _putw( int __binint, FILE *__fp );
  204. _WCRTLINK extern int    puts( const char *__s );
  205. _WCRTLINK extern int    remove( const char *__filename );
  206. _WCRTLINK extern int    rename( const char *__old, const char *__new );
  207. _WCRTLINK extern void    rewind( FILE *__fp );
  208. _WCRTLINK extern int    scanf( const char *__format, ... );
  209. _WCRTLINK extern void    setbuf( FILE *__fp, char *__buf );
  210. _WCRTLINK extern int    setvbuf( FILE *__fp, char *__buf, int __mode, 
  211.                  size_t __size );
  212. _WCRTLINK extern int    sprintf( char *__s, const char *__format, ... );
  213. _WCRTLINK extern int    sscanf( const char *__s, const char *__format, ... );
  214. _WCRTLINK extern char *    _tempnam( char *__dir, char *__prefix );
  215. _WCRTLINK extern FILE    *tmpfile( void );
  216. _WCRTLINK extern char    *tmpnam( char *__s );
  217. _WCRTLINK extern int    ungetc( int __c, FILE *__fp );
  218. _WCRTLINK extern int    vfprintf( FILE *__fp, const char *__format, 
  219.                   __va_list __arg );
  220. _WCRTLINK extern int    vprintf( const char *__format, __va_list __arg );
  221. _WCRTLINK extern int    vsprintf( char *__s, const char *__format, 
  222.                   __va_list __arg );
  223.  
  224. #if !defined(NO_EXT_KEYS) /* extensions enabled */
  225. _WCRTLINK extern int    fcloseall( void );
  226. _WCRTLINK extern FILE    *fdopen( int __handle, const char *__mode );
  227. _WCRTLINK extern FILE    *_fdopen( int __handle, const char *__mode );
  228. _WCRTLINK extern int    _grow_handles( int __new_count );
  229. _WCRTLINK extern int    _fgetchar( void );
  230. _WCRTLINK extern int    fgetchar( void );
  231. _WCRTLINK extern int    _fputchar( int __c );
  232. _WCRTLINK extern int    fputchar( int __c );
  233. _WCRTLINK extern FILE    *_fsopen( const char *__filename, const char *__mode, 
  234.                   int __shflag );
  235. _WCRTLINK extern int    flushall( void );
  236. _WCRTLINK extern int    vfscanf( FILE *__fp, const char *__format, 
  237.                  __va_list __arg );
  238. _WCRTLINK extern int    vscanf( const char *__format, __va_list __arg );
  239. _WCRTLINK extern int    vsscanf( const char *__s, const char *__format, 
  240.                  __va_list __arg );
  241. _WCRTLINK extern int    _bprintf( char *__buf, size_t __bufsize, 
  242.                   const char *__fmt, ... );
  243. _WCRTLINK extern int    _snprintf( char *__buf, size_t __bufsize, 
  244.                    const char *__fmt, ... );
  245. _WCRTLINK extern int    _vbprintf( char *__s, size_t __bufsize, 
  246.                    const char *__format, __va_list __arg );
  247. _WCRTLINK extern int    _vsnprintf( char *__s, size_t __bufsize, 
  248.                     const char *__format, __va_list __arg );
  249.  
  250. _WCRTLINK extern FILE    *_wfopen( const wchar_t *, const wchar_t * );
  251. _WCRTLINK extern int    fwprintf( FILE *, const wchar_t *, ... );
  252. _WCRTLINK extern int    fputws( const wchar_t *, FILE * );
  253. _WCRTLINK extern FILE    *_wfsopen( const wchar_t *__filename,
  254.                    const wchar_t *__mode,  int __shflag );
  255. _WCRTLINK extern FILE    *_wfdopen( int, const wchar_t * );
  256. _WCRTLINK extern FILE    *_wfreopen( const wchar_t *, const wchar_t *, FILE * );
  257. _WCRTLINK extern wint_t    putwc( wint_t, FILE * );
  258. _WCRTLINK extern wint_t    fputwc( wint_t, FILE * );
  259. _WCRTLINK extern wint_t    getwc( FILE * );
  260. _WCRTLINK extern wint_t    fgetwc( FILE * );
  261. _WCRTLINK extern wint_t    ungetwc( wint_t, FILE * );
  262. _WCRTLINK extern int    fwscanf( FILE *, const wchar_t *, ... );
  263. _WCRTLINK extern wchar_t *fgetws( wchar_t *, int, FILE * );
  264. _WCRTLINK extern int    vfwprintf( FILE *, const wchar_t *, __va_list );
  265. _WCRTLINK extern int    vfwscanf( FILE *, const wchar_t *, __va_list );
  266. _WCRTLINK extern int    vwscanf( const wchar_t *, __va_list );
  267. _WCRTLINK extern int    vswscanf( const wchar_t *, const wchar_t *, __va_list );
  268. _WCRTLINK extern int    vswprintf( wchar_t *, size_t, const wchar_t *, 
  269.                    __va_list );
  270. _WCRTLINK extern wint_t    getwchar( void );
  271. _WCRTLINK extern wint_t    _fgetwchar( void );
  272. _WCRTLINK extern wint_t    fgetwchar( void );
  273. _WCRTLINK extern wchar_t *_getws( wchar_t * );
  274. _WCRTLINK extern wchar_t *getws( wchar_t * );
  275. _WCRTLINK extern wint_t    putwchar( wint_t );
  276. _WCRTLINK extern int    _putws( const wchar_t * );
  277. _WCRTLINK extern int    putws( const wchar_t * );
  278. _WCRTLINK extern int    _wremove( const wchar_t * );
  279. _WCRTLINK extern wchar_t *_wtempnam( wchar_t *__dir, wchar_t *__prefix );
  280. _WCRTLINK extern wchar_t *_wtmpnam( wchar_t * );
  281. _WCRTLINK extern int    wprintf( const wchar_t *, ... );
  282. _WCRTLINK extern int    wscanf( const wchar_t *, ... );
  283. #ifndef swprintf
  284. _WCRTLINK extern int    swprintf( wchar_t *, size_t, const wchar_t *, ... );
  285. #endif
  286. _WCRTLINK extern int    swscanf( const wchar_t *, const wchar_t *, ... );
  287. _WCRTLINK extern wint_t    _fputwchar( wint_t );
  288. _WCRTLINK extern wint_t    fputwchar( wint_t );
  289. _WCRTLINK extern void    _wperror( const wchar_t * );
  290. _WCRTLINK extern int    vwprintf( const wchar_t *, __va_list );
  291. _WCRTLINK extern int    _bwprintf( wchar_t *, size_t, const wchar_t *, ... );
  292. _WCRTLINK extern int    _snwprintf( wchar_t *, size_t, const wchar_t *, ... );
  293. _WCRTLINK extern int    _vbwprintf( wchar_t *, size_t, const wchar_t *, __va_list );
  294. _WCRTLINK extern int    _vsnwprintf( wchar_t *, size_t, const wchar_t *, 
  295.                     __va_list );
  296. _WCRTLINK extern int    _wrename( const wchar_t *, const wchar_t * );
  297. _WCRTLINK extern FILE *    _wpopen( const wchar_t *__command, const wchar_t *__mode );
  298.  
  299. _WCRTLINK extern int    _usprintf( wchar_t *, const wchar_t *, ... );
  300. _WCRTLINK extern int    _uvsprintf( wchar_t *, const wchar_t *, __va_list );
  301.  
  302. #endif
  303.  
  304.  
  305. #define clearerr(fp)    ((fp)->_flag &= ~(_SFERR|_EOF))
  306. #define feof(fp)    ((fp)->_flag & _EOF)
  307. #define ferror(fp)    ((fp)->_flag & _SFERR)
  308. #define fileno(fp)    ((fp)->_handle)
  309. #define _fileno(fp)    ((fp)->_handle)
  310. #if defined(__SW_BD) || defined(__SW_BM)
  311. #define getc(fp)    fgetc(fp)
  312. #define putc(c,fp)    fputc(c,fp)
  313. #else
  314. #define getc(fp) \
  315.     ((fp)->_cnt<=0 \
  316.     || (unsigned)((*(fp)->_ptr)-'\x0d')<=('\0x1a'-'\0x0d') \
  317.     ? fgetc(fp) \
  318.     : ((fp)->_cnt--,*(fp)->_ptr++))
  319. #define putc(c,fp) \
  320.     ((fp)->_flag&_IONBF \
  321.     || (fp)->_bufsize-(fp)->_cnt<=1 \
  322.     ? fputc(c,fp) \
  323.     : ((*(fp)->_ptr=(unsigned char)(c))=='\n') \
  324.     ? fputc('\n',fp) \
  325.     : ((fp)->_flag|=_DIRTY,(fp)->_cnt++,*(fp)->_ptr++))
  326. #endif
  327. #define getchar()    getc(stdin)
  328. #define putchar(c)    putc(c,stdout)
  329.  
  330. #pragma pack(__pop);
  331. #ifdef __cplusplus
  332. };
  333. #endif
  334. #endif
  335.