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 STRIO_READABLE FL_USER4
111 #define STRIO_WRITABLE FL_USER5
112 #define STRIO_READWRITE (STRIO_READABLE|STRIO_WRITABLE)
114 #define STRIO_MODE_SET_P(strio, mode) \
115 ((RBASIC(strio)->flags & STRIO_##mode) && \
116 ((struct StringIO*)DATA_PTR(strio))->flags & FMODE_##mode)
117 #define CLOSED(strio) (!STRIO_MODE_SET_P(strio, READWRITE))
118 #define READABLE(strio) STRIO_MODE_SET_P(strio, READABLE)
119 #define WRITABLE(strio) STRIO_MODE_SET_P(strio, WRITABLE)
182 switch (
rb_scan_args(argc, argv,
"02", &
string, &mode)) {
187 trunc = flags & O_TRUNC;
454 if (copy == orig)
return copy;
498 #define strio_binmode strio_self
501 #define strio_fcntl strio_unimpl
504 #define strio_flush strio_self
507 #define strio_fsync strio_0
627 #define strio_set_sync strio_first
629 #define strio_tell strio_get_pos
658 rb_warn(
"StringIO#bytes is deprecated; use #each_byte instead");
712 if (pos + len > olen) {
769 if (p+clen >= pend)
break;
792 long pos = ptr->
pos, cl = 1;
803 if (cl == 0)
return Qnil;
812 memmove(s + cl, s + pos, rest);
878 rb_warn(
"StringIO#chars is deprecated; use #each_char instead");
922 rb_warn(
"StringIO#codepoints is deprecated; use #each_codepoint instead");
934 for (c = 0; c < (1 <<
CHAR_BIT); c++) {
938 skip[(
unsigned char)*pat++] = m;
943 bm_search(
const char *little,
long llen,
const char *big,
long blen,
const long *skip)
951 while (j >= 0 && big[k] == little[j]) {
955 if (j < 0)
return k + 1;
956 i += skip[(
unsigned char)big[i]];
964 const char *s, *e, *
p;
1000 if (limit > 0 && s + limit < e) {
1006 else if ((n = RSTRING_LEN(str)) == 0) {
1008 while (*p ==
'\n') {
1014 while ((p = memchr(p,
'\n', e - p)) && (p != e)) {
1023 if ((p = memchr(s,
RSTRING_PTR(str)[0], e - s)) != 0) {
1031 for (p = s; p + n <= e; ++
p) {
1042 if ((pos =
bm_search(p, n, s, e - s, skip)) >= 0) {
1126 rb_warn(
"StringIO#lines is deprecated; use #each_line instead");
1184 if (len == 0)
return INT2FIX(0);
1190 if (ptr->
pos == olen) {
1209 #define strio_addstr rb_io_addstr
1218 #define strio_print rb_io_print
1226 #define strio_printf rb_io_printf
1258 #define strio_puts rb_io_puts
1282 if (!
NIL_P(argv[0])) {
1297 if (len <= ptr->
pos) {
1319 if (len > rest) len = rest;
1348 #define strio_syswrite rb_io_write
1356 #define strio_isatty strio_false
1359 #define strio_pid strio_nil
1362 #define strio_fileno strio_nil
1374 if (
NIL_P(
string)) {
1446 VALUE ext_enc, int_enc, opt;
1448 argc =
rb_scan_args(argc, argv,
"11:", &ext_enc, &int_enc, &opt);
1450 if (
NIL_P(ext_enc)) {