17 #if defined(HAVE_FCNTL_H) || defined(_WIN32)
19 #elif defined(HAVE_SYS_FCNTL_H)
20 #include <sys/fcntl.h>
33 #define IS_STRIO(obj) (rb_typeddata_is_kind_of((obj), &strio_data_type))
34 #define error_inval(msg) (errno = EINVAL, rb_sys_fail(msg))
61 if (--ptr->
count <= 0) {
83 #define check_strio(self) ((struct StringIO*)rb_check_typeddata((self), &strio_data_type))
103 if (len > rlen) len = rlen;
104 if (len < 0) len = 0;
108 #define StringIO(obj) get_strio(obj)
110 #define CLOSED(ptr) (!((ptr)->flags & FMODE_READWRITE))
111 #define READABLE(ptr) ((ptr)->flags & FMODE_READABLE)
112 #define WRITABLE(ptr) ((ptr)->flags & FMODE_WRITABLE)
173 switch (
rb_scan_args(argc, argv,
"02", &
string, &mode)) {
178 trunc = flags & O_TRUNC;
443 if (copy == orig)
return copy;
485 #define strio_binmode strio_self
488 #define strio_fcntl strio_unimpl
491 #define strio_flush strio_self
494 #define strio_fsync strio_0
614 #define strio_set_sync strio_first
616 #define strio_tell strio_get_pos
690 if (pos + len > olen) {
746 if (p+clen >= pend)
break;
769 long pos = ptr->
pos, cl = 1;
780 if (cl == 0)
return Qnil;
788 memmove(s + cl, s + pos, rest);
892 for (c = 0; c < (1 <<
CHAR_BIT); c++) {
896 skip[(
unsigned char)*pat++] = m;
901 bm_search(
const char *little,
long llen,
const char *big,
long blen,
const long *skip)
909 while (j >= 0 && big[k] == little[j]) {
913 if (j < 0)
return k + 1;
914 i += skip[(
unsigned char)big[i]];
922 const char *s, *e, *
p;
958 if (limit > 0 && s + limit < e) {
972 while ((p = memchr(p,
'\n', e - p)) && (p != e)) {
981 if ((p = memchr(s,
RSTRING_PTR(str)[0], e - s)) != 0) {
989 for (p = s; p + n <= e; ++
p) {
1000 if ((pos =
bm_search(p, n, s, e - s, skip)) >= 0) {
1134 if (len == 0)
return INT2FIX(0);
1140 if (ptr->
pos == olen) {
1159 #define strio_addstr rb_io_addstr
1168 #define strio_print rb_io_print
1176 #define strio_printf rb_io_printf
1208 #define strio_puts rb_io_puts
1232 if (!
NIL_P(argv[0])) {
1247 if (len <= ptr->
pos) {
1269 if (len > rest) len = rest;
1298 #define strio_syswrite rb_io_write
1306 #define strio_isatty strio_false
1309 #define strio_pid strio_nil
1312 #define strio_fileno strio_nil
1324 if (
NIL_P(
string)) {
1396 VALUE ext_enc, int_enc, opt;
1398 argc =
rb_scan_args(argc, argv,
"11:", &ext_enc, &int_enc, &opt);
1400 if (
NIL_P(ext_enc)) {