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: impl.h,v 1.2 2003/03/09 19:29:21 steveg Exp $
11 #ifndef SIO_BUFFER_SIZE
17 #include <sys/types.h>
21 * A struct map_unit describes a memory mapped area of a file.
23 * addr is the address where the file is mapped. If addr is NULL
24 * the other fields are meaningless.
25 * valid_bytes indicates how many bytes are _valid_ in that unit
26 * mapped_bytes of a unit is how many bytes are mapped in that
27 * unit ( valid <= mapped ).
28 * Normally mapped_bytes will be equal to valid_bytes until
29 * we reach the end of the file. Then if the file size is not a multiple
30 * of the unit size, only the rest of the file will be mapped at the
31 * unit, leaving part of what was mapped at the unit before still
32 * visible (this happens because I chose not to unmap a unit before
33 * remapping it). In that case valid_bytes shows the size of the "new"
34 * mapping and mapped_bytes shows how many bytes are really mapped.
35 * mapped_bytes is used in Sdone() to unmap the units.
46 * Meaning of fields used when memory mapping:
48 * file_offset: it is the offset in the file where the next
49 * mapping should be done
51 * file_size: size of the file (obtained from stat(2))
53 struct mmap_descriptor
57 struct map_unit first_unit ;
58 struct map_unit second_unit ;
61 typedef struct mmap_descriptor mapd_s ;
63 #endif /* HAVE_MMAP */
65 typedef enum { FAILURE, SUCCESS } sio_status_e ;
68 * Descriptor management: convert a descriptor pointer to an input or
69 * output descriptor pointer
71 #define IDP( dp ) (&(dp)->descriptor.input_descriptor)
72 #define ODP( dp ) (&(dp)->descriptor.output_descriptor)
74 #define DESCRIPTOR_INITIALIZED( dp ) ((dp)->initialized)
79 #define SIO_BUFFER_SIZE 8192
80 #define SIO_NO_TIED_FD (-1)
82 typedef enum { NO = 0, YES = 1 } boolean_e ;
96 #define MIN( a, b ) ( (a) < (b) ? (a) : (b) )
102 static char *itoa( num )
105 #define NUMBUF_SIZE 15
106 static char numbuf[ NUMBUF_SIZE ] ;
107 char *p = &numbuf[ NUMBUF_SIZE ] ;
112 *--p = num % 10 + '0' ;
119 # define ASSERT( expr ) \
122 char *s1 = "SIO assertion << expr >> failed: File: " ; \
123 char *s2 = __FILE__ ; \
124 char *s3 = ", line: " ; \
125 char *s4 = itoa( __LINE__ ) ; \
127 (void) write( 2, s1, strlen( s1 ) ) ; \
128 (void) write( 2, s2, strlen( s2 ) ) ; \
129 (void) write( 2, s3, strlen( s3 ) ) ; \
130 (void) write( 2, s4, strlen( s4 ) ) ; \
131 (void) write( 2, s5, strlen( s5 ) ) ; \
135 # define ASSERT( expr )
142 * Internal functions that are visible
144 int __sio_writef( __sio_od_t *odp, int fd ) ;
145 int __sio_extend_buffer( __sio_id_t *idp, int fd, int b_left ) ;
146 int __sio_init( __sio_descriptor_t *dp, int fd, enum __sio_stream stream_type );
147 int __sio_more( __sio_id_t *idp, int fd ) ;
148 sio_status_e __sio_switch( __sio_id_t *idp, int fd ) ;
153 #define sio_memcopy( from, to, nbytes ) (void) memcpy( to, from, nbytes )
154 #define sio_memscan( from, nbytes, ch ) memchr( from, ch, nbytes )
156 #define sio_memcopy( from, to, nbytes ) (void) bcopy( from, to, nbytes )
160 #define sio_memcopy __sio_memcopy
162 void __sio_memcopy() ;
166 char *sio_memscan() ;
169 #endif /* SIO_BUFFER_SIZE */