summaryrefslogtreecommitdiff
path: root/src/libio/mpu-libio.h
blob: 74fb8cdbcf9750d124c3c1efd0bdc1365c0fef15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/***************************************************************
  MPU-LIBIO.H

       This file contains internal declarations for
       LIBMPUIO stream operations.

       PART OF : MPUIO - library .

       USAGE   : Internal only .

       NOTE    : NONE .

       Copyright (C) 2000 - 2026  by Andrey V.Kosteltsev.
       All Rights Reserved.
 ***************************************************************/

#ifndef __MPU_LIBIO_H
#define __MPU_LIBIO_H 1

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <libmpuio.h>
#include <mpu-symbols.h>

#define __MPU_IO_MAGIC       0x4d505549U

#define __MPU_IO_NO_READS    0x00000001U
#define __MPU_IO_NO_WRITES   0x00000002U
#define __MPU_IO_EOF_SEEN    0x00000004U
#define __MPU_IO_ERR_SEEN    0x00000008U
#define __MPU_IO_USER_BUF    0x00000010U
#define __MPU_IO_LINE_BUF    0x00000020U
#define __MPU_IO_UNBUFFERED  0x00000040U
#define __MPU_IO_READING     0x00000080U
#define __MPU_IO_WRITING     0x00000100U
#define __MPU_IO_APPEND      0x00000200U
#define __MPU_IO_STATIC      0x00000400U
#define __MPU_IO_STRING      0x00000800U
#define __MPU_IO_COUNTED     0x00001000U
#define __MPU_IO_MEMSTREAM   0x00002000U
#define __MPU_IO_PIPE        0x00004000U
#define __MPU_IO_COOKIE      0x00008000U
#define __MPU_IO_NOLIST      0x00010000U

struct __mpu_IO_jump_t;

struct __mpu_IO_FILE
{
  __mpu_uint32_t   _magic;
  unsigned int     _flags;

  int              _fileno;

  unsigned char   *_read_base;
  unsigned char   *_read_ptr;
  unsigned char   *_read_end;

  unsigned char   *_write_base;
  unsigned char   *_write_ptr;
  unsigned char   *_write_end;

  unsigned char   *_buf_base;
  unsigned char   *_buf_end;


  pthread_mutex_t  _lock;

  struct __mpu_IO_FILE  *_next;

  unsigned int           _pins;
  unsigned int           _closing;

  void                  *_cookie;

  unsigned int           _unget_count;
  __mpu_char16_t         _unget_chars[8];
};

struct __mpu_IO_FILE_plus
{
   struct __mpu_IO_FILE          file;
   const struct __mpu_IO_jump_t *vtable;
};

#define __MPU_IO_PLUS(STREAM) \
   ((struct __mpu_IO_FILE_plus *)(void *)(STREAM))
#define __MPU_IO_JUMPS(STREAM) \
   (__MPU_IO_PLUS( STREAM )->vtable)

struct __mpu_IO_jump_t
{
  int    (*finish)( mpu_FILE *stream );
  int    (*underflow)( mpu_FILE *stream );
  int    (*overflow)( mpu_FILE *stream, int c );
  int    (*sync)( mpu_FILE *stream );
  int    (*setbuf)( mpu_FILE *stream, unsigned char *buf,
                    int mode, size_t size );
  off_t  (*seekoff)( mpu_FILE *stream, off_t offset, int whence );
  off_t  (*seekpos)( mpu_FILE *stream, off_t position );
  int    (*flush)( mpu_FILE *stream );
  int    (*close)( mpu_FILE *stream );
  int    (*seek)( mpu_FILE *stream, off_t offset, int whence );
  off_t  (*tell)( mpu_FILE *stream );

  int    (*get_byte)( mpu_FILE *stream );
  int    (*put_byte)( unsigned char c, mpu_FILE *stream );
  size_t (*xsgetn)( mpu_FILE *stream, void *data, size_t size );
  size_t (*xsputn)( mpu_FILE *stream, const void *data, size_t size );

  int    (*get_char)( mpu_FILE *stream, __mpu_char16_t *wc );
  int    (*put_char)( __mpu_char16_t wc, mpu_FILE *stream );
};

typedef struct __mpu_IO_cookie_file
{
  void                      *user_cookie;
  mpu_cookie_io_functions_t  io;
} __mpu_IO_cookie_file;

typedef struct __mpu_IO_strfile
{
  __mpu_char16_t   *buffer;
  size_t            capacity;
  size_t            length;
  size_t            pos;
  int               nul_terminated;
  int               dynamic;
  __mpu_char16_t  **publish_buffer;
  size_t           *publish_size;
} __mpu_IO_strfile;


extern pthread_mutex_t  __mpu_IO_list_lock;
extern mpu_FILE        *__mpu_IO_list_all;

extern const struct __mpu_IO_jump_t  __mpu_IO_file_jumps;
extern const struct __mpu_IO_jump_t  __mpu_IO_str_jumps;
extern const struct __mpu_IO_jump_t  __mpu_IO_cookie_jumps;

extern int       __mpu_IO_lock_init( pthread_mutex_t *lock );
extern int       __mpu_IO_parse_mode( const char *mode, unsigned int *flags,
                                      int *oflags, int for_open );
