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