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