/
io.h
509 lines (416 loc) · 12.2 KB
/
io.h
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
/* io.h
* Copyright (C) 2001-2003, The Perl Foundation.
* SVN Info
* $Id$
* Overview:
* Parrot IO subsystem
* Data Structure and Algorithms:
* History:
* Originally written by Melvin Smith
* Refactored by Juergen Boemmels
* 2003-08-18: Internal structures moved to io/io_private.h
* Notes:
* References:
* Perl6 RFCs (14,30,47,60,186,239,321,345,350)
* Some ideas and goals from Perl5.7 and Nick Ing-Simmons' work
* Some ideas from AT&T SFIO
*/
#ifndef PARROT_IO_H_GUARD
#define PARROT_IO_H_GUARD
#include <stdio.h>
/* which OS are we on? (this should be moved into Configure-land) */
#ifdef MINIPARROT
# define PIO_OS_STDIO
#else
# ifdef _WIN32
# define PIO_OS_WIN32
# else
# ifdef PARROT_HAS_HEADER_UNISTD
# define PIO_OS_UNIX
# else
# define PIO_OS_STDIO
# endif
# endif
#endif
#ifdef PIO_OS_WIN32
# include <io.h>
#endif
#ifndef STDIN_FILENO
# define STDIN_FILENO 0
#endif
#ifndef STDOUT_FILENO
# define STDOUT_FILENO 1
#endif
#ifndef STDERR_FILENO
# define STDERR_FILENO 2
#endif
/* &gen_from_def(stdio.pasm) */
#define PIO_STDIN_FILENO 0
#define PIO_STDOUT_FILENO 1
#define PIO_STDERR_FILENO 2
/* &end_gen */
#ifndef O_ACCMODE
# define O_ACCMODE 0003
#endif
#ifdef BLKSIZE
# define PIO_BLKSIZE BLKSIZE
#else
# define PIO_BLKSIZE 8192
#endif
#define PIO_LINEBUFSIZE 256 /* Default linebuffer size */
#define PIO_GRAIN 2048 /* Smallest size for a block buffer */
#define PIO_BUFSIZE (PIO_GRAIN * 2)
#define PIO_NR_OPEN 256 /* Size of an "IO handle table" */
/* &gen_from_enum(iotypes.pasm) */
enum {
PIO_TYPE_FILE,
PIO_TYPE_PIPE,
PIO_TYPE_SOCKET,
PIO_TYPE_MAX
};
/* &end_gen */
/* This is temporary until subs/code refs are done..*/
typedef void *DummyCodeRef;
#ifdef PIO_OS_WIN32
typedef Parrot_WIN32_HANDLE PIOHANDLE;
typedef Parrot_OFF_T PIOOFF_T;
#endif
#ifdef PIO_OS_UNIX
/* Hopefully INTVAL_SIZE is enough for PTR_SIZE so that
* the FILE* of pio_stdio_layers fit into a PIOHANDLE. */
typedef INTVAL PIOHANDLE;
typedef off_t PIOOFF_T;
#endif
#ifdef PIO_OS_STDIO
typedef FILE* PIOHANDLE;
typedef long PIOOFF_T;
#endif
extern PIOOFF_T piooffsetzero;
typedef struct _ParrotIOLayerAPI ParrotIOLayerAPI;
typedef struct _ParrotIOLayer ParrotIOLayer;
typedef struct _ParrotIOFilter ParrotIOFilter;
typedef struct _ParrotIO ParrotIO;
typedef struct _ParrotIOData ParrotIOData;
struct _ParrotIOLayer {
void *self; /* Instance specific data */
const char *name;
INTVAL flags;
const ParrotIOLayerAPI *api;
ParrotIOLayer *up;
ParrotIOLayer *down;
};
#define PIO_DOWNLAYER(x) x->down
#define PIO_UPLAYER(x) x->up
/* Others to come */
#ifdef PIO_OS_UNIX
extern ParrotIOLayer pio_unix_layer;
#endif
#ifdef PIO_OS_WIN32
extern ParrotIOLayer pio_win32_layer;
#endif
#ifdef PIO_OS_STDIO
extern ParrotIOLayer pio_stdio_layer;
#endif
extern ParrotIOLayer pio_buf_layer;
extern ParrotIOLayer pio_mmap_layer;
extern ParrotIOLayer pio_string_layer;
extern INTVAL pio_errno;
/* HEADERIZER BEGIN: src/io/io.c */
PARROT_API
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * new_io_pmc(PARROT_INTERP, NULLOK(ParrotIO *io))
__attribute__nonnull__(1);
PARROT_API
void Parrot_IOData_mark(PARROT_INTERP, NOTNULL(ParrotIOData *piodata))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_API
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
PMC * PIO_accept(PARROT_INTERP, NOTNULL(PMC *pmc))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_API
INTVAL PIO_base_init(SHIM_INTERP, SHIM(ParrotIOLayer *l));
PARROT_API
INTVAL PIO_bind(PARROT_INTERP, NOTNULL(PMC *pmc), NOTNULL(STRING *address))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);
PARROT_API
INTVAL PIO_close(PARROT_INTERP, NULLOK(PMC *pmc))
__attribute__nonnull__(1);
PARROT_API
INTVAL PIO_connect(PARROT_INTERP,
NOTNULL(PMC *pmc),
NOTNULL(STRING *address))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);
PARROT_API
void PIO_destroy(SHIM_INTERP, NOTNULL(PMC *pmc))
__attribute__nonnull__(2);
PARROT_API
PARROT_WARN_UNUSED_RESULT
INTVAL PIO_eof(SHIM_INTERP, NOTNULL(PMC *pmc))
__attribute__nonnull__(2);
PARROT_API
INTVAL PIO_eprintf(NULLOK(PARROT_INTERP), ARGIN(const char *s), ...);
PARROT_API
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * PIO_fdopen(PARROT_INTERP,
NULLOK(ParrotIOLayer *layer),
PIOHANDLE fd,
ARGIN(const char *sflags))
__attribute__nonnull__(1);
PARROT_API
void PIO_finish(PARROT_INTERP)
__attribute__nonnull__(1);
PARROT_API
void PIO_flush(PARROT_INTERP, NOTNULL(PMC *pmc))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_API
INTVAL PIO_fprintf(PARROT_INTERP,
NOTNULL(PMC *pmc),
ARGIN(const char *s),
...)
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_API
PARROT_WARN_UNUSED_RESULT
PIOHANDLE PIO_getfd(SHIM_INTERP, NOTNULL(PMC *pmc))
__attribute__nonnull__(2);
PARROT_API
void PIO_init(PARROT_INTERP)
__attribute__nonnull__(1);
PARROT_API
INTVAL PIO_init_stacks(PARROT_INTERP)
__attribute__nonnull__(1);
PARROT_API
void PIO_internal_shutdown(SHIM_INTERP);
PARROT_API
PARROT_WARN_UNUSED_RESULT
INTVAL PIO_isatty(SHIM_INTERP, NOTNULL(PMC *pmc))
__attribute__nonnull__(2);
PARROT_API
PARROT_WARN_UNUSED_RESULT
INTVAL PIO_listen(PARROT_INTERP, NOTNULL(PMC *pmc), INTVAL backlog)
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_API
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
ParrotIO * PIO_new(PARROT_INTERP,
NULLOK(INTVAL iotype),
INTVAL flags,
INTVAL mode)
__attribute__nonnull__(1);
PARROT_API
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * PIO_open(PARROT_INTERP,
NULLOK(ParrotIOLayer *layer),
ARGIN(const char *spath),
ARGIN(const char *sflags))
__attribute__nonnull__(1);
PARROT_API
PARROT_WARN_UNUSED_RESULT
INTVAL PIO_parse_open_flags(ARGIN_NULLOK(const char *flagstr));
PARROT_API
INTVAL PIO_peek(PARROT_INTERP, NOTNULL(PMC *pmc), NOTNULL(STRING **buffer))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);
PARROT_API
INTVAL PIO_pioctl(PARROT_INTERP, NOTNULL(PMC *pmc), INTVAL cmd, INTVAL arg)
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_API
INTVAL PIO_poll(PARROT_INTERP,
NOTNULL(PMC *pmc),
INTVAL which,
INTVAL sec,
INTVAL usec)
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_API
INTVAL PIO_printf(PARROT_INTERP, ARGIN(const char *s), ...)
__attribute__nonnull__(1);
PARROT_API
INTVAL PIO_putps(PARROT_INTERP, NOTNULL(PMC *pmc), NULLOK(STRING *s))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_API
INTVAL PIO_puts(PARROT_INTERP, NOTNULL(PMC *pmc), ARGIN(const char *s))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_API
PARROT_WARN_UNUSED_RESULT
INTVAL PIO_read(PARROT_INTERP,
NOTNULL(PMC *pmc),
NOTNULL(char *buffer),
size_t len)
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);
PARROT_API
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
STRING * PIO_reads(PARROT_INTERP, NOTNULL(PMC *pmc), size_t len)
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_API
INTVAL PIO_recv(PARROT_INTERP, NOTNULL(PMC *pmc), NOTNULL(STRING **buf))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);
PARROT_API
PARROT_WARN_UNUSED_RESULT
PIOOFF_T PIO_seek(PARROT_INTERP,
NOTNULL(PMC *pmc),
PIOOFF_T offset,
INTVAL w)
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_API
PARROT_WARN_UNUSED_RESULT
INTVAL PIO_send(PARROT_INTERP, NOTNULL(PMC *pmc), NOTNULL(STRING *buf))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);
PARROT_API
INTVAL PIO_setbuf(PARROT_INTERP, NOTNULL(PMC *pmc), size_t bufsize)
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_API
INTVAL PIO_setlinebuf(PARROT_INTERP, NOTNULL(PMC *pmc))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_API
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * PIO_socket(PARROT_INTERP, INTVAL fam, INTVAL type, INTVAL proto)
__attribute__nonnull__(1);
PARROT_API
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * PIO_STDERR(PARROT_INTERP)
__attribute__nonnull__(1);
PARROT_API
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * PIO_STDIN(PARROT_INTERP)
__attribute__nonnull__(1);
PARROT_API
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * PIO_STDOUT(PARROT_INTERP)
__attribute__nonnull__(1);
PARROT_API
PARROT_WARN_UNUSED_RESULT
PIOOFF_T PIO_tell(PARROT_INTERP, NOTNULL(PMC *pmc))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_API
PARROT_WARN_UNUSED_RESULT
INTVAL PIO_write(PARROT_INTERP,
NOTNULL(PMC *pmc),
ARGIN(const void *buffer),
size_t len)
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
STRING * PIO_make_io_string(PARROT_INTERP,
NOTNULL(STRING **buf),
size_t len)
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PIOOFF_T PIO_make_offset(INTVAL offset);
PIOOFF_T PIO_make_offset32(INTVAL hi, INTVAL lo);
PIOOFF_T PIO_make_offset_pmc(PARROT_INTERP, NOTNULL(PMC *pmc))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
/* HEADERIZER END: src/io/io.c */
/* io_layers.c - If you add new layers, register them in init_layers() */
/* HEADERIZER BEGIN: src/io/io_layers.c */
PARROT_API
void PIO_base_delete_layer(NULLOK(ParrotIOLayer *layer));
PARROT_API
PARROT_MALLOC
PARROT_CANNOT_RETURN_NULL
ParrotIOLayer * PIO_base_new_layer(NULLOK(ParrotIOLayer *proto));
PARROT_API
PARROT_IGNORABLE_RESULT
PARROT_CANNOT_RETURN_NULL
ParrotIOLayer * PIO_copy_stack(NULLOK(ParrotIOLayer *stack));
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
PARROT_API
ParrotIOLayer * PIO_get_layer(SHIM_INTERP, ARGIN(const char *name));
PARROT_API
PARROT_IGNORABLE_RESULT
PARROT_CAN_RETURN_NULL
ParrotIOLayer * PIO_pop_layer(PARROT_INTERP, NULLOK(PMC *pmc))
__attribute__nonnull__(1);
PARROT_API
INTVAL PIO_push_layer(PARROT_INTERP,
NULLOK(PMC *pmc),
NULLOK(ParrotIOLayer *layer))
__attribute__nonnull__(1);
PARROT_IGNORABLE_RESULT
PARROT_CANNOT_RETURN_NULL
STRING * PIO_pop_layer_str(PARROT_INTERP, NOTNULL(PMC *pmc))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
void PIO_push_layer_str(PARROT_INTERP,
NOTNULL(PMC *pmc),
NULLOK(STRING *ls))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
/* HEADERIZER END: src/io/io_layers.c */
/* Put platform specific macros here if you must */
#ifdef PIO_OS_WIN32
extern STRING *PIO_sockaddr_in(PARROT_INTERP, unsigned short, STRING *);
extern INTVAL PIO_win32_getblksize(PIOHANDLE fd);
# define PIO_getblksize(x) PIO_win32_getblksize(x)
#endif
#ifdef PIO_OS_UNIX
extern STRING *PIO_sockaddr_in(PARROT_INTERP, unsigned short, STRING *);
extern INTVAL PIO_unix_getblksize(PIOHANDLE fd);
# define PIO_getblksize(x) PIO_unix_getblksize(x)
#endif
#ifdef PIO_OS_STDIO
extern INTVAL PIO_stdio_getblksize(PIOHANDLE fd);
# define PIO_sockaddr_in(i, p, a)
# define PIO_getblksize(x) PIO_stdio_getblksize(x)
#endif
/*
* pioctl definitions -- These are mostly for reference
* or C-API writers.
*/
/* pioctl command constants */
#define PIOCTL_CMDRESERVED 0
#define PIOCTL_CMDSETRECSEP 1
#define PIOCTL_CMDGETRECSEP 2
#define PIOCTL_CMDSETBUFTYPE 3
#define PIOCTL_CMDGETBUFTYPE 4
#define PIOCTL_CMDSETBUFSIZE 5
#define PIOCTL_CMDGETBUFSIZE 6
/*
* pioctl argument constants. These don't have to
* be unique across io commands.
*/
#define PIOCTL_NONBUF 0
#define PIOCTL_LINEBUF 1
#define PIOCTL_BLKBUF 2
#endif /* PARROT_IO_H_GUARD */
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4:
*/