1 | /**********************************************************************
|
---|
2 |
|
---|
3 | rubyio.h -
|
---|
4 |
|
---|
5 | $Author: shyouhei $
|
---|
6 | $Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $
|
---|
7 | created at: Fri Nov 12 16:47:09 JST 1993
|
---|
8 |
|
---|
9 | Copyright (C) 1993-2003 Yukihiro Matsumoto
|
---|
10 |
|
---|
11 | **********************************************************************/
|
---|
12 |
|
---|
13 | #ifndef RUBYIO_H
|
---|
14 | #define RUBYIO_H
|
---|
15 |
|
---|
16 | #include <stdio.h>
|
---|
17 | #include <errno.h>
|
---|
18 |
|
---|
19 | #if defined(HAVE_STDIO_EXT_H)
|
---|
20 | #include <stdio_ext.h>
|
---|
21 | #endif
|
---|
22 |
|
---|
23 | typedef struct OpenFile {
|
---|
24 | FILE *f; /* stdio ptr for read/write */
|
---|
25 | FILE *f2; /* additional ptr for rw pipes */
|
---|
26 | int mode; /* mode flags */
|
---|
27 | int pid; /* child's pid (for pipes) */
|
---|
28 | int lineno; /* number of lines read */
|
---|
29 | char *path; /* pathname for file */
|
---|
30 | void (*finalize) _((struct OpenFile*,int)); /* finalize proc */
|
---|
31 | } OpenFile;
|
---|
32 |
|
---|
33 | #define FMODE_READABLE 1
|
---|
34 | #define FMODE_WRITABLE 2
|
---|
35 | #define FMODE_READWRITE 3
|
---|
36 | #define FMODE_APPEND 64
|
---|
37 | #define FMODE_CREATE 128
|
---|
38 | #define FMODE_BINMODE 4
|
---|
39 | #define FMODE_SYNC 8
|
---|
40 | #define FMODE_WBUF 16
|
---|
41 | #define FMODE_RBUF 32
|
---|
42 | #define FMODE_WSPLIT 0x200
|
---|
43 | #define FMODE_WSPLIT_INITIALIZED 0x400
|
---|
44 |
|
---|
45 | #define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
|
---|
46 |
|
---|
47 | #define MakeOpenFile(obj, fp) do {\
|
---|
48 | if (RFILE(obj)->fptr) {\
|
---|
49 | rb_io_close(obj);\
|
---|
50 | free(RFILE(obj)->fptr);\
|
---|
51 | RFILE(obj)->fptr = 0;\
|
---|
52 | }\
|
---|
53 | fp = 0;\
|
---|
54 | fp = RFILE(obj)->fptr = ALLOC(OpenFile);\
|
---|
55 | fp->f = fp->f2 = NULL;\
|
---|
56 | fp->mode = 0;\
|
---|
57 | fp->pid = 0;\
|
---|
58 | fp->lineno = 0;\
|
---|
59 | fp->path = NULL;\
|
---|
60 | fp->finalize = 0;\
|
---|
61 | } while (0)
|
---|
62 |
|
---|
63 | #define GetReadFile(fptr) ((fptr)->f)
|
---|
64 | #define GetWriteFile(fptr) (((fptr)->f2) ? (fptr)->f2 : (fptr)->f)
|
---|
65 |
|
---|
66 | FILE *rb_fopen _((const char*, const char*));
|
---|
67 | FILE *rb_fdopen _((int, const char*));
|
---|
68 | int rb_getc _((FILE*));
|
---|
69 | long rb_io_fread _((char *, long, FILE *));
|
---|
70 | long rb_io_fwrite _((const char *, long, FILE *));
|
---|
71 | int rb_io_mode_flags _((const char*));
|
---|
72 | int rb_io_modenum_flags _((int));
|
---|
73 | void rb_io_check_writable _((OpenFile*));
|
---|
74 | void rb_io_check_readable _((OpenFile*));
|
---|
75 | void rb_io_fptr_finalize _((OpenFile*));
|
---|
76 | void rb_io_synchronized _((OpenFile*));
|
---|
77 | void rb_io_check_initialized _((OpenFile*));
|
---|
78 | void rb_io_check_closed _((OpenFile*));
|
---|
79 | int rb_io_wait_readable _((int));
|
---|
80 | int rb_io_wait_writable _((int));
|
---|
81 | void rb_io_set_nonblock(OpenFile *fptr);
|
---|
82 |
|
---|
83 | VALUE rb_io_taint_check _((VALUE));
|
---|
84 | NORETURN(void rb_eof_error _((void)));
|
---|
85 |
|
---|
86 | void rb_read_check _((FILE*));
|
---|
87 | int rb_read_pending _((FILE*));
|
---|
88 | #endif
|
---|