Upgrade to 1.46.0
[platform/upstream/nghttp2.git] / third-party / mruby / mrbgems / mruby-io / include / mruby / ext / io.h
1 /*
2 ** io.h - IO class
3 */
4
5 #ifndef MRUBY_IO_H
6 #define MRUBY_IO_H
7
8 #include <mruby.h>
9
10 #ifdef MRB_DISABLE_STDIO
11 # error IO and File conflicts 'MRB_DISABLE_STDIO' configuration in your 'build_config.rb'
12 #endif
13
14 #if defined(__cplusplus)
15 extern "C" {
16 #endif
17
18 #if defined(MRB_WITHOUT_IO_PREAD_PWRITE)
19 # undef MRB_WITH_IO_PREAD_PWRITE
20 #elif !defined(MRB_WITH_IO_PREAD_PWRITE)
21 # if defined(__unix__) || defined(__MACH__)
22 #  define MRB_WITH_IO_PREAD_PWRITE
23 # endif
24 #endif
25
26 struct mrb_io {
27   int fd;   /* file descriptor, or -1 */
28   int fd2;  /* file descriptor to write if it's different from fd, or -1 */
29   int pid;  /* child's pid (for pipes)  */
30   unsigned int readable:1,
31                writable:1,
32                sync:1,
33                is_socket:1;
34 };
35
36 #define MRB_O_RDONLY            0x0000
37 #define MRB_O_WRONLY            0x0001
38 #define MRB_O_RDWR              0x0002
39 #define MRB_O_ACCMODE           (MRB_O_RDONLY | MRB_O_WRONLY | MRB_O_RDWR)
40 #define MRB_O_NONBLOCK          0x0004
41 #define MRB_O_APPEND            0x0008
42 #define MRB_O_SYNC              0x0010
43 #define MRB_O_NOFOLLOW          0x0020
44 #define MRB_O_CREAT             0x0040
45 #define MRB_O_TRUNC             0x0080
46 #define MRB_O_EXCL              0x0100
47 #define MRB_O_NOCTTY            0x0200
48 #define MRB_O_DIRECT            0x0400
49 #define MRB_O_BINARY            0x0800
50 #define MRB_O_SHARE_DELETE      0x1000
51 #define MRB_O_TMPFILE           0x2000
52 #define MRB_O_NOATIME           0x4000
53 #define MRB_O_DSYNC             0x00008000
54 #define MRB_O_RSYNC             0x00010000
55
56 #define MRB_O_RDONLY_P(f)       ((mrb_bool)(((f) & MRB_O_ACCMODE) == MRB_O_RDONLY))
57 #define MRB_O_WRONLY_P(f)       ((mrb_bool)(((f) & MRB_O_ACCMODE) == MRB_O_WRONLY))
58 #define MRB_O_RDWR_P(f)         ((mrb_bool)(((f) & MRB_O_ACCMODE) == MRB_O_RDWR))
59 #define MRB_O_READABLE_P(f)     ((mrb_bool)((((f) & MRB_O_ACCMODE) | 2) == 2))
60 #define MRB_O_WRITABLE_P(f)     ((mrb_bool)(((((f) & MRB_O_ACCMODE) + 1) & 2) == 2))
61
62 #define E_IO_ERROR                 (mrb_class_get(mrb, "IOError"))
63 #define E_EOF_ERROR                (mrb_class_get(mrb, "EOFError"))
64
65 int mrb_io_fileno(mrb_state *mrb, mrb_value io);
66
67 #if defined(__cplusplus)
68 } /* extern "C" { */
69 #endif
70 #endif /* MRUBY_IO_H */