]> pd.if.org Git - pdclib/blob - includes/stdio.h
Porting current working set from CVS.
[pdclib] / includes / stdio.h
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* Input/output <stdio.h>
6
7    This file is part of the Public Domain C Library (PDCLib).
8    Permission is granted to use, modify, and / or redistribute at will.
9 */
10
11 #ifndef _PDCLIB_STDIO_H
12 #define _PDCLIB_STDIO_H _PDCLIB_STDIO_H
13
14 #ifndef _PDCLIB_INT_H
15 #define _PDCLIB_INT_H _PDCLIB_INT_H
16 #include <_PDCLIB_int.h>
17 #endif
18
19 #ifndef _PDCLIB_SIZE_T_DEFINED
20 #define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED
21 typedef _PDCLIB_size_t size_t;
22 #endif
23
24 #ifndef _PDCLIB_NULL_DEFINED
25 #define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED
26 #define NULL _PDCLIB_NULL
27 #endif
28
29 /* See setvbuf(), third argument */
30 /* Fully buffered - transmit block-wise */
31 #define _IOFBF 1
32 /* Line buffered - transmit line-wise */
33 #define _IOLBF 2
34 /* Not buffered - transmit immediately */
35 #define _IONBF 4
36
37 /* See setbuf(). Minimum 256. */
38 #define BUFSIZ 1024
39
40 /* Internal-only flags for representing mode */
41 #define _PDCLIB_FREAD    1
42 #define _PDCLIB_FWRITE   2
43 #define _PDCLIB_FAPPEND  4
44 #define _PDCLIB_FRW      8
45 #define _PDCLIB_FBIN    16
46
47 typedef struct _PDCLIB_file_t FILE;
48 typedef _PDCLIB_fpos_t        fpos_t;
49
50 /* Must be integer and of negative value */
51 #define EOF -1
52
53 /* Maximum number of files this implementation can open simultaneously. Minimum 8. */
54 #define FOPEN_MAX 1
55
56 /* Maximum file name length (plus terminating \0) this implementation does
57    guarantee can be opened. If there is no limit on the length of filenames,
58    this should be a recommended size for filename buffers.
59 */
60 #define FILENAME_MAX 1024
61
62 /* Buffer size for tmpnam() */
63 #define L_tmpnam 1024
64
65 /* Number of distinct file names that can be generated by tmpnam(). */
66 #define TMP_MAX 50
67
68 /* See fseek(), third argument */
69 #define SEEK_CUR 1
70 #define SEEK_END 2
71 #define SEEK_SET 4
72
73 typedef struct
74 {
75     _PDCLIB_fd_t   handle;   /* OS-specific file descriptor */
76     _PDCLIB_fpos_t position; /* file position indicator */
77     void *         buffer;   /* file buffer */
78     size_t         bufsize;  /* size of buffer */
79     int            status;   /* misc. status bits */
80   /*mbstate_t      mbstate;*//* multibyte parse state */ /* TODO: Unmask. */
81     FILE *         next;     /* provisions for linked list handling */
82 } FILE;
83
84 /* Text-mode I/O is at liberty to skip non-printing characters and trailing spaces.
85    Binary I/O is at liberty to add trailing zero bytes.
86    First operation decides "orientation" of the stream (wide / byte).
87    freopen() removes orientation; see also fwide().
88    Binary wide-oriented streams have the file-positioning restrictions ascribed to both text and binary streams.
89    For wide-oriented streams, after a successful call to a file-positioning function that leaves the file position indicator prior to the end-of-file, a wide character output function can overwrite a partial multibyte character; any file contents beyond the byte(s) written are henceforth indeterminate.
90    Whether a file of zero length (unwritten-to) actually exists is implementation-defined.
91    Wide text input from file: fgetwc() / mbrtowc()
92    Wide text output to file: wcrtomb() / fputwc()
93    Multibyte encoding in file may contain embedded null bytes
94    Multibyte encoding in file need not begin / end in initial shift state.
95    Conversion may trigger EILSEQ.
96 */
97
98 /* Operations on files */
99 int remove( const char * filename );
100 int rename( const char * old, const char * new );
101 FILE * tmpfile( void ); /* TODO: Implement. */
102 char * tmpnam( char * s ); /* TODO: Implement. */
103
104 /* File access functions */
105 int fclose( FILE * stream );
106 int fflush( FILE * stream );
107 FILE * fopen( const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode );
108 FILE * freopen( const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode, FILE * _PDCLIB_restrict stream );
109 void setbuf( FILE * _PDCLIB_restrict stream, char * _PDCLIB_restrict buf );
110 int setvbuf( FILE * _PDCLIB_restrict stream, char * _PDCLIB_restrict buf, int mode, size_t size );
111
112 /* Formatted input/output functions */
113 int fprintf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... );
114 int fscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... );
115 int printf( const char * _PDCLIB_restrict format, ... );
116 int scanf( const char * _PDCLIB_restrict format, ... );
117 int snprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restrict format, ... );
118 int sprintf( char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, ... );
119 int sscanf( const char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, ... );
120 int vfprintf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg );
121 int vfscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg );
122 int vprintf( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg );
123 int vscanf( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg );
124 int vsnprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg );
125 int vsprintf( char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg );
126 int vsscanf( const char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg );
127
128 /* Character input/output functions */
129 int fgetc( FILE * stream );
130 char * fgets( char * _PDCLIB_restrict s, int n, FILE * _PDCLIB_restrict stream );
131 int fputc( int c, FILE * stream );
132 int fputs( const char * _PDCLIB_restrict s, FILE * _PDCLIB_restrict stream );
133 int getc( FILE * stream );
134 int getchar( void );
135 char * gets( char * s );
136 int putc( int c, FILE * stream );
137 int putchar( int c );
138 int puts( const char * s );
139 int ungetc( int c, FILE * stream );
140
141 /* Direct input/output functions */
142 size_t fread( void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, FILE * _PDCLIB_restrict stream );
143 size_t fwrite( const void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, FILE * _PDCLIB_restrict stream );
144
145 /* File positioning functions */
146 int fgetpos( FILE * _PDCLIB_restrict stream, fpos_t * _PDCLIB_restrict pos );
147 int fseek( FILE * stream, long int offset, int whence );
148 int fsetpos( FILE * stream, const fpos_t * pos );
149 long int ftell( FILE * stream );
150 void rewind( FILE * stream );
151
152 /* Error-handling functions */
153 void clearerr( FILE * stream );
154 int feof( FILE * stream );
155 int ferror( FILE * stream );
156 void perror( const char * s );
157
158 #endif