]> pd.if.org Git - pdclib/blob - includes/stdio.h
Merged PDPCLIB code.
[pdclib] / includes / stdio.h
1 // ----------------------------------------------------------------------------
2 // $Id$
3 // ----------------------------------------------------------------------------
4 // Public Domain C Library - http://pdclib.sourceforge.net
5 // This code is Public Domain. Use, modify, and redistribute at will.
6 // ----------------------------------------------------------------------------
7 // Input/output
8 // ----------------------------------------------------------------------------
9
10 #ifndef __STDIO_H
11 #define __STDIO_H __STDIO_H
12
13 // ----------------------------------------------------------------------------
14 // MACROS
15
16 #define _IOFBF       // TODO
17 #define _IOLBF       // TODO
18 #define _IONBF       // TODO
19 #define BUFSIZ       // TODO
20 #define EOF          // TODO
21 #define FILENAME_MAX // TODO
22 #define FOPEN_MAX    // TODO
23 #define L_tmpnam     // TODO
24 #define NULL         0
25 #define SEEK_CUR     // TODO
26 #define SEEK_END     // TODO
27 #define SEEK_SET     // TODO
28 #define TMP_MAX      // TODO
29
30 #define stderr // TODO
31 #define stdin  // TODO
32 #define stdout // TODO
33
34 // ----------------------------------------------------------------------------
35 // TYPEDEFS
36
37 typedef FILE;   // TODO
38 typedef fpos_t; // TODO
39 typedef size_t; // TODO
40
41 // ----------------------------------------------------------------------------
42 // FUNCTIONS
43
44 // TODO: Documentation.
45
46 void clearerr( FILE * stream );
47 int fclose( FILE * stream );
48 int feof( FILE * stream );
49 int ferror( FILE * stream );
50 int fflush( FILE * stream );
51 FILE * fopen( const char * restrict filename, const char * restrict mode );
52 FILE * freopen( const char * restrict filename, const char * restrict mode, FILE * stream );
53 int remove( const char * filename );
54 int rename( const char * old, const char * new );
55 void rewind( FILE * stream );
56 void setbuf( FILE * restrict stream, char * restrict buf );
57 int setvbuf( FILE * restrict stream, char * restrict buf, int mode, size_t size );
58 FILE * tmpfile( void )
59 char * tmpnam( char * s );
60
61 int fseek( FILE * stream, long offset, int mode );
62 int fsetpos( FILE * stream, const fpos_t * pos );
63 int fgetpos( FILE * restrict stream, fpos_t * restrict pos );
64 long ftell( FILE * stream );
65
66 int fgetc( FILE * stream );
67 char *fgets( char * restrict s, int n, FILE * restrict stream );
68 size_t fread( void * restrict ptr, size_t size, size_t nelem, FILE * restrict stream );
69 int getc( FILE * stream );
70 int getchar( void );
71 char * gets( char * s );
72 int ungetc( int c, FILE * stream );
73
74 int fputc( int c, FILE * stream );
75 int fputs( const char * restrict s, FILE * restrict stream );
76 size_t fwrite( const void * restrict ptr, size_t size, size_t nelem, FILE * restrict stream );
77 void perror( const char * s );
78 int putc( int c, FILE * stream );
79 int putchar( int c );
80 int puts( const char * s );
81
82 int fscanf( FILE * restrict stream, const char * restrict format, ... );
83 int scanf( const char * restrict format, ... );
84 int sscanf( const char * restrict s, const char * restrict format, ... );
85 int vfscanf( FILE * restrict stream, const char * restrict format, va_list ap );
86 int vscanf( const char * restrict format, va_list ap );
87 int vsscanf( const char * restrict s, const char * restrict format, va_list ap );
88
89 int fprintf( FILE * restrict stream, const char * restrict format, ... );
90 int printf( const char * restrict format, ... );
91 int snprintf( char * restrict s, size_t n, const char * restrict format, ... );
92 int sprintf( char * restrict s, const char * restrict format, ... );
93 int vfprintf( FILE * restrict stream, const char * restrict format, va_list ap );
94 int vprintf( const char * restrict format, va_list ap );
95 int vsnprintf( char * restrict s, size_t n, const char * restrict format, va_list ap );
96 int vsprintf( char * restrict s, const char * restrict format, va_list ap);
97
98 /* PDPC code - unreviewed
99 /*
100     What we have is an internal buffer, which is 8 characters
101     longer than the actually used buffer.  E.g. say BUFSIZ is
102     512 bytes, then we actually allocate 520 bytes.  The first
103     2 characters will be junk, the next 2 characters set to NUL,
104     for protection against some backward-compares.  The fourth-last
105     character is set to '\n', to protect against overscan.  The
106     last 3 characters will be junk, to protect against memory
107     violation.  intBuffer is the internal buffer, but everyone refers
108     to fbuf, which is actually set to the &intBuffer[4].  Also,
109     szfbuf is the size of the "visible" buffer, not the internal
110     buffer.  The reason for the 2 junk characters at the beginning
111     is to align the buffer on a 4-byte boundary.
112 */
113
114 typedef struct
115 {
116 #if (defined(__OS2__) || defined(__32BIT__))
117     unsigned long hfile;  /* OS/2 file handle */
118 #endif
119 #if (defined(__MSDOS__) || defined(__DOS__) || defined(__POWERC))
120     int hfile; /* dos file handle */
121 #endif
122 #if (defined(__MVS__))
123     void *hfile;
124     int recfm;
125     int style;
126     int lrecl;
127     char ddname[9];
128 #endif
129     int quickBin;  /* 1 = do DosRead NOW!!!! */
130     int quickText; /* 1 = quick text mode */
131     int textMode; /* 1 = text mode, 0 = binary mode */
132     int intFno;   /* internal file number */
133     unsigned long bufStartR; /* buffer start represents, e.g. if we
134         have read in 3 buffers, each of 512 bytes, and we are
135         currently reading from the 3rd buffer, then the first
136         character in the buffer would be 1024, so that is what is
137         put in bufStartR. */
138     char *fbuf;     /* file buffer - this is what all the routines
139                        look at. */
140     size_t szfbuf;  /* size of file buffer (the one that the routines
141                        see, and the user allocates, and what is actually
142                        read in from disk) */
143     char *upto;     /* what character is next to read from buffer */
144     char *endbuf;   /* pointer PAST last character in buffer, ie it
145                        points to the '\n' in the internal buffer */
146     int errorInd;   /* whether an error has occurred on this file */
147     int eofInd;     /* whether EOF has been reached on this file */
148     int ungetCh;    /* character pushed back, -1 if none */
149     int bufTech;    /* buffering technique, _IOFBF etc */
150     char *intBuffer; /* internal buffer */
151     int noNl;       /* When doing gets, we don't copy NL */
152     int mode;       /* __WRITE_MODE or __READ_MODE */
153     int update;     /* Is file update (read + write)? */
154     int theirBuffer; /* Is the buffer supplied by them? */
155 } FILE;
156
157 typedef unsigned long fpos_t;
158
159 #define NULL ((void *)0)
160 #define FILENAME_MAX 260
161 #define FOPEN_MAX 40
162 #define _IOFBF 1
163 #define _IOLBF 2
164 #define _IONBF 3
165 /*#define BUFSIZ 409600*/
166 /* #define BUFSIZ 8192 */
167 /*#define BUFSIZ 5120*/
168 #define BUFSIZ 6144
169 /* #define BUFSIZ 10 */
170 /* #define BUFSIZ 512 */
171 #define EOF -1
172 #define L_tmpnam FILENAME_MAX
173 #define TMP_MAX 25
174 #define SEEK_SET 0
175 #define SEEK_CUR 1
176 #define SEEK_END 2
177 #define __NFILE (FOPEN_MAX - 3)
178 #define __WRITE_MODE 1
179 #define __READ_MODE 2
180
181 extern FILE *stdin;
182 extern FILE *stdout;
183 extern FILE *stderr;
184
185 extern FILE *__userFiles[__NFILE];
186 */
187
188 #endif // __STDIO_H