home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / libnix-0.8-src.lha / libnix-0.8 / sources / headers / stdio.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-12  |  3.4 KB  |  93 lines

  1. #ifndef STDIO_H
  2. #define STDIO_H
  3. #include <stdarg.h>
  4.  
  5. /* Adjusted to be compatible with the GNUC-headers
  6.  * (At least for normal ANSI stuff)
  7.  * Member names are not the same, but they need not be :-)
  8.  */
  9.  
  10. typedef long fpos_t;
  11.  
  12. typedef struct __FILE
  13. {
  14.   unsigned char *p;      /* pointer to actual character */
  15.   int incount;          /* Bytes left in buffer for reading, writemode: 0 */
  16.   int outcount;       /* Space left in buffer for writing + fp->linebufsize,
  17.                * readmode: 0 
  18.                            */
  19.   short flags;          /* Some flags: 0x01 line buffered
  20.                *         0x02 unbuffered
  21.                *         0x04 read mode
  22.                *         0x08 write mode
  23.                *         0x20 EOF read
  24.                *         0x40 error encountered
  25.                            *             0x80 buffer malloc'ed by library
  26.                *         0x200 sprintf/sscanf buffer 
  27.                            */
  28.   short file;             /* The filehandle */
  29.   unsigned char *buffer;  /* original buffer pointer */
  30.   int bufsize;          /* size of the buffer */
  31.   int linebufsize;      /* 0 full buffered
  32.                * -bufsize line buffered&write mode
  33.                * readmode: undefined */
  34. /* from this point on not binary compatible to gnu headers */
  35.   unsigned char unget[4]; /* ungetc buffer 4 bytes necessary (for -Na*)
  36.                            * ANSI requires 3 bytes (for -.*), so one more
  37.                            * doesn't matter
  38.                            */
  39.   unsigned char *tmpp;      /* Stored p if ungetc pending, otherwise NULL */
  40.   int tmpinc;          /* Stored incount if ungetc pending, otherwise undefined */
  41.   long tmpdir;            /* lock to directory if temporary file */
  42.   char *name;             /* filename if temporary file */
  43. } FILE;
  44.  
  45. #define NULL ((void *)0l)
  46. #define BUFSIZ 1024
  47. #define EOF (-1)
  48. #define SEEK_SET 0
  49. #define SEEK_CUR 1
  50. #define SEEK_END 2
  51. #define _IOFBF 0
  52. #define _IOLBF 1
  53. #define _IONBF 2
  54.  
  55. extern FILE *fopen(const char *filename,const char *mode);
  56. extern FILE *freopen(const char *filename,const char *mode,FILE *stream);
  57. extern int fclose(FILE *stream);
  58. extern int fgetc(FILE *stream);
  59. extern int fputc(int c,FILE *stream);
  60. extern int ungetc(int c,FILE *stream);
  61. extern int sprintf(char *s,const char *format,...);
  62. extern int sscanf(const char *s,const char *format,...);
  63. extern int vprintf(const char *format,va_list args);
  64. extern int vsprintf(char *s,const char *format,va_list args);
  65. extern int vfprintf(FILE *stream,const char *format,va_list args);
  66. extern int vscanf(const char *format,va_list args);
  67. extern int vsscanf(const char *s,const char *format,va_list args);
  68. extern int vfscanf(FILE *stream,const char *format,va_list args);
  69. extern int fseek(FILE *stream,long int offset,int whence);
  70. extern int fputs(const char *s,FILE *stream);
  71. extern long int ftell(FILE *stream);
  72. extern int setvbuf(FILE *stream,char *buf,int mode,unsigned long size);
  73.  
  74. /* More GCC headers compatibility */
  75.  
  76. extern int __swbuf(int c,FILE *stream);
  77. extern int __srget(FILE *stream);
  78. extern FILE **__sF; /* Standard I/O streams */
  79. #define stdin  (__sF[0]) /* Other streams are not in __sF */
  80. #define stdout (__sF[1])
  81. #define stderr (__sF[2])
  82.  
  83. /* Be careful: We have side effects and use incount in __srget -
  84.                must use comma-operator */
  85. #define getc(fp) ((fp)->incount--,(fp)->incount>=0?(int)*(fp)->p++:__srget(fp))
  86. #define putc(c,fp) \
  87. ((fp)->outcount--,(fp)->outcount>=0|| \
  88. ((fp)->outcount>=(fp)->linebufsize&&(char)(c)!='\n')? \
  89. *(fp)->p++=(c):__swbuf((c),(fp)))
  90. #define ferror(fp) ((fp)->flags&64)
  91. #define feof(fp)   ((fp)->flags&32)
  92. #endif
  93.