2 * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
3 * All rights reserved. The file named COPYRIGHT specifies the terms
4 * and conditions for redistribution.
8 * $Id: sio.h,v 1.6 2003/06/10 13:15:44 steveg Exp $
19 * 1) SIO functions and macros have names starting with a capital S
20 * 2) SIO constants meant to be used by user programs have
21 * names starting with SIO_
22 * 3) Internal functions, struct identifiers, enum identifiers
23 * etc. have names starting with __sio
24 * 4) Internal constants and macros have names starting with __SIO
31 * SIO_FLUSH_ALL: flush all output streams
32 * SIO_ERR: operation failed
33 * SIO_EOF: eof on stream
34 * #define SIO_EOF (-2)
36 #define SIO_FLUSH_ALL (-1)
47 * Descriptor for an input stream
49 struct __sio_input_descriptor
52 * buf: points to the buffer area.
53 * When doing memory mapping, it is equal to the unit
54 * from which we are reading. When doing buffered I/O
55 * it points to the primary buffer. The auxiliary
56 * buffer is right below buf and is of the same size.
59 unsigned buffer_size ;
61 char *start ; /* start of valid buffer contents */
62 char *end ; /* end of valid buffer contents + 1 */
63 char *nextb ; /* pointer to next byte to read/write */
64 /* Always: start <= nextb < end */
66 unsigned line_length ;
70 int memory_mapped ; /* flag to denote if we use */
74 typedef struct __sio_input_descriptor __sio_id_t ;
78 * Descriptor for an output stream
80 struct __sio_output_descriptor
83 * buf: points to the buffer area.
84 * buf_end: is equal to buf + buffer_size
89 unsigned buffer_size ;
91 char *start ; /* start of valid buffer contents */
92 /* (used by the R and W functions) */
93 char *nextb ; /* pointer to next byte to read/write */
94 /* Always: start <= nextb < buf_end */
95 int buftype ; /* type of buffering */
98 typedef struct __sio_output_descriptor __sio_od_t ;
105 enum __sio_stream { __SIO_INPUT_STREAM, __SIO_OUTPUT_STREAM } ;
111 struct __sio_descriptor
115 __sio_id_t input_descriptor ;
116 __sio_od_t output_descriptor ;
118 enum __sio_stream stream_type ;
122 typedef struct __sio_descriptor __sio_descriptor_t ;
126 * The array of descriptors (as many as available file descriptors)
128 extern int __sio_n_descriptors ;
129 extern __sio_descriptor_t *__sio_descriptors ;
133 * Internally used macros
135 #define __SIO_FD_INITIALIZED( fd ) \
136 (fd >= 0 && fd < __sio_n_descriptors && __sio_descriptors[ fd ].initialized)
137 #define __SIO_ID( fd ) (__sio_descriptors[ fd ].descriptor.input_descriptor)
138 #define __SIO_OD( fd ) (__sio_descriptors[ fd ].descriptor.output_descriptor)
139 #define __SIO_MUST_FLUSH( od, ch ) \
140 ( (od).buftype != SIO_FULLBUF && \
141 ( (od).buftype == SIO_NOBUF || ch == '\n' ) )
149 * NOTE: The maximum line size depends on whether the descriptor
150 * was originally memory mapped. If it was, then the maximum
151 * line size will be the map_unit_size (a function of the system
152 * page size and PAGES_MAPPED). Otherwise, it will be either the
153 * optimal block size as reported by stat(2) or SIO_BUFFER_SIZE.
156 #define SIOLINELEN( fd ) __SIO_ID( fd ).line_length
161 char *Srdline ( int fd ) ;
164 * The Write functions
166 int Swrite ( int fd, const char *buf, unsigned int nbytes );
167 int Sprint ( int fd, const char *format, ... )
169 __attribute__ ((format (printf, 2, 3)));
173 int Sputchar( int fd, char c );
174 int Sprintv ( int fd, const char *format, va_list ap )
176 __attribute__ ((format (printf, 2, 0)));
184 int Sdone ( int fd ) ;
185 int Sflush ( int fd ) ;
186 int Sclose ( int fd ) ;
187 int Sbuftype ( int fd, int type ) ;
188 int Smorefds ( int ) ;
189 int __sio_converter( __sio_od_t *, int , const char *, va_list );
190 int sio_setup(int fd, __sio_descriptor_t **dp, unsigned int type );
193 __attribute__ ((noreturn))
195 void terminate(const char *);