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