21 #define free(x) xfree(x)
23 #if defined(DOSISH) || defined(__CYGWIN__)
27 #include <sys/types.h>
28 #if defined HAVE_NET_SOCKET_H
29 # include <net/socket.h>
30 #elif defined HAVE_SYS_SOCKET_H
31 # include <sys/socket.h>
34 #if defined(__BOW__) || defined(__CYGWIN__) || defined(_WIN32) || defined(__EMX__) || defined(__BEOS__) || defined(__HAIKU__)
35 # define NO_SAFE_RENAME
38 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(sun) || defined(_nec_ews)
46 #include <sys/types.h>
47 #if defined(HAVE_SYS_IOCTL_H) && !defined(_WIN32)
48 #include <sys/ioctl.h>
50 #if defined(HAVE_FCNTL_H) || defined(_WIN32)
52 #elif defined(HAVE_SYS_FCNTL_H)
53 #include <sys/fcntl.h>
56 #if !HAVE_OFF_T && !defined(off_t)
63 #if defined(HAVE_SYS_PARAM_H) && !(defined(__EMX__) || defined(__HIUX_MPP__))
64 # include <sys/param.h>
77 #elif defined HAVE_SYS_SYSCALL_H
78 #include <sys/syscall.h>
81 #if defined(__BEOS__) || defined(__HAIKU__)
83 # define NOFILE (OPEN_MAX)
90 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
93 #if SIZEOF_OFF_T > SIZEOF_LONG && !defined(HAVE_LONG_LONG)
94 # error off_t is bigger than long, but you have no long long...
98 # ifdef _POSIX_PIPE_BUF
99 # define PIPE_BUF _POSIX_PIPE_BUF
101 # define PIPE_BUF 512
105 #if defined(HAVE___SYSCALL) && (defined(__APPLE__) || defined(__OpenBSD__))
107 off_t __syscall(quad_t number, ...);
110 #define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
112 #define IO_RBUF_CAPA_MIN 8192
113 #define IO_CBUF_CAPA_MIN (128*1024)
114 #define IO_RBUF_CAPA_FOR(fptr) (NEED_READCONV(fptr) ? IO_CBUF_CAPA_MIN : IO_RBUF_CAPA_MIN)
115 #define IO_WBUF_CAPA_MIN 8192
120 #define open rb_w32_uopen
160 rb_bug(
"rb_update_max_fd: invalid fd (%d) given.", fd);
171 flags =
fcntl(fd, F_GETFD);
176 flags2 = flags & ~FD_CLOEXEC;
178 flags2 = flags | FD_CLOEXEC;
179 if (flags != flags2) {
180 ret =
fcntl(fd, F_SETFD, flags2);
182 rb_bug(
"rb_maygvl_fd_fix_cloexec: fcntl(%d, F_SETFD, %d) failed: %s", fd, flags2,
strerror(
errno));
193 #if defined(HAVE_FCNTL) && defined(F_DUPFD_CLOEXEC)
194 static int try_dupfd_cloexec = 1;
195 if (try_dupfd_cloexec) {
196 ret =
fcntl(fd, F_DUPFD_CLOEXEC, minfd);
203 if (
errno == EINVAL) {
204 ret =
fcntl(fd, F_DUPFD, minfd);
206 try_dupfd_cloexec = 0;
211 ret =
fcntl(fd, F_DUPFD, minfd);
213 #elif defined(F_DUPFD)
214 ret =
fcntl(fd, F_DUPFD, minfd);
219 if (ret == -1)
return -1;
224 #define argf_of(obj) (*(struct argf *)DATA_PTR(obj))
225 #define ARGF argf_of(argf)
227 #ifdef _STDIO_USES_IOSTREAM
229 # define STDIO_READ_DATA_PENDING(fp) ((fp)->_IO_read_ptr != (fp)->_IO_read_end)
231 # define STDIO_READ_DATA_PENDING(fp) ((fp)->_gptr < (fp)->_egptr)
233 #elif defined(FILE_COUNT)
234 # define STDIO_READ_DATA_PENDING(fp) ((fp)->FILE_COUNT > 0)
235 #elif defined(FILE_READEND)
236 # define STDIO_READ_DATA_PENDING(fp) ((fp)->FILE_READPTR < (fp)->FILE_READEND)
237 #elif defined(__BEOS__) || defined(__HAIKU__)
238 # define STDIO_READ_DATA_PENDING(fp) ((fp)->_state._eof == 0)
240 # define STDIO_READ_DATA_PENDING(fp) (!feof(fp))
243 #define GetWriteIO(io) rb_io_get_write_io(io)
245 #define READ_DATA_PENDING(fptr) ((fptr)->rbuf.len)
246 #define READ_DATA_PENDING_COUNT(fptr) ((fptr)->rbuf.len)
247 #define READ_DATA_PENDING_PTR(fptr) ((fptr)->rbuf.ptr+(fptr)->rbuf.off)
248 #define READ_DATA_BUFFERED(fptr) READ_DATA_PENDING(fptr)
250 #define READ_CHAR_PENDING(fptr) ((fptr)->cbuf.len)
251 #define READ_CHAR_PENDING_COUNT(fptr) ((fptr)->cbuf.len)
252 #define READ_CHAR_PENDING_PTR(fptr) ((fptr)->cbuf.ptr+(fptr)->cbuf.off)
255 #define WAIT_FD_IN_WIN32(fptr) \
256 (rb_w32_io_cancelable_p((fptr)->fd) ? 0 : rb_thread_wait_fd((fptr)->fd))
258 #define WAIT_FD_IN_WIN32(fptr)
261 #define READ_CHECK(fptr) do {\
262 if (!READ_DATA_PENDING(fptr)) {\
263 WAIT_FD_IN_WIN32(fptr);\
264 rb_io_check_closed(fptr);\
270 # define S_ISSOCK(m) _S_ISSOCK(m)
273 # define S_ISSOCK(m) (((m) & S_IFMT) == _S_IFSOCK)
276 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
282 #define rb_sys_fail_path(path) rb_sys_fail_str(path)
287 #define NEED_NEWLINE_DECORATOR_ON_READ(fptr) ((fptr)->mode & FMODE_TEXTMODE)
288 #define NEED_NEWLINE_DECORATOR_ON_WRITE(fptr) ((fptr)->mode & FMODE_TEXTMODE)
289 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
291 # define DEFAULT_TEXTMODE FMODE_TEXTMODE
292 # define TEXTMODE_NEWLINE_DECORATOR_ON_WRITE ECONV_CRLF_NEWLINE_DECORATOR
300 #define NEED_READCONV(fptr) ((fptr)->encs.enc2 != NULL || (fptr)->encs.ecflags & ~ECONV_CRLF_NEWLINE_DECORATOR)
301 #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)))
302 #define SET_BINARY_MODE(fptr) setmode((fptr)->fd, O_BINARY)
304 #define NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr) do {\
305 if (NEED_NEWLINE_DECORATOR_ON_READ(fptr)) {\
306 if (((fptr)->mode & FMODE_READABLE) &&\
307 !((fptr)->encs.ecflags & ECONV_NEWLINE_DECORATOR_MASK)) {\
308 setmode((fptr)->fd, O_BINARY);\
311 setmode((fptr)->fd, O_TEXT);\
316 #define SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(enc2, ecflags) do {\
317 if ((enc2) && ((ecflags) & ECONV_DEFAULT_NEWLINE_DECORATOR)) {\
318 (ecflags) |= ECONV_UNIVERSAL_NEWLINE_DECORATOR;\
344 if (r < 0 &&
errno) {
356 if (pos < 0 &&
errno) {
371 for (i = 0; i < fptr->
rbuf.
len; i++) {
372 if (*p ==
'\n') newlines++;
373 if (extra_max == newlines)
break;
378 while (newlines >= 0) {
380 if (newlines == 0)
break;
385 read_size = _read(fptr->
fd, buf, fptr->
rbuf.
len + newlines);
390 if (read_size == fptr->
rbuf.
len) {
412 set_binary_mode_with_seek_cur(
rb_io_t *fptr)
422 #define SET_BINARY_MODE_WITH_SEEK_CUR(fptr) set_binary_mode_with_seek_cur(fptr)
426 # define DEFAULT_TEXTMODE 0
427 #define NEED_READCONV(fptr) ((fptr)->encs.enc2 != NULL || NEED_NEWLINE_DECORATOR_ON_READ(fptr))
428 #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)))
429 #define SET_BINARY_MODE(fptr) (void)(fptr)
430 #define NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr) (void)(fptr)
431 #define SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(enc2, ecflags) ((void)(enc2), (void)(ecflags))
432 #define SET_BINARY_MODE_WITH_SEEK_CUR(fptr) (void)(fptr)
435 #if !defined HAVE_SHUTDOWN && !defined shutdown
436 #define shutdown(a,b) 0
440 #define is_socket(fd, path) rb_w32_is_socket(fd)
441 #elif !defined(S_ISSOCK)
442 #define is_socket(fd, path) 0
448 if (
fstat(fd, &sbuf) < 0)
450 return S_ISSOCK(sbuf.st_mode);
504 write_io =
RFILE(io)->fptr->tied_io_for_writing;
522 write_io =
RFILE(io)->fptr->tied_io_for_writing;
523 RFILE(io)->fptr->tied_io_for_writing = w;
524 return write_io ? write_io :
Qnil;
550 #if !(defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32))
561 if (r < 0 &&
errno) {
583 #if SIZEOF_LONG > SIZEOF_INT
617 #define io_seek(fptr, ofs, whence) (errno = 0, lseek(flush_before_seek(fptr)->fd, (ofs), (whence)))
618 #define io_tell(fptr) lseek(flush_before_seek(fptr)->fd, 0, SEEK_CUR)
626 #define FMODE_SYNCWRITE (FMODE_SYNC|FMODE_WRITABLE)
749 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
755 #if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(O_NONBLOCK)
761 if (
fstat(fptr->
fd, &buf) == 0 &&
763 #
if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(
O_NONBLOCK)
764 && (r =
fcntl(fptr->
fd, F_GETFL)) != -1 &&
791 return read(iis->
fd, iis->
buf, iis->
capa);
798 return write(iis->
fd, iis->
buf, iis->
capa);
897 #if defined(ERESTART)
904 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
923 #if defined(ERESTART)
930 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
945 const char *senc, *denc;
1021 long n,
r, offset = 0;
1023 if ((n = len) <= 0)
return n;
1057 arg.
ptr = ptr + offset;
1067 if (r == n)
return len;
1091 # define MODE_BTMODE(a,b,c) ((fmode & FMODE_BINMODE) ? (b) : \
1092 (fmode & FMODE_TEXTMODE) ? (c) : (a))
1103 #define fmode (fptr->mode)
1107 rb_raise(
rb_eArgError,
"ASCII incompatible string written for text mode IO without encoding conversion: %s",
1119 if (!
NIL_P(common_encoding)) {
1128 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
1129 #define fmode (fptr->mode)
1136 setmode(fptr->
fd, O_TEXT);
1139 rb_raise(
rb_eArgError,
"ASCII incompatible string written for text mode IO without encoding conversion: %s",
1154 if (len > 0)
return len;
1169 return (ssize_t)
io_binwrite(0, buf, (
long)size, fptr, 0);
1330 pos =
io_seek(fptr, pos, whence);
1360 VALUE offset, ptrname;
1363 if (
rb_scan_args(argc, argv,
"11", &offset, &ptrname) == 2) {
1425 if (io ==
ARGF.current_file) {
1513 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
1579 static VALUE nogvl_fsync(
void *
ptr)
1617 #define rb_io_fsync rb_f_notimplement
1620 #ifdef HAVE_FDATASYNC
1621 static VALUE nogvl_fdatasync(
void *ptr)
1625 return (
VALUE)fdatasync(fptr->
fd);
1657 #define rb_io_fdatasync rb_io_fsync
1728 static const char closed[] =
" (closed)";
1772 if (n <= 0)
return 0;
1773 if (n > len) n = (
int)len;
1798 if ((n -= c) <= 0)
break;
1808 if ((n -= c) <= 0)
break;
1855 return (ssize_t)
io_bufread(buf, (
long)size, fptr);
1858 #define SMALLBUF 100
1868 #
if defined(__BEOS__) || defined(__HAIKU__)
1876 if (st.st_size >= pos && pos >= 0) {
1877 siz += st.st_size - pos;
1903 const char *sname, *dname;
1924 #define MORE_CHAR_SUSPENDED Qtrue
1925 #define MORE_CHAR_FINISHED Qnil
1929 const unsigned char *ss, *sp, *se;
1930 unsigned char *ds, *
dp, *de;
1950 ss = sp = (
const unsigned char *)fptr->
rbuf.
ptr + fptr->
rbuf.
off;
1962 fptr->
rbuf.
off -= putbackable;
1963 fptr->
rbuf.
len += putbackable;
1970 if (cbuf_len0 != fptr->
cbuf.
len)
1994 if (cbuf_len0 != fptr->
cbuf.
len)
2102 if (siz == 0) siz = BUFSIZ;
2107 if (n == 0 && bytes == 0) {
2113 if (bytes < siz)
break;
2128 oflags =
fcntl(fptr->
fd, F_GETFL);
2167 if ((len =
NUM2LONG(length)) < 0) {
2488 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
2494 if (
NIL_P(length)) {
2508 if (len == 0)
return str;
2511 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
2512 previous_mode = set_binary_mode_with_seek_cur(fptr);
2515 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
2516 if (previous_mode == O_TEXT) {
2517 setmode(fptr->
fd, O_TEXT);
2521 if (fptr->
fd < 0)
return Qnil;
2554 if (0 < limit && limit < searchlen)
2555 searchlen = (
int)limit;
2556 e = memchr(p, delim, searchlen);
2597 if (limit > 0 && pending > limit) pending = limit;
2598 e = memchr(p, delim, pending);
2599 if (e) pending = e - p + 1;
2612 if (e)
return delim;
2636 if (*p != term)
return TRUE;
2638 while (--i && *++p == term);
2641 const char *
e = p +
cnt;
2643 while ((p += i) < e &&
rb_enc_ascget(p, e, &i, enc) == term);
2659 if (cnt >
sizeof buf) cnt =
sizeof buf;
2660 if (*p != term)
return TRUE;
2662 while (--i && *++p == term);
2686 e = memchr(p,
'\n', pending);
2688 pending = (
int)(e - p + 1);
2714 if (io ==
ARGF.current_file) {
2741 else if (2 <= argc) {
2752 if (enc_io != enc_rs &&
2780 if (
NIL_P(rs) && limit < 0) {
2784 else if (limit == 0) {
2793 int c, newline = -1;
2794 const char *rsptr = 0;
2797 int extra_limit = 16;
2821 newline = (
unsigned char)rsptr[rslen - 1];
2825 while ((c =
appendline(fptr, newline, &str, &limit)) !=
EOF) {
2826 const char *
s, *
p, *pp, *
e;
2834 if (pp != p)
continue;
2835 if (!rspara)
rscheck(rsptr, rslen, rs);
2836 if (
memcmp(p, rsptr, rslen) == 0)
break;
2868 if (io ==
ARGF.current_file) {
3560 #if SIZEOF_LONG > SIZEOF_INT
3602 if (isatty(fptr->
fd) == 0)
3607 #if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
3630 if (io != write_io) {
3632 if (fptr && 0 <= (fd = fptr->
fd)) {
3634 if (!(ret & FD_CLOEXEC))
return Qfalse;
3639 if (fptr && 0 <= (fd = fptr->
fd)) {
3641 if (!(ret & FD_CLOEXEC))
return Qfalse;
3646 #define rb_io_close_on_exec_p rb_f_notimplement
3649 #if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
3671 if (io != write_io) {
3673 if (fptr && 0 <= (fd = fptr->
fd)) {
3675 if ((ret & FD_CLOEXEC) != flag) {
3676 ret = (ret & ~FD_CLOEXEC) | flag;
3677 ret =
fcntl(fd, F_SETFD, ret);
3685 if (fptr && 0 <= (fd = fptr->
fd)) {
3687 if ((ret & FD_CLOEXEC) != flag) {
3688 ret = (ret & ~FD_CLOEXEC) | flag;
3689 ret =
fcntl(fd, F_SETFD, ret);
3696 #define rb_io_set_close_on_exec rb_f_notimplement
3699 #define FMODE_PREP (1<<16)
3700 #define IS_PREP_STDIO(f) ((f)->mode & FMODE_PREP)
3701 #define PREP_STDIO_NAME(f) (RSTRING_PTR((f)->pathv))
3706 unsigned char *ds, *
dp, *de;
3710 unsigned char buf[1024];
3716 de = buf +
sizeof(
buf);
3809 else if (0 <= fptr->
fd) {
3813 if (close(fptr->
fd) < 0 &&
NIL_P(err))
3821 if (!
NIL_P(err) && !noraise) {
3878 if (!fptr)
return 0;
3919 if (io != write_io) {
3920 write_fptr =
RFILE(write_io)->fptr;
3921 if (write_fptr && 0 <= write_fptr->
fd) {
3926 fptr =
RFILE(io)->fptr;
3927 if (!fptr)
return Qnil;
3928 if (fptr->
fd < 0)
return Qnil;
3931 #if defined __APPLE__ && defined(__MACH__) && \
3932 (!defined(MAC_OS_X_VERSION_MIN_ALLOWED) || MAC_OS_X_VERSION_MIN_ALLOWED <= 1050)
4012 if (io != write_io) {
4013 write_fptr =
RFILE(write_io)->fptr;
4014 if (write_fptr && 0 <= write_fptr->
fd) {
4019 fptr =
RFILE(io)->fptr;
4065 if (io != write_io) {
4070 RFILE(io)->fptr = wfptr;
4132 if (io != write_io) {
4157 VALUE offset, ptrname;
4162 if (
rb_scan_args(argc, argv,
"11", &offset, &ptrname) == 2) {
4172 rb_warn(
"sysseek for buffered IO");
4175 pos = lseek(fptr->
fd, pos, whence);
4209 rb_warn(
"syswrite for buffered IO");
4251 if (ilen == 0)
return str;
4275 if (n == 0 && ilen > 0) {
4389 case FMODE_READWRITE:
4402 static const char bom_prefix[] =
"bom|utf-";
4403 enum {bom_prefix_len = (
int)
sizeof(bom_prefix) - 1};
4405 const char *
p =
strchr(name,
':');
4408 return len > bom_prefix_len &&
STRNCASECMP(name, bom_prefix, bom_prefix_len) == 0;
4415 const char *
m = modestr, *
p =
NULL;
4465 switch (oflags & (O_RDONLY|O_WRONLY|O_RDWR)) {
4477 if (oflags & O_APPEND) {
4480 if (oflags & O_TRUNC) {
4483 if (oflags & O_CREAT) {
4507 case FMODE_READWRITE:
4540 # define MODE_BINARY(a,b) ((oflags & O_BINARY) ? (b) : (a))
4542 # define MODE_BINARY(a,b) (a)
4544 int accmode = oflags & (O_RDONLY|O_WRONLY|O_RDWR);
4545 if (oflags & O_APPEND) {
4546 if (accmode == O_WRONLY) {
4549 if (accmode == O_RDWR) {
4553 switch (oflags & (O_RDONLY|O_WRONLY|O_RDWR)) {
4573 int default_ext = 0;
4584 *enc = (default_ext && intern != ext) ?
NULL : ext;
4605 long len = (p++) - estr;
4614 memcpy(encname, estr, len);
4615 encname[
len] =
'\0';
4626 memcpy(encname, estr, len);
4627 encname[
len] =
'\0';
4637 rb_warn(
"Unsupported encoding %s ignored", estr);
4643 if (*p ==
'-' && *(p+1) ==
'\0') {
4650 rb_warn(
"Unsupported encoding %s ignored", p);
4651 else if (idx2 == idx) {
4652 rb_warn(
"Ignoring internal encoding %s: it is identical to external encoding %s", p, estr);
4674 const char *
p =
strchr(modestr,
':');
4691 if (v !=
Qnil) encoding =
v;
4693 if (v !=
Qnil) extenc =
v;
4700 rb_warn(
"Ignoring encoding parameter '%s': %s_encoding is used",
4702 extenc ==
Qundef ?
"internal" :
"external");
4710 if (
NIL_P(intenc)) {
4717 if (*p ==
'-' && *(p+1) ==
'\0') {
4728 if (extencoding == intencoding) {
4732 if (!
NIL_P(encoding)) {
4753 int fmode = *fmode_p;
4761 if (!(fmode & FMODE_BINMODE) &&
4766 #if !DEFAULT_TEXTMODE
4767 else if (!(ecflags & ECONV_NEWLINE_DECORATOR_MASK)) {
4777 if (!
NIL_P(opthash)) {
4793 int *oflags_p,
int *fmode_p,
convconfig_t *convconfig_p)
4800 int has_enc = 0, has_vmode = 0;
4838 if (
NIL_P(opthash)) {
4842 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
4845 0, TEXTMODE_NEWLINE_DECORATOR_ON_WRITE) : 0;
4857 #if DEFAULT_TEXTMODE
4858 else if (
NIL_P(vmode)) {
4865 if (!
NIL_P(vmode)) {
4876 if (!
NIL_P(*vperm_p)) {
4888 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
4891 0, TEXTMODE_NEWLINE_DECORATOR_ON_WRITE) : 0;
4909 convconfig_p->enc =
enc;
4910 convconfig_p->enc2 =
enc2;
4911 convconfig_p->ecflags =
ecflags;
4912 convconfig_p->ecopts =
ecopts;
4971 file = fdopen(fd, modestr);
4982 file = fdopen(fd, modestr);
4996 if (setvbuf(file,
NULL, _IOFBF, 0) != 0)
4997 rb_warn(
"setvbuf() can't be honoured (fd=%d)", fd);
5005 if (isatty(fptr->
fd))
5015 VALUE b1, b2, b3, b4;
5101 convconfig->enc, convconfig->enc2);
5105 fptr->
encs = *convconfig;
5118 const char *
p =
strchr(modestr,
':');
5130 convconfig.ecflags = 0;
5131 convconfig.ecopts =
Qnil;
5154 #if defined(__CYGWIN__) || !defined(HAVE_FORK)
5177 if (list->
fptr == fptr) {
5183 while (list->
next) {
5210 #if !defined(HAVE_FORK) && !defined(_WIN32)
5265 popen_redirect(
struct popen_arg *
p)
5268 close(p->write_pair[1]);
5269 if (p->write_pair[0] != 0) {
5270 dup2(p->write_pair[0], 0);
5271 close(p->write_pair[0]);
5274 if (p->pair[1] != 1) {
5275 dup2(p->pair[1], 1);
5281 if (p->pair[1] != 1) {
5282 dup2(p->pair[1], 1);
5288 if (p->pair[0] != 0) {
5289 dup2(p->pair[0], 0);
5302 for (fd = lowfd; fd <= max; fd++) {
5303 if (!
NIL_P(noclose_fds) &&
5307 ret =
fcntl(fd, F_GETFD);
5308 if (ret != -1 && !(ret & FD_CLOEXEC)) {
5309 fcntl(fd, F_SETFD, ret|FD_CLOEXEC);
5314 #define CONTIGUOUS_CLOSED_FDS 20
5316 if (max < fd + CONTIGUOUS_CLOSED_FDS)
5317 max = fd + CONTIGUOUS_CLOSED_FDS;
5323 popen_exec(
void *pp,
char *errmsg,
size_t errmsg_len)
5325 struct popen_arg *p = (
struct popen_arg*)pp;
5340 #if defined(HAVE_FORK)
5342 struct popen_arg arg;
5343 char errmsg[80] = {
'\0' };
5344 #elif defined(_WIN32)
5345 volatile VALUE argbuf;
5347 int pair[2], write_pair[2];
5349 #if !defined(HAVE_FORK)
5355 const char *
cmd = 0;
5367 else if (eargp->
argc) {
5378 #if defined(HAVE_FORK)
5381 arg.pair[0] = arg.pair[1] = -1;
5382 arg.write_pair[0] = arg.write_pair[1] = -1;
5385 if (
rb_pipe(arg.write_pair) < 0)
5389 close(arg.write_pair[0]);
5390 close(arg.write_pair[1]);
5416 pid =
rb_fork_err(&status, popen_exec, &arg, arg.execp->redirect_fds, errmsg,
sizeof(errmsg));
5423 popen_redirect(&arg);
5436 close(arg.write_pair[0]);
5437 close(arg.write_pair[1]);
5447 close(arg.write_pair[0]);
5448 write_fd = arg.write_pair[1];
5450 else if (fmode & FMODE_READABLE) {
5458 #elif defined(_WIN32)
5462 if (argc >= (
int)(
FIXNUM_MAX /
sizeof(
char *))) {
5467 for (i = 0; i <
argc; ++
i) {
5472 switch (fmode & (FMODE_READABLE|FMODE_WRITABLE)) {
5473 case FMODE_READABLE|FMODE_WRITABLE:
5478 close(write_pair[0]);
5479 close(write_pair[1]);
5488 case FMODE_READABLE:
5494 case FMODE_WRITABLE:
5507 while ((pid = (args ?
5513 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
5525 if ((fmode & (FMODE_READABLE|FMODE_WRITABLE)) == (FMODE_READABLE|FMODE_WRITABLE)) {
5526 close(write_pair[0]);
5527 close(write_pair[1]);
5540 if ((fmode & FMODE_READABLE) && (fmode & FMODE_WRITABLE)) {
5543 close(write_pair[0]);
5544 write_fd = write_pair[1];
5546 else if (fmode & FMODE_READABLE) {
5563 fp = popen(cmd, modestr);
5576 fptr->
encs = *convconfig;
5577 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
5587 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
5589 fptr->
encs.
ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
5595 if (0 <= write_fd) {
5598 write_fptr->
fd = write_fd;
5600 fptr->
mode &= ~FMODE_WRITABLE;
5605 #if defined (__CYGWIN__) || !defined(HAVE_FORK)
5618 return pipe_open(&earg, prog, modestr, fmode, convconfig);
5630 #if !defined(HAVE_FORK)
5632 "fork() function is unimplemented on this machine");
5634 return pipe_open(0, 0, modestr, fmode, convconfig);
5638 return pipe_open(&earg, prog, modestr, fmode, convconfig);
5727 const char *modestr;
5728 VALUE pname, pmode, port, tmp, opt;
5732 argc =
rb_scan_args(argc, argv,
"11:", &pname, &pmode, &opt);
5740 #if SIZEOF_LONG > SIZEOF_INT
5741 if (len > INT_MAX) {
5752 port =
pipe_open_s(pname, modestr, fmode, &convconfig);
5773 VALUE *fname_p,
int *oflags_p,
int *fmode_p,
5776 VALUE opt, fname, vmode, vperm;
5780 argc =
rb_scan_args(argc, argv,
"12:", &fname, &vmode, &vperm, &opt);
5868 VALUE fname, vmode, vperm;
5873 rb_scan_args(argc, argv,
"12", &fname, &vmode, &vperm);
5884 if (
NIL_P(vperm)) perm = 0666;
6022 int redirect =
FALSE;
6030 VALUE tmp = argv[0];
6071 oflags, fmode, &convconfig, perm);
6100 if (fptr == orig)
return io;
6106 "%s can't change access mode from \"%s\" to \"%s\"",
6133 #
if defined (__CYGWIN__) || !defined(HAVE_FORK)
6143 if (
dup2(fd2, fd) < 0)
6151 if (
dup2(fd2, fd) < 0)
6199 if (
rb_scan_args(argc, argv,
"11", &fname, &nmode) == 1) {
6208 fptr =
RFILE(file)->fptr;
6214 if (!
NIL_P(nmode)) {
6218 (fptr->
mode & FMODE_READWRITE)) {
6220 "%s can't change access mode from \"%s\" to \"%s\"",
6255 if (close(fptr->
fd) < 0)
6274 if (dest == io)
return dest;
6287 #if defined (__CYGWIN__) || !defined(HAVE_FORK)
6302 if (io != write_io) {
6343 if (argc == 0)
return Qnil;
6391 for (i=0; i<
argc; i++) {
6497 if (len == 0)
return 0;
6499 return ptr[len - 1] ==
c;
6501 return rb_enc_ascget(ptr + ((len - 1) / n) * n, ptr + len, &n, enc) ==
c;
6553 for (i=0; i<
argc; i++) {
6632 for (i=0; i<
argc; i++) {
6638 else if (argc > 1) {
6690 (
void)fwrite(mesg,
sizeof(
char),
len, stderr);
6747 if (path && strcmp(path,
"-")) klass =
rb_cFile;
6759 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
6760 fptr->
encs.
ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
6873 int fd,
fmode, oflags = O_RDONLY;
6876 #if defined(HAVE_FCNTL) && defined(F_GETFL)
6884 argc =
rb_scan_args(argc, argv,
"11:", &fnum, &vmode, &opt);
6891 #if defined(HAVE_FCNTL) && defined(F_GETFL)
6892 oflags =
fcntl(fd, F_GETFL);
6898 #if defined(HAVE_FCNTL) && defined(F_GETFL)
6914 fp->
encs = convconfig;
6919 else if (
fileno(stdout) == fd)
6921 else if (
fileno(stderr) == fd)
6958 if (
RFILE(io)->fptr) {
6961 if (0 < argc && argc < 3) {
6981 rb_warn(
"%s::new() does not take block; use %s::open() instead",
7044 if (!
RTEST(autoclose))
7165 #define next_argv() argf_next_argv(argf)
7166 #define ARGF_GENERIC_INPUT_P() \
7167 (ARGF.current_file == rb_stdin && TYPE(ARGF.current_file) != T_FILE)
7168 #define ARGF_FORWARD(argc, argv) do {\
7169 if (ARGF_GENERIC_INPUT_P())\
7170 return argf_forward((argc), (argv), argf);\
7172 #define NEXT_ARGF_FORWARD(argc, argv) do {\
7173 if (!next_argv()) return Qnil;\
7174 ARGF_FORWARD((argc), (argv));\
7192 int stdout_binmode = 0;
7201 if (
ARGF.init_p == 0) {
7219 if (
ARGF.next_p == 1) {
7224 if (
strlen(fn) == 1 && fn[0] ==
'-') {
7227 rb_warn(
"Can't do inplace edit for stdio; skipping");
7237 #ifndef NO_SAFE_RENAME
7247 if (*
ARGF.inplace) {
7250 #ifdef NO_SAFE_RENAME
7254 rb_warn(
"Can't rename %s to %s: %s, skipping file",
7261 rb_warn(
"Can't rename %s to %s: %s, skipping file",
7269 #ifdef NO_SAFE_RENAME
7270 rb_fatal(
"Can't do inplace edit without backup");
7272 if (unlink(fn) < 0) {
7273 rb_warn(
"Can't remove %s: %s, skipping file",
7281 #ifndef NO_SAFE_RENAME
7284 fchmod(fw, st.st_mode);
7286 chmod(fn, st.st_mode);
7288 if (st.st_uid!=st2.st_uid || st.st_gid!=st2.st_gid) {
7291 err = fchown(fw, st.st_uid, st.st_gid);
7293 err =
chown(fn, st.st_uid, st.st_gid);
7295 if (err &&
getuid() == 0 && st2.st_uid == 0) {
7297 rb_warn(
"Can't set owner/group of %s to same as %s: %s, skipping file",
7311 if (!
ARGF.binmode) {
7315 if (!
NIL_P(write_io)) {
7321 if (
ARGF.encs.enc) {
7327 if (!
ARGF.binmode) {
7329 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
7330 fptr->
encs.
ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
7341 else if (
ARGF.next_p == -1) {
7345 rb_warn(
"Can't do inplace edit for stdio");
7625 volatile VALUE port;
7640 #ifdef HAVE_SYS_SELECT_H
7641 #include <sys/select.h>
7664 if (max < fptr->fd) max = fptr->
fd;
7675 if (!
NIL_P(write)) {
7681 if (max < fptr->fd) max = fptr->
fd;
7688 if (!
NIL_P(except)) {
7695 if (max < fptr->fd) max = fptr->
fd;
7696 if (io != write_io) {
7699 if (max < fptr->fd) max = fptr->
fd;
7714 if (!pending &&
n == 0)
return Qnil;
7757 else if (io != write_io) {
7797 #ifdef HAVE_POSIX_FADVISE
7798 struct io_advise_struct {
7806 io_advise_internal(
void *
arg)
7808 struct io_advise_struct *ptr =
arg;
7809 return posix_fadvise(ptr->fd, ptr->offset, ptr->len, ptr->advice);
7815 #ifdef POSIX_FADV_NORMAL
7816 if (sym == sym_normal)
7817 return INT2NUM(POSIX_FADV_NORMAL);
7820 #ifdef POSIX_FADV_RANDOM
7821 if (sym == sym_random)
7822 return INT2NUM(POSIX_FADV_RANDOM);
7825 #ifdef POSIX_FADV_SEQUENTIAL
7826 if (sym == sym_sequential)
7827 return INT2NUM(POSIX_FADV_SEQUENTIAL);
7830 #ifdef POSIX_FADV_WILLNEED
7831 if (sym == sym_willneed)
7832 return INT2NUM(POSIX_FADV_WILLNEED);
7835 #ifdef POSIX_FADV_DONTNEED
7836 if (sym == sym_dontneed)
7837 return INT2NUM(POSIX_FADV_DONTNEED);
7840 #ifdef POSIX_FADV_NOREUSE
7841 if (sym == sym_noreuse)
7842 return INT2NUM(POSIX_FADV_NOREUSE);
7852 struct io_advise_struct ias;
7855 num_adv = io_advise_sym_to_const(advice);
7861 if (num_adv ==
Qnil)
7865 ias.advice =
NUM2INT(num_adv);
7866 ias.offset = offset;
7886 if (advice != sym_normal &&
7887 advice != sym_sequential &&
7888 advice != sym_random &&
7889 advice != sym_willneed &&
7890 advice != sym_dontneed &&
7891 advice != sym_noreuse) {
7946 rb_scan_args(argc, argv,
"12", &advice, &offset, &len);
7955 #ifdef HAVE_POSIX_FADVISE
7956 return do_io_advise(fptr, advice, off, l);
8023 if (
NIL_P(timeout)) {
8037 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
8039 #define NUM2IOCTLREQ(num) NUM2ULONG(num)
8042 #define NUM2IOCTLREQ(num) NUM2INT(num)
8073 #define DEFULT_IOCTL_NARG_LEN (256)
8077 linux_iocparm_len(ioctl_req_t
cmd)
8081 if ((cmd & 0xFFFF0000) == 0) {
8086 len = _IOC_SIZE(cmd);
8103 #define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
8107 len = IOCPARM_LEN(cmd);
8108 #elif defined(__linux__)
8109 len = linux_iocparm_len(cmd);
8120 typedef long fcntl_arg_t;
8123 typedef int fcntl_arg_t;
8134 len =
sizeof(fcntl_arg_t);
8142 #ifdef F_DUPFD_CLOEXEC
8143 case F_DUPFD_CLOEXEC:
8144 len =
sizeof(fcntl_arg_t);
8154 len =
sizeof(fcntl_arg_t);
8164 len =
sizeof(fcntl_arg_t);
8174 len =
sizeof(fcntl_arg_t);
8179 len =
sizeof(
struct f_owner_ex);
8184 len =
sizeof(
struct f_owner_ex);
8189 len =
sizeof(
struct flock);
8194 len =
sizeof(
struct flock);
8199 len =
sizeof(
struct flock);
8219 len =
sizeof(fcntl_arg_t);
8229 len =
sizeof(fcntl_arg_t);
8234 len =
sizeof(fcntl_arg_t);
8265 else if (arg ==
Qtrue) {
8347 static VALUE nogvl_fcntl(
void *ptr)
8349 struct fcntl_arg *
arg =
ptr;
8351 #if defined(F_DUPFD)
8352 if (arg->cmd == F_DUPFD)
8355 return (
VALUE)
fcntl(arg->fd, arg->cmd, arg->narg);
8359 do_fcntl(
int fd,
int cmd,
long narg)
8362 struct fcntl_arg arg;
8369 #if defined(F_DUPFD)
8370 if (retval != -1 && cmd == F_DUPFD) {
8390 retval = do_fcntl(fptr->
fd, cmd, narg);
8430 return rb_fcntl(io, req, arg);
8433 #define rb_io_fcntl rb_f_notimplement
8436 #if defined(HAVE_SYSCALL) || defined(HAVE___SYSCALL)
8478 #if SIZEOF_VOIDP == 8 && defined(HAVE___SYSCALL) && SIZEOF_INT != 8
8479 # define SYSCALL __syscall
8480 # define NUM2SYSCALLID(x) NUM2LONG(x)
8481 # define RETVAL2NUM(x) LONG2NUM(x)
8482 # if SIZEOF_LONG == 8
8483 long num, retval = -1;
8484 # elif SIZEOF_LONG_LONG == 8
8485 long long num, retval = -1;
8487 # error ---->> it is asserted that __syscall takes the first argument and returns retval in 64bit signed integer. <<----
8490 # define SYSCALL syscall
8491 # define NUM2SYSCALLID(x) NUM2LONG(x)
8492 # define RETVAL2NUM(x) LONG2NUM(x)
8500 long num, retval = -1;
8502 # define SYSCALL syscall
8503 # define NUM2SYSCALLID(x) NUM2INT(x)
8504 # define RETVAL2NUM(x) INT2NUM(x)
8505 int num, retval = -1;
8510 rb_warning(
"We plan to remove a syscall function at future release. DL(Fiddle) provides safer alternative.");
8518 num = NUM2SYSCALLID(argv[0]); ++
argv;
8519 for (i = argc - 1; i--; ) {
8534 retval = SYSCALL(num);
8537 retval = SYSCALL(num, arg[0]);
8540 retval = SYSCALL(num, arg[0],arg[1]);
8543 retval = SYSCALL(num, arg[0],arg[1],arg[2]);
8546 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3]);
8549 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4]);
8552 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5]);
8555 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6]);
8559 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8563 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8567 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8568 arg[7], arg[8], arg[9]);
8571 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8572 arg[7], arg[8], arg[9], arg[10]);
8575 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8576 arg[7], arg[8], arg[9], arg[10], arg[11]);
8579 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8580 arg[7], arg[8], arg[9], arg[10], arg[11], arg[12]);
8587 return RETVAL2NUM(retval);
8589 #undef NUM2SYSCALLID
8593 #define rb_f_syscall rb_f_notimplement
8730 int pipes[2],
state;
8737 argc =
rb_scan_args(argc, argv,
"02:", &v1, &v2, &opt);
8764 #if DEFAULT_TEXTMODE
8769 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
8776 #if DEFAULT_TEXTMODE
8822 #if SIZEOF_LONG > SIZEOF_INT
8878 int orig_argc =
argc;
8985 if (!
NIL_P(offset)) {
9026 arg.
argc = (argc > 1) ? 1 : 0;
9027 if (!
NIL_P(offset)) {
9042 VALUE string, offset, opt;
9053 int mode = O_WRONLY|O_CREAT;
9057 if (
NIL_P(offset)) mode |= O_TRUNC;
9067 if (!
NIL_P(offset)) {
9191 #if defined(ERESTART)
9252 #ifdef HAVE_SENDFILE
9255 # define USE_SENDFILE
9257 # ifdef HAVE_SYS_SENDFILE_H
9258 # include <sys/sendfile.h>
9264 return sendfile(out_fd, in_fd, offset, (
size_t)count);
9267 # elif 0 || defined(__APPLE__)
9271 # define USE_SENDFILE
9273 # ifdef HAVE_SYS_UIO_H
9274 # include <sys/uio.h>
9278 simple_sendfile(
int out_fd,
int in_fd,
off_t *offset,
off_t count)
9284 r = sendfile(in_fd, out_fd, pos, &count,
NULL, 0);
9287 r = sendfile(in_fd, out_fd, pos, (
size_t)count,
NULL, &sbytes, 0);
9289 if (r != 0 && sbytes == 0)
return -1;
9296 return (ssize_t)sbytes;
9307 struct stat src_stat, dst_stat;
9321 if (!
S_ISREG(src_stat.st_mode))
9330 if ((dst_stat.st_mode & S_IFMT) != S_IFSOCK)
9334 use_pread = src_offset != (
off_t)-1;
9337 if (copy_length == (
off_t)-1) {
9339 copy_length = src_stat.st_size - src_offset;
9349 copy_length = src_stat.st_size - cur;
9354 # if SIZEOF_OFF_T > SIZEOF_SIZE_T
9358 ss = (ssize_t)copy_length;
9361 ss = simple_sendfile(stp->
dst_fd, stp->
src_fd, &src_offset, ss);
9369 if (0 < copy_length) {
9370 goto retry_sendfile;
9375 goto retry_sendfile;
9383 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
9399 goto retry_sendfile;
9401 stp->
syserr =
"sendfile";
9415 return read(fd, buf, count);
9423 if (offset == (
off_t)-1) {
9428 ss = pread(stp->
src_fd, buf, len, offset);
9442 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
9454 stp->
syserr = offset == (
off_t)-1 ?
"read" :
"pread";
9467 ss = write(stp->
dst_fd, buf+off, len);
9500 use_eof = copy_length == (
off_t)-1;
9502 use_pread = src_offset != (
off_t)-1;
9513 src_offset = (
off_t)-1;
9517 while (use_eof || 0 < copy_length) {
9518 if (!use_eof && copy_length < (
off_t)
sizeof(
buf)) {
9519 len = (size_t)copy_length;
9553 ret = nogvl_copy_stream_sendfile(stp);
9570 const int buflen = 16*1024;
9592 l = buflen < rest ? buflen : (
long)rest;
9607 if (off != (
off_t)-1)
9612 stp->
total += numwrote;
9638 VALUE src_io, dst_io;
9639 rb_io_t *src_fptr = 0, *dst_fptr = 0;
9654 if (
NIL_P(src_io)) {
9656 int oflags = O_RDONLY;
9669 src_fd = src_fptr->
fd;
9681 if (
NIL_P(dst_io)) {
9683 int oflags = O_WRONLY|O_CREAT|O_TRUNC;
9701 dst_fd = dst_fptr->fd;
9713 size_t len = src_fptr->
rbuf.
len;
9732 if (dst_fptr &&
io_fflush(dst_fptr) < 0) {
9739 if (src_fd == -1 || dst_fd == -1) {
9806 rb_scan_args(argc, argv,
"22", &src, &dst, &length, &src_offset);
9816 if (
NIL_P(src_offset))
9899 argc =
rb_scan_args(argc, argv,
"11:", &v1, &v2, &opt);
10127 return ARGF.current_file;
10207 if (!
NIL_P(length)) {
10226 if (
NIL_P(str)) str = tmp;
10229 if (
ARGF.next_p != -1) {
10235 else if (argc >= 1) {
10336 if (
ARGF.next_p == -1) {
10674 return ARGF.filename;
10705 return ARGF.current_file;
10765 if (
ARGF.init_p &&
ARGF.next_p == 0) {
10795 if (
ARGF.next_p != -1) {
10898 return ARGF.inplace;
11160 #define rb_intern(str) rb_intern_const(str)
11164 #include <sys/cygwin.h>
11165 static struct __cygwin_perfile pf[] =
11173 cygwin_internal(CW_PERFILE, pf);
11444 #if defined (_WIN32) || defined(__CYGWIN__)
11464 #if defined(O_NDELAY) || defined(O_NONBLOCK)
11465 # ifndef O_NONBLOCK
11466 # define O_NONBLOCK O_NDELAY
11478 # define O_BINARY 0
#define STRNCASECMP(s1, s2, n)
VALUE rb_thread_blocking_region(rb_blocking_function_t *func, void *data1, rb_unblock_function_t *ubf, void *data2)
void rb_define_global_const(const char *, VALUE)
struct timeval rb_time_interval(VALUE num)
#define RSTRING_LEN(string)
static long NUM2LONG(VALUE x)
VALUE rb_econv_open_exc(const char *senc, const char *denc, int ecflags)
static void make_readconv(rb_io_t *fptr, int size)
static VALUE rb_io_rewind(VALUE io)
const char * rb_econv_asciicompat_encoding(const char *encname)
void rb_thread_atfork_before_exec(void)
static VALUE rb_io_close_read(VALUE io)
VALUE rb_io_addstr(VALUE, VALUE)
VALUE rb_str_locktmp_ensure(VALUE str, VALUE(*func)(VALUE), VALUE arg)
static VALUE rb_obj_display(int argc, VALUE *argv, VALUE self)
static int nogvl_copy_stream_wait_write(struct copy_stream_struct *stp)
static long fcntl_narg_len(int cmd)
static VALUE rb_io_set_lineno(VALUE io, VALUE lineno)
static ID id_set_encoding
#define MBCLEN_CHARFOUND_P(ret)
static VALUE rb_io_open_with_args(int argc, VALUE *argv)
void rb_thread_atfork(void)
#define ECONV_NEWLINE_DECORATOR_WRITE_MASK
static VALUE argf_getpartial(int argc, VALUE *argv, VALUE argf, int nonblock)
static VALUE UINT2NUM(unsigned int v)
VALUE rb_ary_new4(long n, const VALUE *elts)
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,...)
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)
void rb_io_check_readable(rb_io_t *)
size_t strlen(const char *)
static VALUE io_enc_str(VALUE str, rb_io_t *fptr)
void rb_update_max_fd(int fd)
void rb_io_set_nonblock(rb_io_t *fptr)
static VALUE sym_autoclose
void rb_io_synchronized(rb_io_t *)
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)
VALUE rb_io_get_io(VALUE)
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)
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 io_fflush(rb_io_t *)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
int rb_io_modestr_oflags(const char *modestr)
static const char * rb_io_fmode_modestr(int fmode)
static void argf_init(struct argf *p, VALUE v)
static VALUE rb_io_ioctl(int argc, VALUE *argv, VALUE io)
static VALUE argf_inplace_mode_set(VALUE argf, VALUE val)
VALUE rb_f_sprintf(int, const VALUE *)
size_t rb_econv_memsize(rb_econv_t *)
static void must_respond_to(ID mid, VALUE val, ID id)
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
static VALUE io_s_write(int argc, VALUE *argv, int binary)
void rb_file_const(const char *name, VALUE value)
static VALUE select_call(VALUE arg)
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)
rb_hash_aset(CALLBACK_TABLE, id_num, cmd)
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)
static VALUE rb_io_write_nonblock(VALUE io, VALUE str)
#define ENC_CODERANGE_SET(obj, cr)
void rb_io_check_initialized(rb_io_t *)
#define READ_DATA_PENDING_COUNT(fptr)
VALUE rb_ary_shift(VALUE ary)
#define rb_block_call(arg1, arg2, arg3, arg4, arg5, arg6)
#define ECONV_ERROR_HANDLER_MASK
static VALUE io_s_foreach(struct foreach_arg *arg)
void rb_write_error2(const char *, long)
rb_encoding * rb_to_encoding(VALUE enc)
void rb_econv_close(rb_econv_t *ec)
static VALUE io_flush_buffer_async(VALUE arg)
ssize_t rb_io_bufwrite(VALUE io, const void *buf, size_t size)
static VALUE io_binwrite_string(VALUE arg)
VALUE rb_str_unlocktmp(VALUE)
static void io_encoding_set(rb_io_t *, VALUE, VALUE, VALUE)
static VALUE rb_io_syswrite(VALUE io, VALUE str)
#define FMODE_WSPLIT_INITIALIZED
VALUE rb_enc_from_encoding(rb_encoding *encoding)
ID rb_frame_this_func(void)
static VALUE argf_external_encoding(VALUE argf)
SOCKET rb_w32_get_osfhandle(int)
RUBY_EXTERN VALUE rb_stdin
static VALUE argf_each_line(int argc, VALUE *argv, VALUE argf)
static VALUE rb_io_close_write(VALUE io)
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_io_check_byte_readable(rb_io_t *fptr)
void rb_close_before_exec(int lowfd, int maxhint, VALUE noclose_fds)
static VALUE opt_i_get(ID id, VALUE *var)
int rb_thread_alone(void)
VALUE rb_io_ungetc(VALUE, VALUE)
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)
static VALUE INT2NUM(int v)
int rb_thread_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *)
static VALUE rb_io_getline_fast(rb_io_t *fptr, rb_encoding *enc, VALUE io)
static VALUE rb_io_sync(VALUE io)
int writeconv_pre_ecflags
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
#define RSTRING_PTR(string)
static VALUE rb_io_readchar(VALUE io)
int rb_enc_str_coderange(VALUE)
int rb_io_modestr_fmode(const char *modestr)
static VALUE argf_write(VALUE argf, VALUE str)
static int rb_sysopen_internal(struct sysopen_struct *data)
void rb_raise(VALUE exc, const char *fmt,...)
int rb_io_fptr_finalize(rb_io_t *)
static VALUE rb_io_sysseek(int argc, VALUE *argv, VALUE io)
#define SET_BINARY_MODE_WITH_SEEK_CUR(fptr)
int writeconv_initialized
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
VALUE rb_io_getbyte(VALUE)
VALUE rb_ary_clear(VALUE ary)
static void pipe_add_fptr(rb_io_t *fptr)
VALUE rb_io_taint_check(VALUE)
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 argf_write_io(VALUE argf)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
static int ruby_dup(int orig)
#define ENCODING_MAXNAMELEN
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
#define RARRAY_LEN(ARRAY)
#define STDIO_READ_DATA_PENDING(fp)
void rb_include_module(VALUE klass, VALUE module)
#define MORE_CHAR_FINISHED
void rb_syswait(rb_pid_t pid)
static VALUE more_char(rb_io_t *fptr)
static VALUE rb_io_s_sysopen(int argc, VALUE *argv)
static VALUE argf_lineno(VALUE argf)
VALUE rb_io_write(VALUE, VALUE)
VALUE rb_file_open_str(VALUE, const char *)
static void prepare_getline_args(int argc, VALUE *argv, VALUE *rsp, long *limit, VALUE io)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
static VALUE rb_file_open_generic(VALUE io, VALUE filename, int oflags, int fmode, convconfig_t *convconfig, mode_t perm)
static VALUE internal_write_func(void *ptr)
static VALUE rb_io_each_byte(VALUE io)
VALUE writeconv_pre_ecopts
static void argf_close(VALUE file)
static void open_key_args(int argc, VALUE *argv, VALUE opt, struct foreach_arg *arg)
static VALUE argf_readchar(VALUE argf)
static int max_file_descriptor
static VALUE rb_io_external_encoding(VALUE io)
static VALUE rb_f_readlines(int argc, VALUE *argv, VALUE recv)
static int argf_next_argv(VALUE argf)
VALUE rb_str_tmp_new(long)
VALUE rb_check_to_integer(VALUE, const char *)
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)
void rb_io_read_check(rb_io_t *)
static VALUE nogvl_copy_stream_func(void *arg)
#define GetOpenFile(obj, fp)
static VALUE nogvl_ioctl(void *ptr)
static void validate_enc_binmode(int *fmode_p, int ecflags, rb_encoding *enc, rb_encoding *enc2)
static VALUE rb_io_tell(VALUE io)
static void io_check_tty(rb_io_t *fptr)
#define ENC_CODERANGE_7BIT
const char * rb_obj_classname(VALUE)
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)
static VALUE read_all(rb_io_t *fptr, long siz, VALUE str)
static void * exec_interrupts(void *arg)
VALUE rb_str_buf_cat(VALUE, const char *, long)
void rb_thread_fd_close(int)
static VALUE rb_io_set_autoclose(VALUE io, VALUE autoclose)
#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)
static VALUE rb_io_s_popen(int argc, VALUE *argv, VALUE klass)
rb_pid_t rb_fork(int *, int(*)(void *), void *, VALUE)
void rb_exc_raise(VALUE mesg)
#define SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(enc2, ecflags)
#define rb_io_set_close_on_exec
static VALUE rb_io_sysread(int argc, VALUE *argv, VALUE io)
static void io_ungetbyte(VALUE str, rb_io_t *fptr)
#define RB_TYPE_P(obj, type)
static VALUE rb_file_open_internal(VALUE io, VALUE filename, const char *modestr)
return rb_str_append(rb_str_new2(cmd_id_head), id_num)
void rb_write_error(const char *)
static int str_end_with_asciichar(VALUE str, int c)
static VALUE argf_binmode_m(VALUE argf)
VALUE rb_file_open(const char *, const char *)
int rb_thread_fd_writable(int)
VALUE rb_econv_make_exception(rb_econv_t *ec)
#define MEMZERO(p, type, n)
static VALUE pipe_open(struct rb_exec_arg *eargp, VALUE prog, const char *modestr, int fmode, convconfig_t *convconfig)
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)
RUBY_EXTERN VALUE rb_mWaitReadable
RUBY_EXTERN VALUE rb_output_rs
void rb_str_setter(VALUE, ID, VALUE *)
memset(y->frac+ix+1, 0,(y->Prec-(ix+1))*sizeof(BDIGIT))
void rb_maygvl_fd_fix_cloexec(int fd)
VALUE rb_rescue(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2)
static VALUE copy_stream_fallback_body(VALUE arg)
void rb_thread_sleep(int)
VALUE rb_class_new_instance(int, VALUE *, VALUE)
#define ECONV_NEWLINE_DECORATOR_READ_MASK
VALUE rb_io_get_write_io(VALUE io)
VALUE rb_class_name(VALUE)
int rb_block_given_p(void)
void rb_io_unbuffered(rb_io_t *fptr)
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)
#define rb_sys_fail_path(path)
static void stdout_setter(VALUE val, ID id, VALUE *variable)
RUBY_EXTERN VALUE rb_cObject
static VALUE rb_f_backquote(VALUE obj, VALUE str)
#define PREP_STDIO_NAME(f)
static struct pipe_list * pipe_list
static VALUE argf_readlines(int, VALUE *, VALUE)
static VALUE argf_getline(int argc, VALUE *argv, VALUE argf)
#define FMODE_SETENC_BY_BOM
#define MBCLEN_NEEDMORE_P(ret)
static VALUE rb_io_s_binread(int argc, VALUE *argv, VALUE io)
void ruby_set_inplace_mode(const char *)
char * ruby_strdup(const char *)
static VALUE io_flush_buffer_sync(void *arg)
rb_pid_t rb_w32_spawn(int, const char *, const char *)
static int io_strip_bom(VALUE io)
static void mode_enc(rb_io_t *fptr, const char *estr)
VALUE rb_str_cat2(VALUE, const char *)
VALUE rb_obj_as_string(VALUE)
static VALUE io_s_readlines(struct foreach_arg *arg)
#define ECONV_STATEFUL_DECORATOR_MASK
static ssize_t maygvl_copy_stream_read(int has_gvl, struct copy_stream_struct *stp, char *buf, size_t len, off_t offset)
VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd)
rb_econv_t * rb_econv_open_opts(const char *source_encoding, const char *destination_encoding, int ecflags, VALUE ecopts)
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
#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)
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)
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)
void rb_define_const(VALUE, const char *, VALUE)
int rb_io_wait_writable(int)
static VALUE select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fdset_t *fds)
#define NEWOBJ(obj, type)
static VALUE rb_io_each_char(VALUE io)
void rb_lastline_set(VALUE)
static VALUE rb_io_getline(int argc, VALUE *argv, VALUE io)
struct rb_io_t::rb_io_enc_t encs
#define NUM2IOCTLREQ(num)
#define READ_DATA_PENDING(fptr)
VALUE writeconv_asciicompat
static VALUE finish_writeconv(rb_io_t *fptr, int noalloc)
#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)
#define RUBY_FUNC_EXPORTED
ssize_t rb_io_bufread(VALUE io, void *buf, size_t size)
unsigned char buf[MIME_BUF_SIZE]
static VALUE argf_eof(VALUE argf)
#define ENC_CODERANGE_BROKEN
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)
STATIC void C_block perm[64/CHUNKBITS][1<< CHUNKBITS]
#define rb_enc_mbminlen(enc)
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)
static void rb_io_ext_int_to_encs(rb_encoding *ext, rb_encoding *intern, rb_encoding **enc, rb_encoding **enc2)
static VALUE argf_initialize(VALUE argf, VALUE argv)
#define ENC_CODERANGE_VALID
static VALUE io_getpartial(int argc, VALUE *argv, VALUE io, int nonblock)
static VALUE rb_io_seek_m(int argc, VALUE *argv, VALUE io)
rb_pid_t rb_fork_err(int *, int(*)(void *, char *, size_t), void *, VALUE, char *, size_t)
VALUE rb_str_resize(VALUE, long)
VALUE rb_io_binmode(VALUE)
static void io_set_encoding_by_bom(VALUE io)
static void advice_arg_check(VALUE advice)
int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc)
static VALUE argf_alloc(VALUE klass)
#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.
static VALUE rb_f_gets(int argc, VALUE *argv, VALUE recv)
VALUE rb_io_fdopen(int, int, const char *)
int rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p)
void rb_define_readonly_variable(const char *, VALUE *)
static VALUE copy_stream_body(VALUE arg)
static VALUE seek_before_access(VALUE argp)
static VALUE rb_io_set_pos(VALUE io, VALUE offset)
VALUE rb_funcall2(VALUE, ID, int, const VALUE *)
Calls a method.
static VALUE rb_io_init_copy(VALUE dest, VALUE io)
static void nogvl_copy_stream_read_write(struct copy_stream_struct *stp)
static rb_encoding * io_input_encoding(rb_io_t *fptr)
size_t rb_io_memsize(const rb_io_t *)
static VALUE io_close(VALUE io)
static VALUE rb_io_check_io(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)
static VALUE argf_rewind(VALUE argf)
#define NEED_READCONV(fptr)
static VALUE rb_io_pid(VALUE io)
void rb_fatal(const char *fmt,...)
static VALUE io_s_read(struct foreach_arg *arg)
#define RB_GC_GUARD(object)
VALUE rb_eSystemCallError
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)
int rb_run_exec_options(const struct rb_exec_arg *e, struct rb_exec_arg *s)
static VALUE rb_io_s_for_fd(int argc, VALUE *argv, VALUE klass)
static VALUE rb_f_select(int argc, VALUE *argv, VALUE obj)
#define MEMMOVE(p1, p2, type, n)
RUBY_EXTERN VALUE rb_mWaitWritable
static int wsplit_p(rb_io_t *fptr)
static VALUE rb_io_s_open(int argc, VALUE *argv, VALUE klass)
static VALUE rb_f_print(int argc, VALUE *argv)
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)
static VALUE argf_to_io(VALUE argf)
static void io_unread(rb_io_t *fptr)
VALUE rb_assoc_new(VALUE car, VALUE cdr)
static void rb_scan_open_args(int argc, VALUE *argv, VALUE *fname_p, int *oflags_p, int *fmode_p, convconfig_t *convconfig_p, mode_t *perm_p)
void rb_thread_wait_fd(int)
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)
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)
#define ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(n)
static VALUE argf_readline(int, VALUE *, VALUE)
static VALUE rb_io_s_binwrite(int argc, VALUE *argv, VALUE io)
static void rb_io_mode_enc(rb_io_t *fptr, const char *modestr)
const char * rb_class2name(VALUE)
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)
#define ECONV_NEWLINE_DECORATOR_MASK
int rb_wait_for_single_fd(int fd, int events, struct timeval *tv)
VALUE rb_rescue2(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2,...)
register unsigned int len
int rb_io_oflags_fmode(int oflags)
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 argf_read(int argc, VALUE *argv, VALUE argf)
static VALUE sysopen_func(void *ptr)
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 do_writeconv(VALUE str, rb_io_t *fptr)
static VALUE io_shift_cbuf(rb_io_t *fptr, int len, VALUE *strp)
void rb_sys_fail(const char *mesg)
VALUE rb_io_ungetbyte(VALUE, VALUE)
static VALUE read_internal_call(VALUE arg)
static VALUE pipe_open_v(int argc, VALUE *argv, const char *modestr, int fmode, convconfig_t *convconfig)
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)
VALUE rb_funcall3(VALUE, ID, int, const VALUE *)
Calls a method.
static VALUE rb_io_set_encoding(int argc, VALUE *argv, VALUE io)
int rb_exec_arg_addopt(struct rb_exec_arg *e, VALUE key, VALUE val)
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 Data_Make_Struct(klass, type, mark, free, sval)
#define rb_io_close_on_exec_p
int rb_respond_to(VALUE, ID)
static VALUE bufread_call(VALUE arg)
VALUE rb_define_module_under(VALUE outer, const char *name)
#define StringValueCStr(v)
rb_pid_t rb_w32_aspawn(int, const char *, char *const *)
static VALUE argf_tell(VALUE argf)
RUBY_EXTERN VALUE rb_default_rs
static VALUE argf_each_byte(VALUE argf)
static int do_ioctl(int fd, ioctl_req_t cmd, long narg)
int rb_econv_putbackable(rb_econv_t *ec)
static VALUE argf_filename_getter(ID id, VALUE *var)
static VALUE rb_io_binmode_m(VALUE io)
void rb_str_modify(VALUE)
VALUE rb_usascii_str_new2(const char *)
static VALUE rb_io_isatty(VALUE io)
static long io_fread(VALUE str, long offset, rb_io_t *fptr)
int rb_io_read_pending(rb_io_t *)
#define ENCODING_GET(obj)
rb_encoding * rb_enc_get(VALUE obj)
static VALUE io_s_write0(struct write_arg *arg)
void rb_insecure_operation(void)
static VALUE rb_io_lineno(VALUE io)
static long io_writable_length(rb_io_t *fptr, long l)
void rb_io_check_char_readable(rb_io_t *fptr)
static VALUE io_read(int argc, VALUE *argv, VALUE io)
RUBY_EXTERN VALUE rb_stderr
VALUE rb_hash_lookup2(VALUE hash, VALUE key, VALUE def)
static void pipe_atexit(void)
static VALUE io_new_instance(VALUE args)
static VALUE rb_io_putc(VALUE io, VALUE ch)
#define MBCLEN_INVALID_P(ret)
VALUE rb_exc_new3(VALUE etype, VALUE str)
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 int rb_io_fmode_oflags(int fmode)
static VALUE check_pipe_command(VALUE filename_or_command)
static VALUE rb_io_s_pipe(int argc, VALUE *argv, VALUE klass)
VALUE rb_str_buf_cat_ascii(VALUE, const char *)
static VALUE rb_io_to_io(VALUE io)
static VALUE rb_io_inspect(VALUE obj)
void rb_mod_sys_fail(VALUE mod, const char *mesg)
static VALUE rb_io_s_try_convert(VALUE dummy, VALUE io)
void rb_thread_execute_interrupts(VALUE th)
VALUE rb_check_array_type(VALUE ary)
static void clear_codeconv(rb_io_t *fptr)
void * rb_thread_call_with_gvl(void *(*func)(void *), void *data1)
VALUE rb_hash_aref(VALUE hash, VALUE key)
static void rb_io_fptr_cleanup(rb_io_t *fptr, int noraise)
#define rb_fd_select(n, rfds, wfds, efds, timeout)
static void parse_mode_enc(const char *estr, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p)
VALUE rb_str_catf(VALUE str, const char *format,...)
int rb_exec_err(const struct rb_exec_arg *, char *, size_t)
long rb_w32_write_console(uintptr_t, int)
rb_ivar_set(einfo, ID_at_interp, interp)
VALUE rb_check_string_type(VALUE)
#define is_socket(fd, path)
VALUE rb_io_ascii8bit_binmode(VALUE)
void rb_gvar_readonly_setter(VALUE val, ID id, void *data, struct rb_global_variable *gvar)
RUBY_EXTERN char * strerror(int)
static VALUE argf_each_char(VALUE argf)
static VALUE rb_io_advise(int argc, VALUE *argv, VALUE io)
static VALUE rb_io_getc(VALUE io)
#define rb_str_set_len(str, length)
VALUE rb_str_locktmp(VALUE)
static long io_binwrite(VALUE str, const char *ptr, long len, rb_io_t *fptr, int nosync)
void(* finalize)(struct rb_io_t *, int)
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)
FILE * rb_fdopen(int, const char *)
static rb_io_t * flush_before_seek(rb_io_t *fptr)
static VALUE rb_open_file(int argc, VALUE *argv, VALUE io)
#define rb_enc_left_char_head(s, p, e, enc)
VALUE rb_ary_dup(VALUE ary)
VALUE rb_io_puts(int, VALUE *, VALUE)
void rb_exec_arg_fixup(struct rb_exec_arg *e)
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)
VALUE rb_ary_join(VALUE ary, VALUE sep)
FILE * rb_io_stdio_file(rb_io_t *fptr)
VALUE rb_ary_new2(long capa)
static VALUE io_reopen(VALUE io, VALUE nfile)
static VALUE rb_io_readline(int argc, VALUE *argv, VALUE io)
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
static long ioctl_narg_len(ioctl_req_t cmd)
static VALUE internal_read_func(void *ptr)
void rb_io_check_writable(rb_io_t *)
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)
static char NUM2CHR(VALUE x)
RUBY_EXTERN VALUE rb_eIOError
static VALUE rb_io_readbyte(VALUE io)
const char * rb_id2name(ID id)
#define READ_CHAR_PENDING_PTR(fptr)
return rb_funcall(q->proc, ID_call, 0)
#define MakeOpenFile(obj, fp)
#define StringValuePtr(v)
#define MORE_CHAR_SUSPENDED
RUBY_EXTERN int dup2(int, int)
static VALUE sym_sequential
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 VALUE fill_cbuf(rb_io_t *fptr, int ec_flags)
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
void rb_warning(const char *fmt,...)
int rb_enc_find_index(const char *name)
static VALUE sym_open_args
RUBY_EXTERN VALUE rb_eEOFError
#define rb_check_frozen(obj)
#define NEED_NEWLINE_DECORATOR_ON_READ(fptr)
#define CONST_ID(var, str)
static VALUE rb_io_fileno(VALUE io)
const char * ruby_get_inplace_mode(void)
RUBY_EXTERN VALUE rb_stdout
void rb_stdio_set_default_encoding(void)
#define MODE_BTMODE(a, b, c)
VALUE rb_obj_freeze(VALUE)
static VALUE rb_f_p(int argc, VALUE *argv, VALUE self)
static VALUE argf_forward(int argc, VALUE *argv, VALUE argf)
static VALUE pipe_open_s(VALUE prog, const char *modestr, int fmode, convconfig_t *convconfig)
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)
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)
static VALUE rb_io_getline_1(VALUE rs, long limit, VALUE io)
VALUE rb_str_buf_new(long)
VALUE rb_usascii_str_new(const char *, long)
static VALUE rb_ioctl(VALUE io, VALUE req, VALUE arg)
static VALUE io_read_nonblock(int argc, VALUE *argv, VALUE io)
VALUE rb_io_set_write_io(VALUE io, VALUE w)
static const char * rb_io_oflags_modestr(int oflags)
#define DEFULT_IOCTL_NARG_LEN
static VALUE argf_file(VALUE argf)
static VALUE copy_stream_finalize(VALUE arg)
static VALUE io_getc(rb_io_t *fptr, rb_encoding *enc)
int rb_io_wait_readable(int)
#define READ_CHAR_PENDING(fptr)
static void argf_free(void *ptr)
VALUE rb_io_printf(int, VALUE *, VALUE)
#define READ_DATA_PENDING_PTR(fptr)
static void extract_binmode(VALUE opthash, int *fmode)
static VALUE argf_close_m(VALUE argf)
#define OBJSETUP(obj, c, t)
static VALUE select_end(VALUE arg)
VALUE rb_class_new(VALUE super)
Creates a new class.
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_io_print(int, VALUE *, VALUE)
VALUE rb_str_new2(const char *)
static VALUE rb_io_each_codepoint(VALUE io)
static void pipe_del_fptr(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,...)
void rb_io_check_closed(rb_io_t *)
static VALUE rb_io_s_foreach(int argc, VALUE *argv, VALUE self)
static VALUE rb_io_open(VALUE filename, VALUE vmode, VALUE vperm, VALUE opt)
#define ECONV_UNIVERSAL_NEWLINE_DECORATOR
static VALUE argf_initialize_copy(VALUE argf, VALUE orig)
static VALUE argf_getc(VALUE argf)
void rb_econv_putback(rb_econv_t *ec, unsigned char *p, int n)
static VALUE argf_skip(VALUE argf)
#define SET_BINARY_MODE(fptr)
char * strrchr(const char *, const char)
VALUE rb_exec_arg_init(int argc, VALUE *argv, int accept_shell, struct rb_exec_arg *e)
VALUE rb_econv_str_convert(rb_econv_t *ec, VALUE src, int flags)
static VALUE argf_forward_call(VALUE arg)
void rb_read_check(FILE *fp)
static int io_fillbuf(rb_io_t *fptr)
rb_encoding * rb_enc_from_index(int index)
VALUE rb_obj_class(VALUE)
VALUE rb_str_new(const char *, long)
static VALUE rb_io_s_new(int argc, VALUE *argv, VALUE klass)
static void clear_readconv(rb_io_t *fptr)