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) {
84 #define check_strio(self) ((struct StringIO*)rb_check_typeddata((self), &strio_data_type))
104 if (len > rlen) len = rlen;
105 if (len < 0) len = 0;
110 #define StringIO(obj) get_strio(obj)
112 #define STRIO_READABLE FL_USER4
113 #define STRIO_WRITABLE FL_USER5
114 #define STRIO_READWRITE (STRIO_READABLE|STRIO_WRITABLE)
116 #define STRIO_MODE_SET_P(strio, mode) \
117 ((RBASIC(strio)->flags & STRIO_##mode) && \
118 ((struct StringIO*)DATA_PTR(strio))->flags & FMODE_##mode)
119 #define CLOSED(strio) (!STRIO_MODE_SET_P(strio, READWRITE))
120 #define READABLE(strio) STRIO_MODE_SET_P(strio, READABLE)
121 #define WRITABLE(strio) STRIO_MODE_SET_P(strio, WRITABLE)
185 switch (
rb_scan_args(argc, argv,
"02", &
string, &mode)) {
190 trunc = flags & O_TRUNC;
457 if (copy == orig)
return copy;
500 #define strio_binmode strio_self
502 #define strio_fcntl strio_unimpl
504 #define strio_flush strio_self
506 #define strio_fsync strio_0
625 #define strio_set_sync strio_first
627 #define strio_tell strio_get_pos
656 rb_warn(
"StringIO#bytes is deprecated; use #each_byte instead");
710 if (pos + len > olen) {
767 if (p+clen >= pend)
break;
790 long pos = ptr->
pos, cl = 1;
801 if (cl == 0)
return Qnil;
810 memmove(s + cl, s + pos, rest);
876 rb_warn(
"StringIO#chars is deprecated; use #each_char instead");
920 rb_warn(
"StringIO#codepoints is deprecated; use #each_codepoint instead");
932 for (c = 0; c < (1 <<
CHAR_BIT); c++) {
936 skip[(
unsigned char)*pat++] = m;
941 bm_search(
const char *little,
long llen,
const char *big,
long blen,
const long *skip)
949 while (j >= 0 && big[k] == little[j]) {
953 if (j < 0)
return k + 1;
954 i += skip[(
unsigned char)big[i]];
962 const char *s, *e, *p;
998 if (limit > 0 && s + limit < e) {
1004 else if ((n = RSTRING_LEN(str)) == 0) {
1006 while (*p ==
'\n') {
1012 while ((p = memchr(p,
'\n', e - p)) && (p != e)) {
1021 if ((p = memchr(s,
RSTRING_PTR(str)[0], e - s)) != 0) {
1029 for (p = s; p + n <= e; ++p) {
1040 if ((pos =
bm_search(p, n, s, e - s, skip)) >= 0) {
1124 rb_warn(
"StringIO#lines is deprecated; use #each_line instead");
1181 if (len == 0)
return INT2FIX(0);
1187 if (ptr->
pos == olen) {
1213 #define strio_addstr rb_io_addstr
1222 #define strio_print rb_io_print
1230 #define strio_printf rb_io_printf
1262 #define strio_puts rb_io_puts
1286 if (!
NIL_P(argv[0])) {
1301 if (len <= ptr->
pos) {
1323 if (len > rest) len = rest;
1364 int no_exception = 0;
1386 #define strio_syswrite rb_io_write
1397 #define strio_isatty strio_false
1399 #define strio_pid strio_nil
1401 #define strio_fileno strio_nil
1414 if (
NIL_P(
string)) {
1486 VALUE ext_enc, int_enc, opt;
1488 argc =
rb_scan_args(argc, argv,
"11:", &ext_enc, &int_enc, &opt);
1490 if (
NIL_P(ext_enc)) {