extern int       __mpu_IO_valid( mpu_FILE *stream );
extern void      __mpu_IO_link_in( mpu_FILE *stream );
extern void      __mpu_IO_unlink_locked( mpu_FILE *stream );
extern void      __mpu_IO_unlink( mpu_FILE *stream );
extern mpu_FILE *__mpu_IO_file_open( int fd, unsigned int flags );

extern int       __mpu_IO_doallocbuf( mpu_FILE *stream );

extern int       __mpu_IO_file_finish_unlocked( mpu_FILE *stream );
extern int       __mpu_IO_file_underflow_unlocked( mpu_FILE *stream );
extern int       __mpu_IO_file_overflow_unlocked( mpu_FILE *stream, int c );
extern int       __mpu_IO_file_sync_unlocked( mpu_FILE *stream );
extern int       __mpu_IO_file_setbuf_unlocked( mpu_FILE *stream,
                                                unsigned char *buf,
                                                int mode, size_t size );
extern off_t     __mpu_IO_file_seekoff_unlocked( mpu_FILE *stream,
                                                 off_t offset, int whence );
extern off_t     __mpu_IO_file_seekpos_unlocked( mpu_FILE *stream,
                                                 off_t position );
extern int       __mpu_IO_file_flush_unlocked( mpu_FILE *stream );
extern int       __mpu_IO_file_sync_input_unlocked( mpu_FILE *stream );
extern int       __mpu_IO_file_get_byte_unlocked( mpu_FILE *stream );
extern int       __mpu_IO_file_put_byte_unlocked( unsigned char c,
                                                  mpu_FILE *stream );
extern size_t    __mpu_IO_file_xsgetn_unlocked( mpu_FILE *stream,
                                                void *data, size_t size );
extern size_t    __mpu_IO_file_xsputn_unlocked( mpu_FILE *stream,
                                                const void *data, size_t size );
extern int       __mpu_IO_file_seek_unlocked( mpu_FILE *stream,
                                              off_t offset, int whence );
extern off_t     __mpu_IO_file_tell_unlocked( mpu_FILE *stream );
extern int       __mpu_IO_file_close_unlocked( mpu_FILE *stream );

extern int       __mpu_IO_finish_unlocked( mpu_FILE *stream );
extern int       __mpu_IO_underflow_unlocked( mpu_FILE *stream );
extern int       __mpu_IO_overflow_unlocked( mpu_FILE *stream, int c );
extern int       __mpu_IO_sync_unlocked( mpu_FILE *stream );
extern int       __mpu_IO_setbuf_unlocked( mpu_FILE *stream,
                                           unsigned char *buf,
                                           int mode, size_t size );
extern off_t     __mpu_IO_seekoff_unlocked( mpu_FILE *stream,
                                            off_t offset, int whence );
extern off_t     __mpu_IO_seekpos_unlocked( mpu_FILE *stream,
                                            off_t position );
extern int       __mpu_IO_flush_unlocked( mpu_FILE *stream );
extern int       __mpu_IO_get_byte_unlocked( mpu_FILE *stream );
extern int       __mpu_IO_put_byte_unlocked( unsigned char c,
                                             mpu_FILE *stream );
extern size_t    __mpu_IO_xsgetn_unlocked( mpu_FILE *stream,
                                           void *data, size_t size );
extern size_t    __mpu_IO_xsputn_unlocked( mpu_FILE *stream,
                                           const void *data, size_t size );
extern int       __mpu_IO_get_char_unlocked( mpu_FILE *stream,
                                             __mpu_char16_t *wc );
extern int       __mpu_IO_put_char_unlocked( __mpu_char16_t wc,
                                             mpu_FILE *stream );
extern int       __mpu_IO_unget_char_unlocked( __mpu_char16_t wc,
                                               mpu_FILE *stream );

extern int       __mpu_UTF8_decode_unlocked( mpu_FILE *stream,
                                             __mpu_char16_t *wc );
extern int       __mpu_UTF8_encode_unlocked( __mpu_char16_t wc,
                                             mpu_FILE *stream );

extern mpu_FILE *__mpu_IO_str_open( __mpu_char16_t *buffer,
                                    size_t capacity,
                                    size_t length,
                                    unsigned int flags );
extern mpu_FILE *__mpu_IO_str_open_readonly( const __mpu_char16_t *buffer,
                                             size_t length );
extern mpu_FILE *__mpu_IO_str_open_counted( __mpu_char16_t *buffer,
                                            size_t capacity );
extern mpu_FILE *__mpu_IO_str_open_memstream( __mpu_char16_t **buffer,
                                              size_t *size,
                                              unsigned int flags );

extern int       __mpu_IO_vfprintf( mpu_FILE *stream,
                                    const __mpu_char16_t *format,
                                    va_list args );
extern int       __mpu_IO_vfprintf_unlocked( mpu_FILE *stream,
                                             const __mpu_char16_t *format,
                                             va_list args );
extern int       __mpu_IO_vfscanf( mpu_FILE *stream,
                                   const __mpu_char16_t *format,
                                   va_list args );
extern int       __mpu_IO_vfscanf_unlocked( mpu_FILE *stream,
                                            const __mpu_char16_t *format,
                                            va_list args );

#endif /* __MPU_LIBIO_H */