25 #define free(x) xfree(x) 27 #if defined(DOSISH) || defined(__CYGWIN__) 31 #include <sys/types.h> 32 #if defined HAVE_NET_SOCKET_H 33 # include <net/socket.h> 34 #elif defined HAVE_SYS_SOCKET_H 35 # include <sys/socket.h> 38 #if defined(__BOW__) || defined(__CYGWIN__) || defined(_WIN32) 39 # define NO_SAFE_RENAME 42 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__sun) || defined(_nec_ews) 50 #include <sys/types.h> 51 #if defined(HAVE_SYS_IOCTL_H) && !defined(_WIN32) 52 #include <sys/ioctl.h> 54 #if defined(HAVE_FCNTL_H) || defined(_WIN32) 56 #elif defined(HAVE_SYS_FCNTL_H) 57 #include <sys/fcntl.h> 60 #if !HAVE_OFF_T && !defined(off_t) 64 #ifdef HAVE_SYS_TIME_H 65 # include <sys/time.h> 70 #if defined(HAVE_SYS_PARAM_H) || defined(__HIUX_MPP__) 71 # include <sys/param.h> 84 #elif defined HAVE_SYS_SYSCALL_H 85 #include <sys/syscall.h> 92 #ifdef HAVE_SYS_WAIT_H 93 # include <sys/wait.h> 99 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR) 102 #if SIZEOF_OFF_T > SIZEOF_LONG && !defined(HAVE_LONG_LONG) 103 # error off_t is bigger than long, but you have no long long... 107 # ifdef _POSIX_PIPE_BUF 108 # define PIPE_BUF _POSIX_PIPE_BUF 110 # define PIPE_BUF 512 115 # define EWOULDBLOCK EAGAIN 118 #if defined(HAVE___SYSCALL) && (defined(__APPLE__) || defined(__OpenBSD__)) 120 off_t __syscall(quad_t number, ...);
123 #ifdef __native_client__ 130 #define IO_RBUF_CAPA_MIN 8192 131 #define IO_CBUF_CAPA_MIN (128*1024) 132 #define IO_RBUF_CAPA_FOR(fptr) (NEED_READCONV(fptr) ? IO_CBUF_CAPA_MIN : IO_RBUF_CAPA_MIN) 133 #define IO_WBUF_CAPA_MIN 8192 138 #define open rb_w32_uopen 164 #define id_exception idException 171 static VALUE sym_DATA;
174 static VALUE sym_HOLE;
199 rb_bug(
"rb_update_max_fd: invalid fd (%d) given.", fd);
202 while (max_fd < afd) {
211 #if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC) 212 int flags, flags2, ret;
221 if (flags != flags2) {
224 rb_bug(
"rb_maygvl_fd_fix_cloexec: fcntl(%d, F_SETFD, %d) failed: %s", fd, flags2,
strerror(
errno));
241 #if defined(O_CLOEXEC) && defined(F_GETFD) 258 static int o_cloexec_state = -1;
263 #elif defined O_NOINHERIT 264 flags |= O_NOINHERIT;
266 ret = open(pathname, flags, mode);
267 if (ret == -1)
return -1;
268 if (ret <= 2 || o_cloexec_state == 0) {
271 else if (o_cloexec_state > 0) {
294 if (oldfd == newfd) {
298 #if defined(HAVE_DUP3) && defined(O_CLOEXEC) 299 static int try_dup3 = 1;
300 if (2 < newfd && try_dup3) {
305 if (
errno == ENOSYS) {
307 ret =
dup2(oldfd, newfd);
311 ret =
dup2(oldfd, newfd);
314 ret =
dup2(oldfd, newfd);
316 if (ret == -1)
return -1;
327 #if defined(HAVE_PIPE2) 328 static int try_pipe2 = 1;
334 if (
errno == ENOSYS) {
345 if (ret == -1)
return -1;
347 if (ret == 0 && fildes[1] == -1) {
364 #if defined(HAVE_FCNTL) && defined(F_DUPFD_CLOEXEC) && defined(F_DUPFD) 365 static int try_dupfd_cloexec = 1;
366 if (try_dupfd_cloexec) {
374 if (
errno == EINVAL) {
377 try_dupfd_cloexec = 0;
384 #elif defined(HAVE_FCNTL) && defined(F_DUPFD) 386 #elif defined(HAVE_DUP) 388 if (ret != -1 && ret < minfd) {
389 const int prev_fd = ret;
395 # error "dup() or fcntl(F_DUPFD) must be supported." 397 if (ret == -1)
return -1;
402 #define argf_of(obj) (*(struct argf *)DATA_PTR(obj)) 403 #define ARGF argf_of(argf) 405 #define GetWriteIO(io) rb_io_get_write_io(io) 407 #define READ_DATA_PENDING(fptr) ((fptr)->rbuf.len) 408 #define READ_DATA_PENDING_COUNT(fptr) ((fptr)->rbuf.len) 409 #define READ_DATA_PENDING_PTR(fptr) ((fptr)->rbuf.ptr+(fptr)->rbuf.off) 410 #define READ_DATA_BUFFERED(fptr) READ_DATA_PENDING(fptr) 412 #define READ_CHAR_PENDING(fptr) ((fptr)->cbuf.len) 413 #define READ_CHAR_PENDING_COUNT(fptr) ((fptr)->cbuf.len) 414 #define READ_CHAR_PENDING_PTR(fptr) ((fptr)->cbuf.ptr+(fptr)->cbuf.off) 417 #define WAIT_FD_IN_WIN32(fptr) \ 418 (rb_w32_io_cancelable_p((fptr)->fd) ? 0 : rb_thread_wait_fd((fptr)->fd)) 420 #define WAIT_FD_IN_WIN32(fptr) 423 #define READ_CHECK(fptr) do {\ 424 if (!READ_DATA_PENDING(fptr)) {\ 425 WAIT_FD_IN_WIN32(fptr);\ 426 rb_io_check_closed(fptr);\ 432 # define S_ISSOCK(m) _S_ISSOCK(m) 435 # define S_ISSOCK(m) (((m) & S_IFMT) == _S_IFSOCK) 438 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) 447 #define NEED_NEWLINE_DECORATOR_ON_READ(fptr) ((fptr)->mode & FMODE_TEXTMODE) 448 #define NEED_NEWLINE_DECORATOR_ON_WRITE(fptr) ((fptr)->mode & FMODE_TEXTMODE) 449 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32) 451 # define DEFAULT_TEXTMODE FMODE_TEXTMODE 452 # define TEXTMODE_NEWLINE_DECORATOR_ON_WRITE ECONV_CRLF_NEWLINE_DECORATOR 460 #define NEED_READCONV(fptr) ((fptr)->encs.enc2 != NULL || (fptr)->encs.ecflags & ~ECONV_CRLF_NEWLINE_DECORATOR) 461 #define NEED_WRITECONV(fptr) (((fptr)->encs.enc != NULL && (fptr)->encs.enc != rb_ascii8bit_encoding()) || ((fptr)->encs.ecflags & ((ECONV_DECORATOR_MASK & ~ECONV_CRLF_NEWLINE_DECORATOR)|ECONV_STATEFUL_DECORATOR_MASK))) 462 #define SET_BINARY_MODE(fptr) setmode((fptr)->fd, O_BINARY) 464 #define NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr) do {\ 465 if (NEED_NEWLINE_DECORATOR_ON_READ(fptr)) {\ 466 if (((fptr)->mode & FMODE_READABLE) &&\ 467 !((fptr)->encs.ecflags & ECONV_NEWLINE_DECORATOR_MASK)) {\ 468 setmode((fptr)->fd, O_BINARY);\ 471 setmode((fptr)->fd, O_TEXT);\ 476 #define SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(enc2, ecflags) do {\ 477 if ((enc2) && ((ecflags) & ECONV_DEFAULT_NEWLINE_DECORATOR)) {\ 478 (ecflags) |= ECONV_UNIVERSAL_NEWLINE_DECORATOR;\ 504 if (r < 0 &&
errno) {
516 if (pos < 0 &&
errno) {
523 extra_max = (long)(pos - fptr->
rbuf.len);
524 p = fptr->
rbuf.ptr + fptr->
rbuf.off;
527 if (*(fptr->
rbuf.ptr + fptr->
rbuf.capa - 1) ==
'\r') {
531 for (i = 0; i < fptr->
rbuf.len; i++) {
532 if (*p ==
'\n') newlines++;
533 if (extra_max == newlines)
break;
538 while (newlines >= 0) {
540 if (newlines == 0)
break;
545 read_size = _read(fptr->
fd, buf, fptr->
rbuf.len + newlines);
551 if (read_size == fptr->
rbuf.len) {
573 set_binary_mode_with_seek_cur(
rb_io_t *fptr)
583 #define SET_BINARY_MODE_WITH_SEEK_CUR(fptr) set_binary_mode_with_seek_cur(fptr) 587 # define DEFAULT_TEXTMODE 0 588 #define NEED_READCONV(fptr) ((fptr)->encs.enc2 != NULL || NEED_NEWLINE_DECORATOR_ON_READ(fptr)) 589 #define NEED_WRITECONV(fptr) (((fptr)->encs.enc != NULL && (fptr)->encs.enc != rb_ascii8bit_encoding()) || NEED_NEWLINE_DECORATOR_ON_WRITE(fptr) || ((fptr)->encs.ecflags & (ECONV_DECORATOR_MASK|ECONV_STATEFUL_DECORATOR_MASK))) 590 #define SET_BINARY_MODE(fptr) (void)(fptr) 591 #define NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr) (void)(fptr) 592 #define SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(enc2, ecflags) ((void)(enc2), (void)(ecflags)) 593 #define SET_BINARY_MODE_WITH_SEEK_CUR(fptr) (void)(fptr) 596 #if !defined HAVE_SHUTDOWN && !defined shutdown 597 #define shutdown(a,b) 0 601 #define is_socket(fd, path) rb_w32_is_socket(fd) 602 #elif !defined(S_ISSOCK) 603 #define is_socket(fd, path) 0 609 if (
fstat(fd, &sbuf) < 0)
611 return S_ISSOCK(sbuf.st_mode);
691 return write_io ? write_io :
Qnil;
717 #if !(defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)) 728 if (r < 0 &&
errno) {
750 #if SIZEOF_LONG > SIZEOF_INT 755 fptr->
rbuf.capa = (int)len;
757 fptr->
rbuf.capa = min_capa;
760 if (fptr->
rbuf.capa < len + fptr->
rbuf.len) {
763 if (fptr->
rbuf.off < len) {
766 char, fptr->
rbuf.len);
769 fptr->
rbuf.off-=(int)len;
770 fptr->
rbuf.len+=(int)len;
784 #define io_seek(fptr, ofs, whence) (errno = 0, lseek(flush_before_seek(fptr)->fd, (ofs), (whence))) 785 #define io_tell(fptr) lseek(flush_before_seek(fptr)->fd, 0, SEEK_CUR) 800 if (fptr->
wbuf.len) {
852 if (fptr->
rbuf.len) {
878 if (err == EMFILE || err == ENFILE || err == ENOMEM) {
915 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 931 struct io_internal_writev_struct {
934 const struct iovec *iov;
942 return read(iis->
fd, iis->
buf, iis->
capa);
949 return write(iis->
fd, iis->
buf, iis->
capa);
961 internal_writev_func(
void *ptr)
963 struct io_internal_writev_struct *iis = ptr;
964 return writev(iis->fd, iis->iov, iis->iovcnt);
1004 rb_writev_internal(
int fd,
const struct iovec *iov,
int iovcnt)
1006 struct io_internal_writev_struct iis;
1009 iis.iovcnt = iovcnt;
1019 long l = fptr->
wbuf.len;
1020 ssize_t r = write(fptr->
fd, fptr->
wbuf.ptr+fptr->
wbuf.off, (
size_t)l);
1022 if (fptr->
wbuf.len <= r) {
1028 fptr->
wbuf.off += (int)r;
1029 fptr->
wbuf.len -= (int)r;
1044 return !result ? (
void*)1 : (
void*)
result;
1068 else if (ret == 1) {
1092 if (fptr->
wbuf.len == 0)
1111 #if defined(ERESTART) 1118 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN 1137 #if defined(ERESTART) 1153 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN 1168 const char *senc, *denc;
1241 if (fptr->
wbuf.len) {
1242 struct iovec iov[2];
1249 r = rb_writev_internal(fptr->
fd, iov, 2);
1254 if (fptr->
wbuf.len <= r) {
1255 r -= fptr->
wbuf.len;
1260 fptr->
wbuf.off += (int)r;
1261 fptr->
wbuf.len -= (int)r;
1281 if (fptr->
wbuf.len) {
1282 if (fptr->
wbuf.len+len <= fptr->wbuf.capa) {
1283 if (fptr->
wbuf.capa < fptr->
wbuf.off+fptr->
wbuf.len+len) {
1288 fptr->
wbuf.len += (int)len;
1307 long n, r, offset = 0;
1312 if ((n = len) <= 0)
return n;
1322 (fptr->
wbuf.ptr && fptr->
wbuf.capa <= fptr->
wbuf.len + len)) {
1328 arg.
ptr = ptr + offset;
1337 if (r == n)
return len;
1353 if (fptr->
wbuf.off) {
1359 fptr->
wbuf.len += (int)len;
1363 # define MODE_BTMODE(a,b,c) ((fmode & FMODE_BINMODE) ? (b) : \ 1364 (fmode & FMODE_TEXTMODE) ? (c) : (a)) 1375 #define fmode (fptr->mode) 1379 rb_raise(
rb_eArgError,
"ASCII incompatible string written for text mode IO without encoding conversion: %s",
1391 if (!
NIL_P(common_encoding)) {
1402 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32) 1403 #define fmode (fptr->mode) 1410 setmode(fptr->
fd, O_TEXT);
1413 rb_raise(
rb_eArgError,
"ASCII incompatible string written for text mode IO without encoding conversion: %s",
1432 if (len > 0)
return len;
1454 return (ssize_t)
io_binwrite(0, buf, (
long)size, fptr, 0);
1538 nogvl_fsync(
void *
ptr)
1617 pos -= fptr->
rbuf.len;
1629 pos =
io_seek(fptr, pos, whence);
1645 if (vwhence == sym_DATA)
1649 if (vwhence == sym_HOLE)
1679 VALUE offset, ptrname;
1682 if (
rb_scan_args(argc, argv,
"11", &offset, &ptrname) == 2) {
1741 if (io ==
ARGF.current_file) {
1766 if (fptr->
rbuf.len == 0) {
1785 fptr->
rbuf.len = (int)r;
1837 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32) 1931 # define rb_io_fsync rb_f_notimplement 1932 # define rb_io_sync rb_f_notimplement 1941 #ifdef HAVE_FDATASYNC 1943 nogvl_fdatasync(
void *
ptr)
1951 return (
VALUE)fdatasync(fptr->
fd);
1983 #define rb_io_fdatasync rb_io_fsync 2054 static const char closed[] =
" (closed)";
2056 fptr =
RFILE(obj)->fptr;
2098 if (n <= 0)
return 0;
2099 if (n > len) n = (int)len;
2101 fptr->
rbuf.off += n;
2102 fptr->
rbuf.len -= n;
2124 if ((n -= c) <= 0)
break;
2133 if ((n -= c) <= 0)
break;
2182 return (ssize_t)
io_bufread(buf, (
long)size, fptr);
2193 #
if defined(__HAIKU__)
2201 if (st.st_size >= pos && pos >= 0) {
2202 siz += st.st_size - pos;
2228 const char *sname, *dname;
2249 #define MORE_CHAR_SUSPENDED Qtrue 2250 #define MORE_CHAR_FINISHED Qnil 2254 const unsigned char *ss, *sp, *se;
2255 unsigned char *ds, *
dp, *de;
2263 if (fptr->
cbuf.len == fptr->
cbuf.capa)
2265 if (fptr->
cbuf.len == 0)
2267 else if (fptr->
cbuf.off + fptr->
cbuf.len == fptr->
cbuf.capa) {
2272 cbuf_len0 = fptr->
cbuf.len;
2275 ss = sp = (
const unsigned char *)fptr->
rbuf.ptr + fptr->
rbuf.off;
2276 se = sp + fptr->
rbuf.len;
2277 ds = dp = (
unsigned char *)fptr->
cbuf.ptr + fptr->
cbuf.off + fptr->
cbuf.len;
2278 de = (
unsigned char *)fptr->
cbuf.ptr + fptr->
cbuf.capa;
2280 fptr->
rbuf.off += (int)(sp - ss);
2281 fptr->
rbuf.len -= (int)(sp - ss);
2282 fptr->
cbuf.len += (int)(dp - ds);
2287 fptr->
rbuf.off -= putbackable;
2288 fptr->
rbuf.len += putbackable;
2295 if (cbuf_len0 != fptr->
cbuf.len)
2303 if (fptr->
rbuf.len == 0) {
2309 ds = dp = (
unsigned char *)fptr->
cbuf.ptr + fptr->
cbuf.off + fptr->
cbuf.len;
2310 de = (
unsigned char *)fptr->
cbuf.ptr + fptr->
cbuf.capa;
2312 fptr->
cbuf.len += (int)(dp - ds);
2319 if (cbuf_len0 != fptr->
cbuf.len)
2353 if (fptr->
cbuf.len == 0)
2355 else if (fptr->
cbuf.capa/2 < fptr->
cbuf.off) {
2366 len = (len + 1) & ~1
L;
2402 int first = !
NIL_P(str);
2408 if (fptr->
cbuf.len) {
2414 if (fptr->
cbuf.len) {
2435 if (siz == 0) siz = BUFSIZ;
2439 n =
io_fread(str, bytes, siz - bytes, fptr);
2440 if (n == 0 && bytes == 0) {
2448 if (bytes < siz)
break;
2467 oflags =
fcntl(fptr->
fd, F_GETFL);
2517 if ((len =
NUM2LONG(length)) < 0) {
2548 if (nonblock && (e ==
EWOULDBLOCK || e == EAGAIN)) {
2553 e,
"read would block");
2655 if ((len =
NUM2LONG(length)) < 0) {
2681 e,
"read would block");
2805 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32) 2811 if (
NIL_P(length)) {
2831 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32) 2832 previous_mode = set_binary_mode_with_seek_cur(fptr);
2836 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32) 2837 if (previous_mode == O_TEXT) {
2838 setmode(fptr->
fd, O_TEXT);
2841 if (n == 0)
return Qnil;
2869 if (0 < limit && limit < searchlen)
2870 searchlen = (int)limit;
2871 e = memchr(p, delim, searchlen);
2873 int len = (int)(e-p+1);
2889 fptr->
cbuf.off += searchlen;
2890 fptr->
cbuf.len -= searchlen;
2912 if (limit > 0 && pending > limit) pending = limit;
2913 e = memchr(p, delim, pending);
2914 if (e) pending = e - p + 1;
2927 if (e)
return delim;
2951 if (*p != term)
return TRUE;
2953 while (--i && *++p == term);
2956 const char *e = p +
cnt;
2974 if (cnt >
sizeof buf) cnt =
sizeof buf;
2975 if (*p != term)
return TRUE;
2977 while (--i && *++p == term);
3002 e = memchr(p,
'\n', pending);
3004 pending = (int)(e - p + 1);
3006 chomplen = (pending > 1 && *(e-1) ==
'\r') + 1;
3011 fptr->
rbuf.off += pending;
3012 fptr->
rbuf.len -= pending;
3017 fptr->
rbuf.off += chomplen;
3018 fptr->
rbuf.len -= chomplen;
3020 len += pending - chomplen;
3040 unsigned int chomp: 1;
3056 args->
chomp = chomp;
3074 else if (2 <= argc) {
3075 rs = argv[0], lim = argv[1];
3095 if (enc_io != enc_rs &&
3130 if (
NIL_P(rs) && limit < 0) {
3135 else if (limit == 0) {
3144 int c, newline = -1;
3145 const char *rsptr = 0;
3148 int extra_limit = 16;
3149 int chomp_cr = chomp;
3173 newline = (
unsigned char)rsptr[rslen - 1];
3174 chomp_cr = chomp && rslen == 1 && newline ==
'\n';
3178 while ((c =
appendline(fptr, newline, &str, &limit)) !=
EOF) {
3179 const char *s, *p, *pp, *e;
3187 if (pp != p)
continue;
3188 if (!rspara)
rscheck(rsptr, rslen, rs);
3189 if (
memcmp(p, rsptr, rslen) == 0) {
3191 if (chomp_cr && p > s && *(p-1) ==
'\r') --p;
3215 if (rspara && c !=
EOF)
3221 if (!
NIL_P(str) && !nolimit) {
3232 int old_lineno, new_lineno;
3236 old_lineno = fptr->
lineno;
3238 if (!
NIL_P(str) && (new_lineno = fptr->
lineno) != old_lineno) {
3239 if (io ==
ARGF.current_file) {
3240 ARGF.lineno += new_lineno - old_lineno;
3244 ARGF.last_lineno = new_lineno;
3433 if (arg->
limit == 0)
3479 if (args.
limit == 0)
3494 rb_warn(
"IO#lines is deprecated; use #each_line instead");
3526 while (fptr->
rbuf.len > 0) {
3527 char *p = fptr->
rbuf.ptr + fptr->
rbuf.off++;
3545 rb_warn(
"IO#bytes is deprecated; use #each_byte instead");
3565 if (fptr->
cbuf.len) {
3571 if (fptr->
cbuf.len == fptr->
cbuf.capa) {
3577 if (fptr->
cbuf.len == 0) {
3583 fptr->
cbuf.off += 1;
3584 fptr->
cbuf.len -= 1;
3616 fptr->
rbuf.off += 1;
3617 fptr->
rbuf.len -= 1;
3625 fptr->
rbuf.off += n;
3626 fptr->
rbuf.len -= n;
3699 rb_warn(
"IO#chars is deprecated; use #each_char instead");
3740 if (fptr->
cbuf.len) {
3749 if (fptr->
cbuf.len == fptr->
cbuf.capa) {
3773 c = (
unsigned char)fptr->
cbuf.ptr[fptr->
cbuf.off];
3775 fptr->
cbuf.off += n;
3776 fptr->
cbuf.len -= n;
3789 fptr->
rbuf.off += n;
3790 fptr->
rbuf.len -= n;
3798 char cbuf[8], *p = cbuf;
3800 if (more >
numberof(cbuf))
goto invalid;
3801 more += n = fptr->
rbuf.len;
3802 if (more >
numberof(cbuf))
goto invalid;
3804 (p += n, (more -= n) > 0)) {
3806 if ((n = fptr->
rbuf.len) > more) n = more;
3827 rb_warn(
"IO#codepoints is deprecated; use #each_codepoint instead");
3916 c = (
unsigned char)fptr->
rbuf.ptr[fptr->
rbuf.off-1];
4012 #if SIZEOF_LONG > SIZEOF_INT 4017 if (fptr->
cbuf.capa - fptr->
cbuf.len < len)
4019 if (fptr->
cbuf.off < len) {
4022 char, fptr->
cbuf.len);
4025 fptr->
cbuf.off -= (int)len;
4026 fptr->
cbuf.len += (int)len;
4054 if (isatty(fptr->
fd) == 0)
4059 #if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC) 4082 if (io != write_io) {
4084 if (fptr && 0 <= (fd = fptr->
fd)) {
4091 if (fptr && 0 <= (fd = fptr->
fd)) {
4098 #define rb_io_close_on_exec_p rb_f_notimplement 4101 #if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC) 4131 if (io != write_io) {
4133 if (fptr && 0 <= (fd = fptr->
fd)) {
4136 ret = (ret & ~FD_CLOEXEC) | flag;
4145 if (fptr && 0 <= (fd = fptr->
fd)) {
4148 ret = (ret & ~FD_CLOEXEC) | flag;
4156 #define rb_io_set_close_on_exec rb_f_notimplement 4159 #define FMODE_PREP (1<<16) 4160 #define IS_PREP_STDIO(f) ((f)->mode & FMODE_PREP) 4161 #define PREP_STDIO_NAME(f) (RSTRING_PTR((f)->pathv)) 4166 unsigned char *ds, *
dp, *de;
4169 if (!fptr->
wbuf.ptr) {
4170 unsigned char buf[1024];
4176 de = buf +
sizeof(
buf);
4208 if (fptr->
wbuf.len == fptr->
wbuf.capa) {
4213 ds = dp = (
unsigned char *)fptr->
wbuf.ptr + fptr->
wbuf.off + fptr->
wbuf.len;
4214 de = (
unsigned char *)fptr->
wbuf.ptr + fptr->
wbuf.capa;
4216 fptr->
wbuf.len += (int)(dp - ds);
4243 return (
void*)(
intptr_t)close(*fd);
4264 return (
void*)(
intptr_t)fclose(file);
4271 return fclose(file);
4285 int mode = fptr->
mode;
4298 if (fptr->
wbuf.len) {
4316 else if (stdio_file) {
4334 if (!
NIL_P(err) && !noraise) {
4401 if (!fptr)
return 0;
4417 size += fptr->
rbuf.capa;
4418 size += fptr->
wbuf.capa;
4419 size += fptr->
cbuf.capa;
4436 if (io != write_io) {
4437 write_fptr =
RFILE(write_io)->fptr;
4438 if (write_fptr && 0 <= write_fptr->
fd) {
4443 fptr =
RFILE(io)->fptr;
4444 if (!fptr)
return 0;
4445 if (fptr->
fd < 0)
return 0;
4560 if (io != write_io) {
4561 write_fptr =
RFILE(write_io)->fptr;
4562 if (write_fptr && 0 <= write_fptr->
fd) {
4596 if (fptr->
fd < 0)
return Qnil;
4610 if (io != write_io) {
4615 RFILE(io)->fptr = wfptr;
4657 if (fptr->
fd < 0)
return Qnil;
4674 if (io != write_io) {
4698 VALUE offset, ptrname;
4703 if (
rb_scan_args(argc, argv,
"11", &offset, &ptrname) == 2) {
4713 rb_warn(
"sysseek for buffered IO");
4716 pos = lseek(fptr->
fd, pos, whence);
4750 if (fptr->
wbuf.len) {
4751 rb_warn(
"syswrite for buffered IO");
4795 if (ilen == 0)
return str;
4827 if (n == 0 && ilen > 0) {
4970 const char *m = modestr, *p =
NULL;
5032 if (oflags & O_APPEND) {
5035 if (oflags & O_TRUNC) {
5038 if (oflags & O_CREAT) {
5095 # define MODE_BINARY(a,b) ((oflags & O_BINARY) ? (b) : (a)) 5097 # define MODE_BINARY(a,b) (a) 5099 int accmode = oflags & (O_RDONLY|O_WRONLY|O_RDWR);
5100 if (oflags & O_APPEND) {
5101 if (accmode == O_WRONLY) {
5104 if (accmode == O_RDWR) {
5108 switch (oflags & (O_RDONLY|O_WRONLY|O_RDWR)) {
5116 if (oflags & O_TRUNC) {
5131 int default_ext = 0;
5141 else if (intern ==
NULL) {
5147 *enc = (default_ext && intern != ext) ?
NULL : ext;
5159 rb_enc_warn(enc,
"Unsupported encoding %s ignored", name);
5169 int fmode = fmode_p ? *fmode_p : 0;
5176 len = p ? (p++ - estr) : (
long)
strlen(estr);
5184 rb_enc_warn(estr_enc,
"BOM with non-UTF encoding %s is nonsense", estr);
5185 fmode &= ~FMODE_SETENC_BY_BOM;
5193 memcpy(encname, estr, len);
5194 encname[
len] =
'\0';
5199 if (fmode_p) *fmode_p =
fmode;
5211 if (*p ==
'-' && *(p+1) ==
'\0') {
5219 else if (!(fmode & FMODE_SETENC_BY_BOM) && (idx2 == idx)) {
5241 if (v !=
Qnil) encoding = v;
5243 if (v !=
Qnil) extenc = v;
5245 if (v !=
Qundef) intenc = v;
5252 encoding, extenc ==
Qundef ?
"internal" :
"external");
5260 if (
NIL_P(intenc)) {
5267 if (*p ==
'-' && *(p+1) ==
'\0') {
5278 if (extencoding == intencoding) {
5282 if (!
NIL_P(encoding)) {
5286 enc_p, enc2_p, fmode_p);
5304 int fmode = *fmode_p;
5312 if (!(fmode & FMODE_BINMODE) &&
5317 #if !DEFAULT_TEXTMODE 5318 else if (!(ecflags & ECONV_NEWLINE_DECORATOR_MASK)) {
5328 if (!
NIL_P(opthash)) {
5356 int *oflags_p,
int *fmode_p,
convconfig_t *convconfig_p)
5363 int has_enc = 0, has_vmode = 0;
5401 if (
NIL_P(opthash)) {
5405 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE 5408 0, TEXTMODE_NEWLINE_DECORATOR_ON_WRITE) : 0;
5418 if (!
NIL_P(vmode)) {
5441 #if DEFAULT_TEXTMODE 5442 else if (
NIL_P(vmode)) {
5449 if (!
NIL_P(*vperm_p)) {
5461 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE 5464 0, TEXTMODE_NEWLINE_DECORATOR_ON_WRITE) : 0;
5482 convconfig_p->enc = enc;
5483 convconfig_p->enc2 = enc2;
5484 convconfig_p->ecflags = ecflags;
5485 convconfig_p->ecopts = ecopts;
5544 file = fdopen(fd, modestr);
5551 file = fdopen(fd, modestr);
5556 file = fdopen(fd, modestr);
5560 if (e == 0) e = EINVAL;
5561 #elif defined(__sun) 5562 if (e == 0) e = EMFILE;
5570 if (setvbuf(file,
NULL, _IOFBF, 0) != 0)
5571 rb_warn(
"setvbuf() can't be honoured (fd=%d)", fd);
5579 int t = isatty(fptr->
fd);
5591 VALUE b1, b2, b3, b4;
5681 convconfig->enc, convconfig->enc2);
5685 fptr->
encs = *convconfig;
5698 const char *p =
strchr(modestr,
':');
5703 &convconfig.enc, &convconfig.enc2, &fmode);
5711 convconfig.ecflags = 0;
5712 convconfig.ecopts =
Qnil;
5735 #if defined(__CYGWIN__) || !defined(HAVE_WORKING_FORK) 5758 if (list->
fptr == fptr) {
5764 while (list->
next) {
5775 #if defined (_WIN32) || defined(__CYGWIN__) 5793 #if !defined(HAVE_WORKING_FORK) && !defined(_WIN32) 5839 #define HAVE_SPAWNV 1 5840 #define spawnv(mode, cmd, args) rb_w32_uaspawn((mode), (cmd), (args)) 5841 #define spawn(mode, cmd) rb_w32_uspawn((mode), (cmd), 0) 5844 #if defined(HAVE_WORKING_FORK) || defined(HAVE_SPAWNV) 5854 #ifdef HAVE_WORKING_FORK 5856 popen_redirect(
struct popen_arg *p)
5859 close(p->write_pair[1]);
5860 if (p->write_pair[0] != 0) {
5861 dup2(p->write_pair[0], 0);
5862 close(p->write_pair[0]);
5865 if (p->pair[1] != 1) {
5866 dup2(p->pair[1], 1);
5872 if (p->pair[1] != 1) {
5873 dup2(p->pair[1], 1);
5879 if (p->pair[0] != 0) {
5880 dup2(p->pair[0], 0);
5886 #if defined(__linux__) 5897 linux_get_maxfd(
void)
5900 char buf[4096], *p, *np, *e;
5903 if (fd == -1)
return -1;
5904 ss = read(fd, buf,
sizeof(buf));
5905 if (ss == -1)
goto err;
5908 while ((
int)
sizeof(
"FDSize:\t0\n")-1 <= e-p &&
5909 (np = memchr(p,
'\n', e-p)) !=
NULL) {
5910 if (
memcmp(p,
"FDSize:",
sizeof(
"FDSize:")-1) == 0) {
5912 p +=
sizeof(
"FDSize:")-1;
5932 #if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC) 5937 ret =
fcntl(0, F_MAXFD);
5939 maxhint = max = ret;
5940 # elif defined(__linux__) 5941 ret = linux_get_maxfd();
5948 for (fd = lowfd; fd <=
max; fd++) {
5949 if (!
NIL_P(noclose_fds) &&
5956 # define CONTIGUOUS_CLOSED_FDS 20 5958 if (max < fd + CONTIGUOUS_CLOSED_FDS)
5959 max = fd + CONTIGUOUS_CLOSED_FDS;
5966 popen_exec(
void *pp,
char *errmsg,
size_t errmsg_len)
5968 struct popen_arg *p = (
struct popen_arg*)pp;
5974 #if defined(HAVE_WORKING_FORK) || defined(HAVE_SPAWNV) 5976 rb_execarg_fixup_v(
VALUE execarg_obj)
5996 #if defined(HAVE_WORKING_FORK) 5998 char errmsg[80] = {
'\0' };
6000 #if defined(HAVE_WORKING_FORK) || defined(HAVE_SPAWNV) 6002 struct popen_arg arg;
6005 #if defined(HAVE_SPAWNV) 6006 # if defined(HAVE_SPAWNVE) 6007 # define DO_SPAWN(cmd, args, envp) ((args) ? \ 6008 spawnve(P_NOWAIT, (cmd), (args), (envp)) : \ 6009 spawne(P_NOWAIT, (cmd), (envp))) 6011 # define DO_SPAWN(cmd, args, envp) ((args) ? \ 6012 spawnv(P_NOWAIT, (cmd), (args)) : \ 6013 spawn(P_NOWAIT, (cmd))) 6015 # if !defined(HAVE_WORKING_FORK) 6017 # if defined(HAVE_SPAWNVE) 6022 #if !defined(HAVE_WORKING_FORK) 6028 #if !defined(HAVE_WORKING_FORK) 6029 const char *
cmd = 0;
6035 #if defined(HAVE_WORKING_FORK) || defined(HAVE_SPAWNV) 6036 arg.execarg_obj = execarg_obj;
6039 arg.pair[0] = arg.pair[1] = -1;
6040 arg.write_pair[0] = arg.write_pair[1] = -1;
6041 # if !defined(HAVE_WORKING_FORK) 6048 if (
rb_pipe(arg.write_pair) < 0)
6052 close(arg.write_pair[0]);
6053 close(arg.write_pair[1]);
6076 if (!
NIL_P(execarg_obj)) {
6077 rb_protect(rb_execarg_fixup_v, execarg_obj, &state);
6079 if (0 <= arg.write_pair[0]) close(arg.write_pair[0]);
6080 if (0 <= arg.write_pair[1]) close(arg.write_pair[1]);
6081 if (0 <= arg.pair[0]) close(arg.pair[0]);
6082 if (0 <= arg.pair[1]) close(arg.pair[1]);
6087 # if defined(HAVE_WORKING_FORK) 6091 # if defined(HAVE_SPAWNVE) 6094 while ((pid = DO_SPAWN(cmd, args, envp)) == -1) {
6096 switch (e =
errno) {
6098 # if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN 6112 # if defined(HAVE_WORKING_FORK) 6116 popen_redirect(&arg);
6128 # if defined(HAVE_WORKING_FORK) 6134 close(arg.write_pair[0]);
6135 close(arg.write_pair[1]);
6137 # if defined(HAVE_WORKING_FORK) 6146 close(arg.write_pair[0]);
6147 write_fd = arg.write_pair[1];
6149 else if (fmode & FMODE_READABLE) {
6159 if (!
NIL_P(execarg_obj)) {
6163 fp = popen(cmd, modestr);
6179 fptr->
encs = *convconfig;
6180 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32) 6190 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE 6192 fptr->
encs.
ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
6198 if (0 <= write_fd) {
6201 write_fptr->
fd = write_fd;
6203 fptr->
mode &= ~FMODE_WRITABLE;
6208 #if defined (__CYGWIN__) || !defined(HAVE_WORKING_FORK) 6219 #if !defined(HAVE_WORKING_FORK) 6221 "fork() function is unimplemented on this machine");
6239 return pipe_open(execarg_obj, modestr, fmode, convconfig);
6343 const char *modestr;
6358 int ex = !
NIL_P(opt);
6366 #if SIZEOF_LONG > SIZEOF_INT 6367 if (len > INT_MAX) {
6380 if (!
NIL_P(execarg_obj)) {
6389 port =
pipe_open(execarg_obj, modestr, fmode, &convconfig);
6409 VALUE *fname_p,
int *oflags_p,
int *fmode_p,
6412 VALUE opt, fname, vmode, vperm;
6416 argc =
rb_scan_args(argc, argv,
"12:", &fname, &vmode, &vperm, &opt);
6505 VALUE fname, vmode, vperm;
6510 rb_scan_args(argc, argv,
"12", &fname, &vmode, &vperm);
6521 if (
NIL_P(vperm)) perm = 0666;
6647 int redirect =
FALSE;
6655 VALUE tmp = argv[0];
6704 oflags, fmode, convconfig, perm);
6729 if (fptr == orig)
return io;
6735 "%s can't change access mode from \"%s\" to \"%s\"",
6762 #
if defined (__CYGWIN__) || !defined(HAVE_WORKING_FORK)
6837 VALUE fname, nmode, opt;
6841 if (
rb_scan_args(argc, argv,
"11:", &fname, &nmode, &opt) == 1) {
6850 fptr =
RFILE(file)->fptr;
6862 (fptr->
mode & FMODE_READWRITE)) {
6864 "%s can't change access mode from \"%s\" to \"%s\"",
6869 fptr->
encs = convconfig;
6875 fptr->
pathv = fname;
6886 fptr->
rbuf.off = fptr->
rbuf.len = 0;
6903 else if (fptr->
stdio_file == stdout && isatty(fptr->
fd)) {
6945 #if defined (__CYGWIN__) || !defined(HAVE_WORKING_FORK) 6960 if (io != write_io) {
7001 if (argc == 0)
return Qnil;
7051 for (i=0; i<
argc; i++) {
7157 if (len == 0)
return 0;
7159 return ptr[len - 1] == c;
7161 return rb_enc_ascget(ptr + ((len - 1) / n) * n, ptr + len, &n, enc) == c;
7222 for (i=0; i<
argc; i++) {
7289 for (i=0; i<
argc; i++) {
7295 else if (argc > 1) {
7376 if (fwrite(mesg,
sizeof(
char), (
size_t)len, stderr) < (
size_t)len) {
7399 if (isatty(
fileno(stderr))) {
7403 if (fwrite(
RSTRING_PTR(mesg),
sizeof(
char), len, stderr) <
len) {
7457 if (path && strcmp(path,
"-")) klass =
rb_cFile;
7469 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE 7470 fptr->
encs.
ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
7534 if (
RFILE(obj)->fptr) {
7537 RFILE(obj)->fptr = 0;
7540 RFILE(obj)->fptr = fp;
7699 int fd,
fmode, oflags = O_RDONLY;
7702 #if defined(HAVE_FCNTL) && defined(F_GETFL) 7709 argc =
rb_scan_args(argc, argv,
"11:", &fnum, &vmode, &opt);
7716 #if defined(HAVE_FCNTL) && defined(F_GETFL) 7717 oflags =
fcntl(fd, F_GETFL);
7723 #if defined(HAVE_FCNTL) && defined(F_GETFL) 7739 fp->
encs = convconfig;
7744 else if (
fileno(stdout) == fd)
7746 else if (
fileno(stderr) == fd)
7777 if (
RFILE(io)->fptr) {
7780 if (0 < argc && argc < 3) {
7861 if (!
RTEST(autoclose))
7871 struct argf *p = ptr;
7881 struct argf *p = ptr;
7889 const struct argf *p = ptr;
7890 size_t size =
sizeof(*p);
7998 #define next_argv() argf_next_argv(argf) 7999 #define ARGF_GENERIC_INPUT_P() \ 8000 (ARGF.current_file == rb_stdin && !RB_TYPE_P(ARGF.current_file, T_FILE)) 8001 #define ARGF_FORWARD(argc, argv) do {\ 8002 if (ARGF_GENERIC_INPUT_P())\ 8003 return argf_forward((argc), (argv), argf);\ 8005 #define NEXT_ARGF_FORWARD(argc, argv) do {\ 8006 if (!next_argv()) return Qnil;\ 8007 ARGF_FORWARD((argc), (argv));\ 8027 int stdout_binmode = 0;
8036 if (
ARGF.init_p == 0) {
8054 if (
ARGF.next_p == 1) {
8065 rb_warn(
"Can't do inplace edit for stdio; skipping");
8075 #ifndef NO_SAFE_RENAME 8086 if (*
ARGF.inplace) {
8090 #ifdef NO_SAFE_RENAME 8109 #ifdef NO_SAFE_RENAME 8110 rb_fatal(
"Can't do inplace edit without backup");
8112 if (unlink(fn) < 0) {
8120 fw =
rb_sysopen(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666);
8121 #ifndef NO_SAFE_RENAME 8126 chmod(fn, st.st_mode);
8128 if (st.st_uid!=st2.st_uid || st.st_gid!=st2.st_gid) {
8131 err = fchown(fw, st.st_uid, st.st_gid);
8133 err =
chown(fn, st.st_uid, st.st_gid);
8135 if (err &&
getuid() == 0 && st2.st_uid == 0) {
8151 if (!
ARGF.binmode) {
8155 if (!
NIL_P(write_io)) {
8161 if (
ARGF.encs.enc) {
8167 if (!
ARGF.binmode) {
8169 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE 8170 fptr->
encs.
ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
8181 else if (
ARGF.next_p == -1) {
8185 rb_warn(
"Can't do inplace edit for stdio");
8189 if (
ARGF.init_p == -1)
ARGF.init_p = 1;
8236 ARGF.last_lineno =
ARGF.lineno = n;
8486 #ifdef HAVE_SYS_SELECT_H 8487 #include <sys/select.h> 8510 if (max < fptr->fd) max = fptr->
fd;
8521 if (!
NIL_P(write)) {
8527 if (max < fptr->fd) max = fptr->
fd;
8534 if (!
NIL_P(except)) {
8541 if (max < fptr->fd) max = fptr->
fd;
8542 if (io != write_io) {
8545 if (max < fptr->fd) max = fptr->
fd;
8560 if (!pending && n == 0)
return Qnil;
8603 else if (io != write_io) {
8643 #ifdef HAVE_POSIX_FADVISE 8644 struct io_advise_struct {
8652 io_advise_internal(
void *arg)
8654 struct io_advise_struct *ptr = arg;
8655 return posix_fadvise(ptr->fd, ptr->offset, ptr->len, ptr->advice);
8661 #ifdef POSIX_FADV_NORMAL 8663 return INT2NUM(POSIX_FADV_NORMAL);
8666 #ifdef POSIX_FADV_RANDOM 8668 return INT2NUM(POSIX_FADV_RANDOM);
8671 #ifdef POSIX_FADV_SEQUENTIAL 8673 return INT2NUM(POSIX_FADV_SEQUENTIAL);
8676 #ifdef POSIX_FADV_WILLNEED 8678 return INT2NUM(POSIX_FADV_WILLNEED);
8681 #ifdef POSIX_FADV_DONTNEED 8683 return INT2NUM(POSIX_FADV_DONTNEED);
8686 #ifdef POSIX_FADV_NOREUSE 8688 return INT2NUM(POSIX_FADV_NOREUSE);
8698 struct io_advise_struct ias;
8701 num_adv = io_advise_sym_to_const(advice);
8711 ias.advice =
NUM2INT(num_adv);
8712 ias.offset = offset;
8716 if (rv && rv != ENOSYS) {
8720 "(%"PRI_OFFT_PREFIX
"d, " 8721 "%"PRI_OFFT_PREFIX
"d, " 8723 fptr->
pathv, offset, len, advice);
8797 rb_scan_args(argc, argv,
"12", &advice, &offset, &len);
8806 #ifdef HAVE_POSIX_FADVISE 8807 return do_io_advise(fptr, advice, off, l);
8809 ((void)off, (
void)l);
8964 if (
NIL_P(timeout)) {
8978 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) 8980 # define NUM2IOCTLREQ(num) NUM2ULONG(num) 8983 # define NUM2IOCTLREQ(num) NUM2INT(num) 8994 nogvl_ioctl(
void *ptr)
8998 return (
VALUE)
ioctl(arg->fd, arg->cmd, arg->narg);
9017 #define DEFULT_IOCTL_NARG_LEN (256) 9019 #if defined(__linux__) && defined(_IOC_SIZE) 9025 if ((cmd & 0xFFFF0000) == 0) {
9030 len = _IOC_SIZE(cmd);
9047 #define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK) 9051 len = IOCPARM_LEN(cmd);
9052 #elif defined(__linux__) && defined(_IOC_SIZE) 9053 len = linux_iocparm_len(cmd);
9064 typedef long fcntl_arg_t;
9067 typedef int fcntl_arg_t;
9070 #if defined __native_client__ && !defined __GLIBC__ 9086 len =
sizeof(fcntl_arg_t);
9094 #ifdef F_DUPFD_CLOEXEC 9096 len =
sizeof(fcntl_arg_t);
9106 len =
sizeof(fcntl_arg_t);
9116 len =
sizeof(fcntl_arg_t);
9126 len =
sizeof(fcntl_arg_t);
9131 len =
sizeof(
struct f_owner_ex);
9136 len =
sizeof(
struct f_owner_ex);
9141 len =
sizeof(
struct flock);
9146 len =
sizeof(
struct flock);
9151 len =
sizeof(
struct flock);
9171 len =
sizeof(fcntl_arg_t);
9181 len =
sizeof(fcntl_arg_t);
9186 len =
sizeof(fcntl_arg_t);
9217 else if (arg ==
Qtrue) {
9265 retval = do_ioctl(fptr->
fd, cmd, narg);
9271 if (ptr[slen-1] != 17)
9297 return rb_ioctl(io, req, arg);
9300 #define rb_io_ioctl rb_f_notimplement 9311 nogvl_fcntl(
void *ptr)
9313 struct fcntl_arg *arg = ptr;
9315 #if defined(F_DUPFD) 9319 return (
VALUE)
fcntl(arg->fd, arg->cmd, arg->narg);
9323 do_fcntl(
int fd,
int cmd,
long narg)
9326 struct fcntl_arg arg;
9333 #if defined(F_DUPFD) 9334 if (retval != -1 && cmd ==
F_DUPFD) {
9352 retval = do_fcntl(fptr->
fd, cmd, narg);
9358 if (ptr[slen-1] != 17)
9385 return rb_fcntl(io, req, arg);
9388 #define rb_io_fcntl rb_f_notimplement 9391 #if defined(HAVE_SYSCALL) || defined(HAVE___SYSCALL) 9430 #if SIZEOF_VOIDP == 8 && defined(HAVE___SYSCALL) && SIZEOF_INT != 8 9431 # define SYSCALL __syscall 9432 # define NUM2SYSCALLID(x) NUM2LONG(x) 9433 # define RETVAL2NUM(x) LONG2NUM(x) 9434 # if SIZEOF_LONG == 8 9435 long num, retval = -1;
9436 # elif SIZEOF_LONG_LONG == 8 9437 long long num, retval = -1;
9439 # error ---->> it is asserted that __syscall takes the first argument and returns retval in 64bit signed integer. <<---- 9441 #elif defined(__linux__) 9442 # define SYSCALL syscall 9443 # define NUM2SYSCALLID(x) NUM2LONG(x) 9444 # define RETVAL2NUM(x) LONG2NUM(x) 9452 long num, retval = -1;
9454 # define SYSCALL syscall 9455 # define NUM2SYSCALLID(x) NUM2INT(x) 9456 # define RETVAL2NUM(x) INT2NUM(x) 9457 int num, retval = -1;
9462 rb_warning(
"We plan to remove a syscall function at future release. DL(Fiddle) provides safer alternative.");
9469 num = NUM2SYSCALLID(argv[0]); ++
argv;
9470 for (i = argc - 1; i--; ) {
9485 retval = SYSCALL(num);
9488 retval = SYSCALL(num, arg[0]);
9491 retval = SYSCALL(num, arg[0],arg[1]);
9494 retval = SYSCALL(num, arg[0],arg[1],arg[2]);
9497 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3]);
9500 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4]);
9503 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5]);
9506 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6]);
9512 return RETVAL2NUM(retval);
9514 #undef NUM2SYSCALLID 9518 #define rb_f_syscall rb_f_notimplement 9683 int pipes[2], state;
9691 argc =
rb_scan_args(argc, argv,
"02:", &v1, &v2, &opt);
9729 #if DEFAULT_TEXTMODE 9734 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32) 9741 #if DEFAULT_TEXTMODE 9787 #if SIZEOF_LONG > SIZEOF_INT 9845 int orig_argc =
argc;
9970 if (!
NIL_P(offset)) {
10020 arg.
argc = (argc > 1) ? 1 : 0;
10021 if (!
NIL_P(offset)) {
10056 int mode = O_WRONLY|O_CREAT;
10060 if (
NIL_P(offset)) mode |= O_TRUNC;
10070 if (!
NIL_P(offset)) {
10191 #if defined(ERESTART) 10206 #if defined(HAVE_POLL) && defined(__linux__) 10207 # define USE_POLL 1 10208 # define IOWAIT_SYSCALL "poll" 10210 # define IOWAIT_SYSCALL "select" 10211 # define USE_POLL 0 10216 nogvl_wait_for_single_fd(
int fd,
short events)
10221 fds.events = events;
10223 return poll(&fds, 1, -1);
10236 ret = nogvl_wait_for_single_fd(stp->
src_fd, POLLIN);
10284 ret = nogvl_wait_for_single_fd(stp->
dst_fd, POLLOUT);
10300 #ifdef HAVE_SENDFILE 10303 # define USE_SENDFILE 10305 # ifdef HAVE_SYS_SENDFILE_H 10306 # include <sys/sendfile.h> 10312 return sendfile(out_fd, in_fd, offset, (
size_t)count);
10315 # elif 0 || defined(__APPLE__) 10319 # define USE_SENDFILE 10328 r = sendfile(in_fd, out_fd, pos, &count,
NULL, 0);
10331 r = sendfile(in_fd, out_fd, pos, (
size_t)count,
NULL, &sbytes, 0);
10333 if (r != 0 && sbytes == 0)
return -1;
10340 return (ssize_t)sbytes;
10347 #ifdef USE_SENDFILE 10351 struct stat src_stat, dst_stat;
10365 if (!
S_ISREG(src_stat.st_mode))
10375 if ((dst_stat.st_mode & S_IFMT) != S_IFSOCK)
10380 use_pread = src_offset != (
off_t)-1;
10383 if (copy_length == (
off_t)-1) {
10385 copy_length = src_stat.st_size - src_offset;
10395 copy_length = src_stat.st_size - cur;
10400 # if SIZEOF_OFF_T > SIZEOF_SIZE_T 10404 ss = (ssize_t)copy_length;
10407 ss = simple_sendfile(stp->
dst_fd, stp->
src_fd, &src_offset, ss);
10415 if (0 < copy_length) {
10416 goto retry_sendfile;
10421 goto retry_sendfile;
10429 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN 10445 goto retry_sendfile;
10447 stp->
syserr =
"sendfile";
10461 return read(fd, buf, count);
10469 if (offset == (
off_t)-1) {
10474 ss = pread(stp->
src_fd, buf, len, offset);
10488 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN 10500 stp->
syserr = offset == (
off_t)-1 ?
"read" :
"pread";
10513 ss = write(stp->
dst_fd, buf+off, len);
10546 use_eof = copy_length == (
off_t)-1;
10548 use_pread = src_offset != (
off_t)-1;
10559 src_offset = (
off_t)-1;
10563 while (use_eof || 0 < copy_length) {
10564 if (!use_eof && copy_length < (
off_t)
sizeof(
buf)) {
10565 len = (size_t)copy_length;
10594 #ifdef USE_SENDFILE 10598 #ifdef USE_SENDFILE 10599 ret = nogvl_copy_stream_sendfile(stp);
10606 #ifdef USE_SENDFILE 10616 const int buflen = 16*1024;
10623 if (stp->
src_fd == -1) {
10638 l = buflen < rest ? buflen : (long)rest;
10640 if (stp->
src_fd == -1) {
10655 if (off != (
off_t)-1)
10660 stp->
total += numwrote;
10687 rb_io_t *src_fptr = 0, *dst_fptr = 0;
10689 const int common_oflags = 0
10699 if (src_io ==
argf ||
10707 if (!
NIL_P(tmp_io)) {
10714 args[1] =
INT2NUM(O_RDONLY|common_oflags);
10721 src_fd = src_fptr->
fd;
10725 if (dst_io ==
argf ||
10733 if (!
NIL_P(tmp_io)) {
10740 args[1] =
INT2NUM(O_WRONLY|O_CREAT|O_TRUNC|common_oflags);
10752 dst_fd = dst_fptr->fd;
10764 size_t len = src_fptr->
rbuf.len;
10783 if (dst_fptr &&
io_fflush(dst_fptr) < 0) {
10790 if (src_fd == -1 || dst_fd == -1) {
10857 rb_scan_args(argc, argv,
"22", &src, &dst, &length, &src_offset);
10867 if (
NIL_P(src_offset))
10950 argc =
rb_scan_args(argc, argv,
"11:", &v1, &v2, &opt);
10969 return arg ==
argf;
11146 old_lineno =
RFILE(
ARGF.current_file)->fptr->lineno;
11149 ARGF.last_lineno =
ARGF.lineno -= old_lineno;
11191 return ARGF.current_file;
11278 VALUE tmp, str, length;
11282 if (!
NIL_P(length)) {
11301 if (
NIL_P(str)) str = tmp;
11304 if (
ARGF.next_p != -1) {
11310 else if (argc >= 1) {
11388 VALUE tmp, str, length;
11414 if (
ARGF.next_p == -1) {
11585 #define FOREACH_ARGF() while (next_argv()) 11590 const VALUE current =
ARGF.current_file;
11592 if (
ARGF.init_p == -1 || current !=
ARGF.current_file) {
11670 rb_warn(
"ARGF#lines is deprecated; use #each_line instead");
11717 rb_warn(
"ARGF#bytes is deprecated; use #each_byte instead");
11756 rb_warn(
"ARGF#chars is deprecated; use #each_char instead");
11795 rb_warn(
"ARGF#codepoints is deprecated; use #each_codepoint instead");
11827 return ARGF.filename;
11858 return ARGF.current_file;
11918 if (
ARGF.init_p &&
ARGF.next_p == 0) {
11947 if (
ARGF.next_p != -1) {
12050 return ARGF.inplace;
12137 #if EAGAIN != EWOULDBLOCK 12154 #if EAGAIN != EWOULDBLOCK 12167 rb_bug(
"invalid read/write type passed to rb_readwrite_sys_fail: %d", writable);
12330 #define rb_intern(str) rb_intern_const(str) 12334 #include <sys/cygwin.h> 12335 static struct __cygwin_perfile pf[] =
12343 cygwin_internal(CW_PERFILE, pf);
12383 #if EAGAIN == EWOULDBLOCK 12649 #if defined (_WIN32) || defined(__CYGWIN__) 12650 atexit(pipe_atexit);
static VALUE argf_bytes(VALUE argf)
#define STRNCASECMP(s1, s2, n)
void rb_define_global_const(const char *, VALUE)
struct timeval rb_time_interval(VALUE num)
void rb_define_readonly_variable(const char *, const VALUE *)
unsigned long ruby_strtoul(const char *str, char **endptr, int base)
static rb_io_t * io_close_fptr(VALUE io)
VALUE rb_econv_open_exc(const char *senc, const char *denc, int ecflags)
static VALUE io_read_nonblock(VALUE io, VALUE length, VALUE str, VALUE ex)
static void make_readconv(rb_io_t *fptr, int size)
void rb_execarg_setenv(VALUE execarg_obj, VALUE env)
static VALUE rb_io_rewind(VALUE io)
void rb_thread_schedule(void)
const char * rb_econv_asciicompat_encoding(const char *encname)
static VALUE rb_io_close_read(VALUE io)
static void argf_close(VALUE argf)
static VALUE rb_obj_display(int argc, VALUE *argv, VALUE self)
static int nogvl_copy_stream_wait_write(struct copy_stream_struct *stp)
VALUE rb_io_getbyte(VALUE io)
static long fcntl_narg_len(int cmd)
static VALUE rb_io_set_lineno(VALUE io, VALUE lineno)
int rb_io_wait_writable(int f)
static ID id_set_encoding
#define MBCLEN_CHARFOUND_P(ret)
static VALUE pipe_open(VALUE execarg_obj, const char *modestr, int fmode, const convconfig_t *convconfig)
void rb_thread_atfork(void)
#define ECONV_NEWLINE_DECORATOR_WRITE_MASK
static VALUE rb_io_set_sync(VALUE io, VALUE sync)
VALUE rb_ary_entry(VALUE ary, long offset)
#define MBCLEN_CHARFOUND_LEN(ret)
void rb_bug(const char *fmt,...)
#define RUBY_TYPED_FREE_IMMEDIATELY
static VALUE rb_io_internal_encoding(VALUE)
static VALUE rb_io_s_readlines(int argc, VALUE *argv, VALUE io)
long rb_str_coderange_scan_restartable(const char *, const char *, rb_encoding *, int *)
static VALUE rb_io_closed(VALUE io)
static void check_getline_args(VALUE *rsp, long *limit, VALUE io)
size_t strlen(const char *)
static VALUE io_enc_str(VALUE str, rb_io_t *fptr)
void rb_readwrite_sys_fail(enum rb_io_wait_readwrite writable, const char *mesg)
void rb_io_check_writable(rb_io_t *fptr)
static VALUE argf_getpartial(int argc, VALUE *argv, VALUE argf, VALUE opts, int nonblock)
static VALUE sym_autoclose
static long setup_narg(ioctl_req_t cmd, VALUE *argp, int io_p)
static VALUE sym_encoding
static VALUE argf_set_pos(VALUE argf, VALUE offset)
static const char closed_stream[]
static VALUE rb_io_codepoints(VALUE io)
int rb_io_modestr_fmode(const char *modestr)
static VALUE argf_set_lineno(VALUE argf, VALUE val)
void rb_syserr_fail(int e, const char *mesg)
static VALUE argf_inplace_mode_get(VALUE argf)
VALUE rb_file_open_str(VALUE fname, const char *modestr)
static VALUE rb_f_putc(VALUE recv, VALUE ch)
void rb_define_virtual_variable(const char *, VALUE(*)(ANYARGS), void(*)(ANYARGS))
static VALUE argf_readpartial(int argc, VALUE *argv, VALUE argf)
VALUE rb_hash_dup(VALUE hash)
static VALUE io_call_close(VALUE io)
static int max(int a, int b)
#define ENCINDEX_UTF_16LE
static int io_fflush(rb_io_t *)
void rb_str_tmp_frozen_release(VALUE str, VALUE tmp)
VALUE rb_io_eof(VALUE io)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
char * rb_execarg_commandline(const struct rb_execarg *eargp, VALUE *prog)
int rb_cloexec_open(const char *pathname, int flags, mode_t mode)
static const char * rb_io_fmode_modestr(int fmode)
static void argf_init(struct argf *p, VALUE v)
int rb_w32_set_nonblock(int)
static VALUE argf_inplace_mode_set(VALUE argf, VALUE val)
VALUE rb_f_sprintf(int, const VALUE *)
static void must_respond_to(ID mid, VALUE val, ID id)
#define rb_usascii_str_new2
static VALUE io_s_write(int argc, VALUE *argv, int binary)
void rb_io_set_nonblock(rb_io_t *fptr)
static VALUE select_call(VALUE arg)
static VALUE rb_io_open_generic(VALUE, int, int, const convconfig_t *, mode_t)
VALUE rb_str_cat(VALUE, const char *, long)
static VALUE argf_readbyte(VALUE argf)
#define ARGF_FORWARD(argc, argv)
static VALUE argf_gets(int, VALUE *, VALUE)
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
VALUE rb_io_binmode(VALUE io)
static void argf_mark(void *ptr)
static VALUE io_puts_ary(VALUE ary, VALUE out, int recur)
static VALUE rb_io_binmode_p(VALUE io)
int rb_execarg_run_options(const struct rb_execarg *e, struct rb_execarg *s, char *errmsg, size_t errmsg_buflen)
#define OBJ_INIT_COPY(obj, orig)
#define ENC_CODERANGE_SET(obj, cr)
#define READ_DATA_PENDING_COUNT(fptr)
VALUE rb_ary_shift(VALUE ary)
static VALUE rb_eEAGAINWaitWritable
int rb_exec_async_signal_safe(const struct rb_execarg *e, char *errmsg, size_t errmsg_buflen)
#define ECONV_ERROR_HANDLER_MASK
void * rb_thread_call_without_gvl2(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2)
rb_encoding * rb_to_encoding(VALUE enc)
void rb_fd_fix_cloexec(int fd)
static int is_popen_fork(VALUE prog)
void rb_econv_close(rb_econv_t *ec)
static VALUE io_flush_buffer_async(VALUE arg)
static VALUE io_binwrite_string(VALUE arg)
VALUE rb_str_unlocktmp(VALUE)
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
static void io_encoding_set(rb_io_t *, VALUE, VALUE, VALUE)
static VALUE rb_io_syswrite(VALUE io, VALUE str)
VALUE rb_enc_from_encoding(rb_encoding *encoding)
static rb_encoding * find_encoding(VALUE v)
ID rb_frame_this_func(void)
static VALUE argf_external_encoding(VALUE argf)
SOCKET rb_w32_get_osfhandle(int)
static VALUE argf_each_line(int argc, VALUE *argv, VALUE argf)
static VALUE rb_io_close_write(VALUE io)
static int io_check_tty(rb_io_t *fptr)
rb_encoding * rb_default_internal_encoding(void)
static VALUE argf_filename(VALUE argf)
VALUE rb_ary_push(VALUE ary, VALUE item)
static void fptr_finalize(rb_io_t *fptr, int noraise)
void rb_close_before_exec(int lowfd, int maxhint, VALUE noclose_fds)
static VALUE opt_i_get(ID id, VALUE *var)
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
VALUE rb_ary_tmp_new(long capa)
static VALUE argf_argv(VALUE argf)
static int io_encname_bom_p(const char *name, long len)
static VALUE rb_io_seek(VALUE io, VALUE offset, int whence)
int rb_thread_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *)
void ruby_sized_xfree(void *x, size_t size)
rb_pid_t rb_fork_ruby(int *status)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
#define ENCINDEX_UTF_16BE
VALUE rb_str_locktmp_ensure(VALUE str, VALUE(*func)(VALUE), VALUE arg)
void rb_str_set_len(VALUE, long)
int writeconv_pre_ecflags
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
#define RBASIC_SET_CLASS(obj, cls)
static VALUE rb_io_readchar(VALUE io)
int rb_enc_str_coderange(VALUE)
static VALUE argf_write(VALUE argf, VALUE str)
static int rb_sysopen_internal(struct sysopen_struct *data)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
int rb_cloexec_dup2(int oldfd, int newfd)
void rb_raise(VALUE exc, const char *fmt,...)
static VALUE rb_io_sysseek(int argc, VALUE *argv, VALUE io)
#define SET_BINARY_MODE_WITH_SEEK_CUR(fptr)
int writeconv_initialized
#define RSTRING_GETMEM(str, ptrvar, lenvar)
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
VALUE rb_ary_clear(VALUE ary)
static VALUE pipe_close(VALUE io)
static void pipe_add_fptr(rb_io_t *fptr)
VALUE rb_convert_type(VALUE, int, const char *, const char *)
static VALUE argf_binmode_p(VALUE argf)
VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE)
#define NEED_WRITECONV(fptr)
static VALUE rb_file_initialize(int argc, VALUE *argv, VALUE io)
static VALUE io_s_readlines(struct getline_arg *arg)
static VALUE argf_write_io(VALUE argf)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
int rb_io_modestr_oflags(const char *modestr)
static int ruby_dup(int orig)
VALUE rb_execarg_new(int argc, const VALUE *argv, int accept_shell)
#define ENCODING_MAXNAMELEN
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
static void unsupported_encoding(const char *name, rb_encoding *enc)
VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd)
void rb_mutex_allow_trap(VALUE self, int val)
void rb_include_module(VALUE klass, VALUE module)
#define MORE_CHAR_FINISHED
VALUE rb_block_call(VALUE, ID, int, const VALUE *, rb_block_call_func_t, VALUE)
int rb_notify_fd_close(int fd)
void rb_gc_mark(VALUE ptr)
VALUE rb_hash_lookup(VALUE hash, VALUE key)
static VALUE more_char(rb_io_t *fptr)
static VALUE rb_io_s_sysopen(int argc, VALUE *argv)
static VALUE argf_lineno(VALUE argf)
static void free_io_buffer(rb_io_buffer_t *buf)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
static VALUE ignore_closed_stream(VALUE io, VALUE exc)
static VALUE internal_write_func(void *ptr)
void rb_io_check_initialized(rb_io_t *fptr)
static VALUE rb_eEINPROGRESSWaitWritable
static VALUE rb_io_each_byte(VALUE io)
void rb_gc_force_recycle(VALUE obj)
VALUE writeconv_pre_ecopts
static void open_key_args(int argc, VALUE *argv, VALUE opt, struct foreach_arg *arg)
static VALUE argf_readchar(VALUE argf)
void rb_update_max_fd(int fd)
static VALUE rb_io_external_encoding(VALUE io)
static VALUE rb_f_readlines(int argc, VALUE *argv, VALUE recv)
static void io_set_read_length(VALUE str, long n)
static int argf_next_argv(VALUE argf)
VALUE rb_check_to_integer(VALUE, const char *)
static const rb_data_type_t argf_type
static long io_fwrite(VALUE str, rb_io_t *fptr, int nosync)
static VALUE rb_f_open(int argc, VALUE *argv)
static VALUE argf_each_codepoint(VALUE argf)
static int rb_fix_detect_o_cloexec(int fd)
RUBY_FUNC_EXPORTED size_t rb_io_memsize(const rb_io_t *fptr)
#define GetOpenFile(obj, fp)
static ssize_t rb_write_internal2(int fd, const void *buf, size_t count)
static VALUE do_writeconv(VALUE str, rb_io_t *fptr, int *converted)
static void validate_enc_binmode(int *fmode_p, int ecflags, rb_encoding *enc, rb_encoding *enc2)
static VALUE rb_f_p_internal(VALUE arg)
VALUE rb_io_ascii8bit_binmode(VALUE io)
static VALUE rb_io_tell(VALUE io)
#define ENC_CODERANGE_7BIT
static VALUE argf_seek_m(int argc, VALUE *argv, VALUE argf)
static void opt_i_set(VALUE val, ID id, VALUE *var)
RUBY_EXTERN void * memmove(void *, const void *, size_t)
int rb_gc_for_fd(int err)
static VALUE read_all(rb_io_t *fptr, long siz, VALUE str)
int rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p)
static void * exec_interrupts(void *arg)
VALUE rb_io_write(VALUE io, VALUE str)
VALUE rb_str_buf_cat(VALUE, const char *, long)
static const char utf_prefix[]
rb_io_t * rb_io_make_open_file(VALUE obj)
static VALUE rb_io_set_autoclose(VALUE io, VALUE autoclose)
#define NEWOBJ_OF(obj, type, klass, flags)
#define rb_fd_isset(n, f)
static ssize_t maygvl_read(int has_gvl, int fd, void *buf, size_t count)
static rb_encoding * io_read_encoding(rb_io_t *fptr)
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
static VALUE rb_io_s_popen(int argc, VALUE *argv, VALUE klass)
VALUE rb_io_gets_internal(VALUE io)
static VALUE rb_io_lines(int argc, VALUE *argv, VALUE io)
static VALUE rb_io_getline_fast(rb_io_t *fptr, rb_encoding *enc, int chomp)
void rb_exc_raise(VALUE mesg)
#define SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(enc2, ecflags)
#define rb_io_set_close_on_exec
VALUE rb_io_close(VALUE io)
VALUE rb_io_flush_raw(VALUE io, int sync)
static VALUE rb_io_sysread(int argc, VALUE *argv, VALUE io)
static void io_ungetbyte(VALUE str, rb_io_t *fptr)
static void argf_block_call(ID mid, int argc, VALUE *argv, VALUE argf)
#define RB_TYPE_P(obj, type)
static VALUE rb_file_open_internal(VALUE io, VALUE filename, const char *modestr)
static int str_end_with_asciichar(VALUE str, int c)
static VALUE argf_binmode_m(VALUE argf)
int rb_thread_fd_writable(int)
VALUE rb_econv_make_exception(rb_econv_t *ec)
#define MEMZERO(p, type, n)
void rb_econv_check_error(rb_econv_t *ec)
VALUE rb_lastline_get(void)
int rb_to_encoding_index(VALUE enc)
rb_encoding * rb_default_external_encoding(void)
void rb_str_setter(VALUE, ID, VALUE *)
void rb_maygvl_fd_fix_cloexec(int fd)
static VALUE copy_stream_fallback_body(VALUE arg)
void rb_thread_sleep(int)
struct rb_execarg * rb_execarg_get(VALUE execarg_obj)
#define ECONV_NEWLINE_DECORATOR_READ_MASK
static VALUE sym_wait_readable
VALUE rb_class_name(VALUE)
static VALUE argf_lines(int argc, VALUE *argv, VALUE argf)
VALUE rb_str_chomp_string(VALUE str, VALUE chomp)
static void * nogvl_close(void *ptr)
int rb_block_given_p(void)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
void rb_io_unbuffered(rb_io_t *fptr)
void rb_write_error2(const char *mesg, long len)
static VALUE argf_internal_encoding(VALUE argf)
VALUE rb_str_encode_ospath(VALUE path)
VALUE rb_str_substr(VALUE, long, long)
static VALUE io_readpartial(int argc, VALUE *argv, VALUE io)
static VALUE argf_getbyte(VALUE argf)
static void stdout_setter(VALUE val, ID id, VALUE *variable)
RUBY_EXTERN VALUE rb_cObject
static VALUE rb_f_backquote(VALUE obj, VALUE str)
static void rb_io_buffer_init(rb_io_buffer_t *buf)
#define PREP_STDIO_NAME(f)
static struct pipe_list * pipe_list
static VALUE argf_block_call_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, argf))
static VALUE argf_readlines(int, VALUE *, VALUE)
static VALUE argf_getline(int argc, VALUE *argv, VALUE argf)
#define FMODE_SETENC_BY_BOM
static VALUE rb_eEWOULDBLOCKWaitWritable
#define MBCLEN_NEEDMORE_P(ret)
static VALUE io_nonblock_eof(VALUE opts)
static VALUE rb_io_s_binread(int argc, VALUE *argv, VALUE io)
char * ruby_strdup(const char *)
static VALUE io_flush_buffer_sync(void *arg)
FILE * rb_io_stdio_file(rb_io_t *fptr)
int rb_io_oflags_fmode(int oflags)
static int io_strip_bom(VALUE io)
VALUE rb_str_cat2(VALUE, const char *)
VALUE rb_obj_as_string(VALUE)
#define ECONV_STATEFUL_DECORATOR_MASK
static struct StringIO * writable(VALUE strio)
static ssize_t maygvl_copy_stream_read(int has_gvl, struct copy_stream_struct *stp, char *buf, size_t len, off_t offset)
rb_econv_t * rb_econv_open_opts(const char *source_encoding, const char *destination_encoding, int ecflags, VALUE ecopts)
VALUE rb_io_get_write_io(VALUE io)
VALUE rb_io_print(int argc, const VALUE *argv, VALUE out)
VALUE rb_execarg_extract_options(VALUE execarg_obj, VALUE opthash)
static int swallow(rb_io_t *fptr, int term)
static VALUE argf_set_encoding(int argc, VALUE *argv, VALUE argf)
#define ARGF_GENERIC_INPUT_P()
#define ECONV_PARTIAL_INPUT
VALUE rb_io_ungetbyte(VALUE io, VALUE b)
#define ECONV_AFTER_OUTPUT
RUBY_EXTERN VALUE rb_mKernel
VALUE rb_thread_current(void)
int rb_cloexec_fcntl_dupfd(int fd, int minfd)
static void pipe_finalize(rb_io_t *fptr, int noraise)
static VALUE copy_stream_fallback(struct copy_stream_struct *stp)
VALUE rb_io_flush(VALUE io)
static VALUE sym_textmode
static VALUE finish_writeconv_sync(VALUE arg)
static VALUE io_write(VALUE io, VALUE str, int nosync)
static VALUE rb_f_puts(int argc, VALUE *argv, VALUE recv)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
static VALUE pipe_pair_close(VALUE rw)
const char * ruby_get_inplace_mode(void)
static int appendline(rb_io_t *fptr, int delim, VALUE *strp, long *lp)
int chown(const char *, int, int)
#define ECONV_DEFAULT_NEWLINE_DECORATOR
VALUE rb_mutex_synchronize(VALUE mutex, VALUE(*func)(VALUE arg), VALUE arg)
static VALUE rb_io_each_line(int argc, VALUE *argv, VALUE io)
#define MODE_BINARY(a, b)
rb_pid_t rb_fork_async_signal_safe(int *status, int(*chfunc)(void *, char *, size_t), void *charg, VALUE fds, char *errmsg, size_t errmsg_buflen)
void rb_define_const(VALUE, const char *, VALUE)
int rb_io_wait_readable(int f)
void rb_sys_fail_str(VALUE mesg)
static VALUE select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fdset_t *fds)
static VALUE io_write_nonblock(VALUE io, VALUE str, VALUE ex)
rb_atomic_t cnt[RUBY_NSIG]
static VALUE rb_io_each_char(VALUE io)
static VALUE rb_io_open_with_args(int argc, const VALUE *argv)
VALUE rb_io_check_io(VALUE io)
void rb_lastline_set(VALUE)
static VALUE argf_chars(VALUE argf)
static VALUE rb_io_getline(int argc, VALUE *argv, VALUE io)
#define MBCLEN_NEEDMORE_LEN(ret)
struct rb_io_t::rb_io_enc_t encs
static void * nogvl_fclose(void *ptr)
union rb_execarg::@139 invoke
#define NUM2IOCTLREQ(num)
#define READ_DATA_PENDING(fptr)
VALUE writeconv_asciicompat
static VALUE finish_writeconv(rb_io_t *fptr, int noalloc)
static VALUE rb_open_file(int argc, const VALUE *argv, VALUE io)
#define NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr)
void rb_gc_register_mark_object(VALUE obj)
static VALUE rb_io_gets_m(int argc, VALUE *argv, VALUE io)
VALUE rb_io_get_io(VALUE io)
#define RUBY_FUNC_EXPORTED
static VALUE argf_eof(VALUE argf)
#define ENC_CODERANGE_BROKEN
static VALUE rb_io_getline_0(VALUE rs, long limit, int chomp, rb_io_t *fptr)
static void io_setstrbuf(VALUE *str, long len)
VALUE rb_obj_alloc(VALUE)
static int io_flush_buffer(rb_io_t *fptr)
#define rb_enc_codepoint(p, e, enc)
#define rb_enc_mbminlen(enc)
VALUE rb_io_gets(VALUE io)
int rb_cloexec_dup(int oldfd)
static int no_exception_p(VALUE opts)
static VALUE rb_f_printf(int argc, VALUE *argv)
static void rscheck(const char *rsptr, long rslen, VALUE rs)
static int nogvl_copy_stream_write(struct copy_stream_struct *stp, char *buf, size_t len)
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
static VALUE argf_initialize(VALUE argf, VALUE argv)
void * rb_thread_call_without_gvl(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2)
#define ENC_CODERANGE_VALID
#define ATOMIC_CAS(var, oldval, newval)
static VALUE rb_io_seek_m(int argc, VALUE *argv, VALUE io)
#define ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(n)
VALUE rb_str_resize(VALUE, long)
static void io_set_encoding_by_bom(VALUE io)
static void advice_arg_check(VALUE advice)
rb_encoding * rb_find_encoding(VALUE enc)
int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc)
static VALUE argf_alloc(VALUE klass)
static void io_ascii8bit_binmode(rb_io_t *fptr)
#define NEXT_ARGF_FORWARD(argc, argv)
static VALUE prep_io(int fd, int fmode, VALUE klass, const char *path)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
int rb_cloexec_pipe(int fildes[2])
static VALUE rb_f_gets(int argc, VALUE *argv, VALUE recv)
void ruby_set_inplace_mode(const char *suffix)
#define RARRAY_CONST_PTR(a)
VALUE rb_io_puts(int argc, const VALUE *argv, VALUE out)
static VALUE copy_stream_body(VALUE arg)
static VALUE seek_before_access(VALUE argp)
static VALUE rb_io_set_pos(VALUE io, VALUE offset)
void rb_last_status_clear(void)
static rb_atomic_t max_file_descriptor
static VALUE rb_io_init_copy(VALUE dest, VALUE io)
VALUE rb_sprintf(const char *format,...)
static void nogvl_copy_stream_read_write(struct copy_stream_struct *stp)
static rb_encoding * io_input_encoding(rb_io_t *fptr)
void rb_execarg_parent_start(VALUE execarg_obj)
static VALUE io_close(VALUE io)
static int rb_sysopen(VALUE fname, int oflags, mode_t perm)
int rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc)
#define IO_RBUF_CAPA_FOR(fptr)
void rb_gvar_readonly_setter(VALUE v, ID id, void *d, struct rb_global_variable *g)
static VALUE argf_rewind(VALUE argf)
#define NEED_READCONV(fptr)
static VALUE rb_io_pid(VALUE io)
static VALUE rb_eEINPROGRESSWaitReadable
void rb_fatal(const char *fmt,...)
static VALUE io_s_read(struct foreach_arg *arg)
VALUE rb_eSystemCallError
static void * io_flush_buffer_sync2(void *arg)
static int maygvl_copy_stream_continue_p(int has_gvl, struct copy_stream_struct *stp)
void rb_last_status_set(int status, rb_pid_t pid)
static VALUE rb_io_readlines(int argc, VALUE *argv, VALUE io)
static VALUE rb_io_s_for_fd(int argc, VALUE *argv, VALUE klass)
static VALUE rb_f_select(int argc, VALUE *argv, VALUE obj)
static VALUE rb_io_chars(VALUE io)
#define MEMMOVE(p1, p2, type, n)
static VALUE rb_io_s_open(int argc, VALUE *argv, VALUE klass)
static void argf_lineno_setter(VALUE val, ID id, VALUE *var)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
static VALUE argf_read_nonblock(int argc, VALUE *argv, VALUE argf)
void rb_write_error_str(VALUE mesg)
void rb_str_modify_expand(VALUE, long)
static VALUE argf_to_io(VALUE argf)
void rb_thread_execute_interrupts(VALUE th)
VALUE rb_ivar_set(VALUE, ID, VALUE)
VALUE rb_check_hash_type(VALUE hash)
static void io_unread(rb_io_t *fptr)
unsigned char buf[MIME_BUF_SIZE]
VALUE rb_assoc_new(VALUE car, VALUE cdr)
void rb_thread_wait_fd(int)
rb_encoding * rb_usascii_encoding(void)
VALUE tied_io_for_writing
#define RUBY_METHOD_FUNC(func)
static VALUE rb_io_close_m(VALUE io)
static VALUE argf_lineno_getter(ID id, VALUE *var)
static ssize_t rb_write_internal(int fd, const void *buf, size_t count)
struct rb_execarg::@139::@141 cmd
static void rb_io_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash, int *oflags_p, int *fmode_p, convconfig_t *convconfig_p)
VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc)
VALUE rb_io_printf(int argc, const VALUE *argv, VALUE out)
void rb_readwrite_syserr_fail(enum rb_io_wait_readwrite writable, int n, const char *mesg)
size_t rb_econv_memsize(rb_econv_t *)
static VALUE argf_readline(int, VALUE *, VALUE)
static VALUE rb_io_s_binwrite(int argc, VALUE *argv, VALUE io)
static void extract_getline_args(int argc, VALUE *argv, struct getline_arg *args)
char * strchr(char *, char)
static VALUE prep_stdio(FILE *f, int fmode, VALUE klass, const char *path)
#define NEED_NEWLINE_DECORATOR_ON_WRITE(fptr)
int rb_utf8_encindex(void)
static void * internal_write_func2(void *ptr)
#define ECONV_NEWLINE_DECORATOR_MASK
int rb_wait_for_single_fd(int fd, int events, struct timeval *tv)
void rb_enc_warn(rb_encoding *enc, const char *fmt,...)
void rb_io_synchronized(rb_io_t *fptr)
VALUE rb_rescue2(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2,...)
static void extract_getline_opts(VALUE opts, struct getline_arg *args)
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
static VALUE rb_io_s_write(int argc, VALUE *argv, VALUE io)
static long io_bufread(char *ptr, long len, rb_io_t *fptr)
#define rb_enc_asciicompat(enc)
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
VALUE rb_str_new_cstr(const char *)
int memcmp(const void *s1, const void *s2, size_t len)
static VALUE rb_file_open_generic(VALUE io, VALUE filename, int oflags, int fmode, const convconfig_t *convconfig, mode_t perm)
static VALUE argf_read(int argc, VALUE *argv, VALUE argf)
static int maygvl_select(int has_gvl, int n, rb_fdset_t *rfds, rb_fdset_t *wfds, rb_fdset_t *efds, struct timeval *timeout)
static int maygvl_copy_stream_wait_read(int has_gvl, struct copy_stream_struct *stp)
static VALUE io_shift_cbuf(rb_io_t *fptr, int len, VALUE *strp)
VALUE rb_uninterruptible(VALUE(*b_proc)(ANYARGS), VALUE data)
void rb_sys_fail(const char *mesg)
static VALUE read_internal_call(VALUE arg)
static VALUE sym_willneed
static VALUE rb_io_autoclose_p(VALUE io)
static VALUE io_write_m(VALUE io, VALUE str)
void rb_jump_tag(int tag)
struct rb_io_buffer_t rb_io_buffer_t
static int global_argf_p(VALUE arg)
static VALUE rb_io_set_encoding(int argc, VALUE *argv, VALUE io)
int rb_reserved_fd_p(int fd)
void rb_define_hooked_variable(const char *, VALUE *, VALUE(*)(ANYARGS), void(*)(ANYARGS))
#define READ_DATA_BUFFERED(fptr)
#define rb_io_close_on_exec_p
int rb_respond_to(VALUE, ID)
static VALUE bufread_call(VALUE arg)
int rb_thread_to_be_killed(VALUE thread)
register unsigned int len
VALUE rb_define_module_under(VALUE outer, const char *name)
#define StringValueCStr(v)
static VALUE argf_tell(VALUE argf)
static VALUE argf_each_byte(VALUE argf)
static size_t argf_memsize(const void *ptr)
void rb_iter_break_value(VALUE val)
VALUE rb_check_to_int(VALUE)
int rb_econv_putbackable(rb_econv_t *ec)
static VALUE argf_codepoints(VALUE argf)
static VALUE argf_filename_getter(ID id, VALUE *var)
static VALUE rb_io_binmode_m(VALUE io)
void rb_str_modify(VALUE)
static VALUE rb_io_isatty(VALUE io)
#define ENCODING_GET(obj)
rb_encoding * rb_enc_get(VALUE obj)
static VALUE io_s_write0(struct write_arg *arg)
void rb_mod_sys_fail_str(VALUE mod, VALUE mesg)
void rb_insecure_operation(void)
static VALUE io_flush_buffer_async2(VALUE arg)
static VALUE rb_io_lineno(VALUE io)
static VALUE io_read(int argc, VALUE *argv, VALUE io)
static int rb_freopen(VALUE fname, const char *mode, FILE *fp)
VALUE rb_yield_values2(int n, const VALUE *argv)
VALUE rb_hash_lookup2(VALUE hash, VALUE key, VALUE def)
static VALUE io_new_instance(VALUE args)
static VALUE rb_io_putc(VALUE io, VALUE ch)
static VALUE rb_io_bytes(VALUE io)
#define MBCLEN_INVALID_P(ret)
#define RARRAY_AREF(a, i)
rb_econv_result_t rb_econv_convert(rb_econv_t *ec, const unsigned char **source_buffer_ptr, const unsigned char *source_buffer_end, unsigned char **destination_buffer_ptr, unsigned char *destination_buffer_end, int flags)
VALUE rb_check_convert_type(VALUE, int, const char *, const char *)
static long io_fread(VALUE str, long offset, long size, rb_io_t *fptr)
static int rb_io_fmode_oflags(int fmode)
static VALUE check_pipe_command(VALUE filename_or_command)
int rb_io_fptr_finalize(rb_io_t *fptr)
static VALUE rb_io_s_pipe(int argc, VALUE *argv, VALUE klass)
static VALUE io_readlines(const struct getline_arg *arg, VALUE io)
VALUE rb_io_fdopen(int fd, int oflags, const char *path)
VALUE rb_str_buf_cat_ascii(VALUE, const char *)
static VALUE rb_io_to_io(VALUE io)
static VALUE rb_io_inspect(VALUE obj)
static void rb_scan_open_args(int argc, const VALUE *argv, VALUE *fname_p, int *oflags_p, int *fmode_p, convconfig_t *convconfig_p, mode_t *perm_p)
static VALUE rb_io_s_try_convert(VALUE dummy, VALUE io)
VALUE rb_check_array_type(VALUE ary)
static void argf_block_call_line(ID mid, int argc, VALUE *argv, VALUE argf)
RUBY_SYMBOL_EXPORT_BEGIN void * rb_thread_call_with_gvl(void *(*func)(void *), void *data1)
static void clear_codeconv(rb_io_t *fptr)
VALUE rb_hash_aref(VALUE hash, VALUE key)
static void rb_io_fptr_cleanup(rb_io_t *fptr, int noraise)
void rb_error_arity(int argc, int min, int max)
#define rb_fd_select(n, rfds, wfds, efds, timeout)
VALUE rb_str_catf(VALUE str, const char *format,...)
VALUE rb_enumeratorize(VALUE obj, VALUE meth, int argc, const VALUE *argv)
void rb_syserr_fail_str(int e, VALUE mesg)
long rb_w32_write_console(uintptr_t, int)
static VALUE rb_eEAGAINWaitReadable
VALUE rb_check_string_type(VALUE)
#define is_socket(fd, path)
RUBY_EXTERN char * strerror(int)
static VALUE argf_each_char(VALUE argf)
static VALUE rb_io_advise(int argc, VALUE *argv, VALUE io)
#define ARGVSTR2ARGV(argv_str)
static VALUE rb_io_getc(VALUE io)
void rb_thread_check_ints(void)
VALUE rb_str_locktmp(VALUE)
static long io_binwrite(VALUE str, const char *ptr, long len, rb_io_t *fptr, int nosync)
static VALUE argf_closed(VALUE argf)
struct rb_encoding_entry * list
int rb_method_basic_definition_p(VALUE, ID)
void rb_define_variable(const char *, VALUE *)
static VALUE rb_io_s_read(int argc, VALUE *argv, VALUE io)
void rb_io_check_readable(rb_io_t *fptr)
FILE * rb_fdopen(int fd, const char *modestr)
void(* finalize)(struct rb_io_t *, int)
static rb_io_t * flush_before_seek(rb_io_t *fptr)
#define TypedData_Make_Struct(klass, type, data_type, sval)
#define rb_enc_left_char_head(s, p, e, enc)
void rb_notimplement(void)
VALUE rb_ary_concat(VALUE x, VALUE y)
static long remain_size(rb_io_t *fptr)
static VALUE argf_argv_getter(ID id, VALUE *var)
#define RETURN_ENUMERATOR(obj, argc, argv)
#define SafeStringValue(v)
static VALUE io_reopen(VALUE io, VALUE nfile)
static void * sysopen_func(void *ptr)
static VALUE rb_io_readline(int argc, VALUE *argv, VALUE io)
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
static VALUE rb_eEWOULDBLOCKWaitReadable
#define rb_sys_fail_path(path)
VALUE rb_io_addstr(VALUE io, VALUE str)
static long ioctl_narg_len(ioctl_req_t cmd)
static VALUE internal_read_func(void *ptr)
void rb_set_class_path(VALUE, VALUE, const char *)
int rb_thread_interrupted(VALUE thval)
static VALUE rb_io_initialize(int argc, VALUE *argv, VALUE io)
static void make_writeconv(rb_io_t *fptr)
VALUE rb_io_taint_check(VALUE io)
int rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val)
static VALUE rb_io_readbyte(VALUE io)
#define READ_CHAR_PENDING_PTR(fptr)
#define MakeOpenFile(obj, fp)
static void fptr_finalize_flush(rb_io_t *fptr, int noraise)
#define MORE_CHAR_SUSPENDED
RUBY_EXTERN int dup2(int, int)
static VALUE sym_sequential
static VALUE io_getpartial(int argc, VALUE *argv, VALUE io, VALUE opts, int nonblock)
VALUE rb_str_new_frozen(VALUE)
static VALUE rb_io_s_copy_stream(int argc, VALUE *argv, VALUE io)
static void clear_writeconv(rb_io_t *fptr)
struct rb_io_enc_t convconfig_t
static void parse_mode_enc(const char *estr, rb_encoding *estr_enc, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p)
static VALUE fill_cbuf(rb_io_t *fptr, int ec_flags)
static rb_io_t * rb_io_get_fptr(VALUE io)
static VALUE rb_io_reopen(int argc, VALUE *argv, VALUE file)
rb_encoding * rb_ascii8bit_encoding(void)
static long read_buffered_data(char *ptr, long len, rb_io_t *fptr)
static VALUE sym_dontneed
static int interpret_seek_whence(VALUE vwhence)
void rb_warning(const char *fmt,...)
int rb_enc_find_index(const char *name)
#define rb_syserr_fail_path(err, path)
static VALUE io_s_foreach(struct getline_arg *arg)
static VALUE sym_open_args
static VALUE pipe_open_s(VALUE prog, const char *modestr, int fmode, const convconfig_t *convconfig)
int rb_io_read_pending(rb_io_t *fptr)
#define rb_check_frozen(obj)
#define NEED_NEWLINE_DECORATOR_ON_READ(fptr)
#define CONST_ID(var, str)
static VALUE rb_io_fileno(VALUE io)
ssize_t rb_io_bufread(VALUE io, void *buf, size_t size)
VALUE rb_str_tmp_frozen_acquire(VALUE str)
#define MODE_BTMODE(a, b, c)
#define rb_intern_const(str)
VALUE rb_obj_freeze(VALUE)
void rb_execarg_parent_end(VALUE execarg_obj)
static VALUE rb_f_p(int argc, VALUE *argv, VALUE self)
static VALUE argf_forward(int argc, VALUE *argv, VALUE argf)
static VALUE rb_f_readline(int argc, VALUE *argv, VALUE recv)
VALUE rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts)
char rb_w32_fd_is_text(int)
#define io_seek(fptr, ofs, whence)
int fchmod(int fd, int mode)
static VALUE argf_fileno(VALUE argf)
static ssize_t rb_read_internal(int fd, void *buf, size_t count)
static VALUE argf_to_s(VALUE argf)
static VALUE io_alloc(VALUE klass)
#define READ_CHAR_PENDING_COUNT(fptr)
void rb_stdio_set_default_encoding(void)
VALUE rb_str_buf_new(long)
VALUE rb_usascii_str_new(const char *, long)
void rb_io_read_check(rb_io_t *fptr)
static void * nogvl_copy_stream_func(void *arg)
static VALUE argf_block_call_line_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, argf))
static const char * rb_io_oflags_modestr(int oflags)
#define RB_INTEGER_TYPE_P(obj)
#define DEFULT_IOCTL_NARG_LEN
static void prepare_getline_args(int argc, VALUE *argv, struct getline_arg *args, VALUE io)
ssize_t rb_io_bufwrite(VALUE io, const void *buf, size_t size)
static VALUE argf_file(VALUE argf)
static VALUE copy_stream_finalize(VALUE arg)
static VALUE io_getc(rb_io_t *fptr, rb_encoding *enc)
#define READ_CHAR_PENDING(fptr)
static void argf_free(void *ptr)
#define READ_DATA_PENDING_PTR(fptr)
static void extract_binmode(VALUE opthash, int *fmode)
static VALUE argf_close_m(VALUE argf)
static VALUE select_end(VALUE arg)
static void rb_io_ext_int_to_encs(rb_encoding *ext, rb_encoding *intern, rb_encoding **enc, rb_encoding **enc2, int fmode)
rb_pid_t rb_waitpid(rb_pid_t pid, int *status, int flags)
VALUE rb_class_new(VALUE super)
Creates a new class.
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
static rb_io_t * rb_io_fptr_new(void)
VALUE rb_str_append(VALUE, VALUE)
VALUE rb_file_open(const char *fname, const char *modestr)
#define ENCINDEX_UTF_32LE
void rb_io_check_byte_readable(rb_io_t *fptr)
static VALUE rb_io_each_codepoint(VALUE io)
static void pipe_del_fptr(rb_io_t *fptr)
void rb_io_check_char_readable(rb_io_t *fptr)
int rb_econv_prepare_options(VALUE opthash, VALUE *ecopts, int ecflags)
void rb_econv_binmode(rb_econv_t *ec)
void rb_warn(const char *fmt,...)
static VALUE rb_io_s_foreach(int argc, VALUE *argv, VALUE self)
#define ENCINDEX_UTF_32BE
static VALUE rb_io_open(VALUE filename, VALUE vmode, VALUE vperm, VALUE opt)
#define ECONV_UNIVERSAL_NEWLINE_DECORATOR
VALUE rb_io_set_write_io(VALUE io, VALUE w)
static VALUE argf_initialize_copy(VALUE argf, VALUE orig)
static VALUE rb_io_getline_1(VALUE rs, long limit, int chomp, VALUE io)
struct rb_execarg::@139::@140 sh
static const char bom_prefix[]
VALUE rb_io_ungetc(VALUE io, VALUE c)
static VALUE argf_getc(VALUE argf)
VALUE rb_mutex_owned_p(VALUE self)
static int maygvl_close(int fd, int keepgvl)
void rb_econv_putback(rb_econv_t *ec, unsigned char *p, int n)
static VALUE argf_skip(VALUE argf)
void rb_io_check_closed(rb_io_t *fptr)
VALUE rb_attr_get(VALUE, ID)
#define SET_BINARY_MODE(fptr)
char * strrchr(const char *, const char)
static VALUE io_encoding_set_v(VALUE v)
VALUE rb_econv_str_convert(rb_econv_t *ec, VALUE src, int flags)
static int maygvl_fclose(FILE *file, int keepgvl)
static VALUE argf_forward_call(VALUE arg)
void rb_write_error(const char *mesg)
static int io_fillbuf(rb_io_t *fptr)
static void fptr_waitpid(rb_io_t *fptr, int nohang)
rb_encoding * rb_enc_from_index(int index)
VALUE rb_obj_class(VALUE)
VALUE rb_str_new(const char *, long)
static VALUE sym_wait_writable
static VALUE rb_io_s_new(int argc, VALUE *argv, VALUE klass)
static VALUE rb_f_print(int argc, const VALUE *argv)
static void clear_readconv(rb_io_t *fptr)