24 #define free(x) xfree(x)
26 #if defined(DOSISH) || defined(__CYGWIN__)
30 #include <sys/types.h>
31 #if defined HAVE_NET_SOCKET_H
32 # include <net/socket.h>
33 #elif defined HAVE_SYS_SOCKET_H
34 # ifndef __native_client__
35 # include <sys/socket.h>
39 #if defined(__BOW__) || defined(__CYGWIN__) || defined(_WIN32) || defined(__EMX__) || defined(__BEOS__) || defined(__HAIKU__)
40 # define NO_SAFE_RENAME
43 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__sun) || defined(_nec_ews)
51 #include <sys/types.h>
52 #if defined(HAVE_SYS_IOCTL_H) && !defined(_WIN32)
53 #include <sys/ioctl.h>
55 #if defined(__native_client__) && defined(NACL_NEWLIB)
58 #if defined(HAVE_FCNTL_H) || defined(_WIN32)
60 #elif defined(HAVE_SYS_FCNTL_H)
61 #include <sys/fcntl.h>
64 #if !HAVE_OFF_T && !defined(off_t)
71 #if defined(HAVE_SYS_PARAM_H) && !(defined(__EMX__) || defined(__HIUX_MPP__))
72 # include <sys/param.h>
85 #elif defined HAVE_SYS_SYSCALL_H
86 #include <sys/syscall.h>
89 #if defined(__BEOS__) || defined(__HAIKU__)
91 # define NOFILE (OPEN_MAX)
98 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
101 #if SIZEOF_OFF_T > SIZEOF_LONG && !defined(HAVE_LONG_LONG)
102 # error off_t is bigger than long, but you have no long long...
106 # ifdef _POSIX_PIPE_BUF
107 # define PIPE_BUF _POSIX_PIPE_BUF
109 # define PIPE_BUF 512
113 #if defined(HAVE___SYSCALL) && (defined(__APPLE__) || defined(__OpenBSD__))
115 off_t __syscall(quad_t number, ...);
118 #define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
120 #define IO_RBUF_CAPA_MIN 8192
121 #define IO_CBUF_CAPA_MIN (128*1024)
122 #define IO_RBUF_CAPA_FOR(fptr) (NEED_READCONV(fptr) ? IO_CBUF_CAPA_MIN : IO_RBUF_CAPA_MIN)
123 #define IO_WBUF_CAPA_MIN 8192
128 #define open rb_w32_uopen
170 rb_bug(
"rb_update_max_fd: invalid fd (%d) given.", fd);
182 #if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
183 int flags, flags2, ret;
184 flags =
fcntl(fd, F_GETFD);
189 flags2 = flags & ~FD_CLOEXEC;
191 flags2 = flags | FD_CLOEXEC;
192 if (flags != flags2) {
193 ret =
fcntl(fd, F_SETFD, flags2);
195 rb_bug(
"rb_maygvl_fd_fix_cloexec: fcntl(%d, F_SETFD, %d) failed: %s", fd, flags2,
strerror(
errno));
215 #elif defined O_NOINHERIT
216 flags |= O_NOINHERIT;
218 ret = open(pathname, flags, mode);
219 if (ret == -1)
return -1;
238 if (oldfd == newfd) {
242 #if defined(HAVE_DUP3) && defined(O_CLOEXEC)
243 static int try_dup3 = 1;
244 if (2 < newfd && try_dup3) {
249 if (
errno == ENOSYS) {
251 ret =
dup2(oldfd, newfd);
255 ret =
dup2(oldfd, newfd);
258 ret =
dup2(oldfd, newfd);
260 if (newfd >= 0 && newfd <= 2)
261 SetStdHandle(newfd == 0 ? STD_INPUT_HANDLE : newfd == 1 ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE, (HANDLE)
rb_w32_get_osfhandle(newfd));
264 if (ret == -1)
return -1;
275 #if defined(HAVE_PIPE2)
276 static int try_pipe2 = 1;
282 if (
errno == ENOSYS) {
293 if (ret == -1)
return -1;
295 if (ret == 0 && fildes[1] == -1) {
312 #if defined(HAVE_FCNTL) && defined(F_DUPFD_CLOEXEC) && defined(F_DUPFD)
313 static int try_dupfd_cloexec = 1;
314 if (try_dupfd_cloexec) {
315 ret =
fcntl(fd, F_DUPFD_CLOEXEC, minfd);
322 if (
errno == EINVAL) {
325 try_dupfd_cloexec = 0;
332 #elif defined(HAVE_FCNTL) && defined(F_DUPFD)
334 #elif defined(HAVE_DUP)
336 if (ret != -1 && ret < minfd) {
337 const int prev_fd = ret;
343 # error "dup() or fcntl(F_DUPFD) must be supported."
345 if (ret == -1)
return -1;
350 #define argf_of(obj) (*(struct argf *)DATA_PTR(obj))
351 #define ARGF argf_of(argf)
353 #ifdef _STDIO_USES_IOSTREAM
355 # define STDIO_READ_DATA_PENDING(fp) ((fp)->_IO_read_ptr != (fp)->_IO_read_end)
357 # define STDIO_READ_DATA_PENDING(fp) ((fp)->_gptr < (fp)->_egptr)
359 #elif defined(FILE_COUNT)
360 # define STDIO_READ_DATA_PENDING(fp) ((fp)->FILE_COUNT > 0)
361 #elif defined(FILE_READEND)
362 # define STDIO_READ_DATA_PENDING(fp) ((fp)->FILE_READPTR < (fp)->FILE_READEND)
363 #elif defined(__BEOS__) || defined(__HAIKU__)
364 # define STDIO_READ_DATA_PENDING(fp) ((fp)->_state._eof == 0)
366 # define STDIO_READ_DATA_PENDING(fp) (!feof(fp))
369 #define GetWriteIO(io) rb_io_get_write_io(io)
371 #define READ_DATA_PENDING(fptr) ((fptr)->rbuf.len)
372 #define READ_DATA_PENDING_COUNT(fptr) ((fptr)->rbuf.len)
373 #define READ_DATA_PENDING_PTR(fptr) ((fptr)->rbuf.ptr+(fptr)->rbuf.off)
374 #define READ_DATA_BUFFERED(fptr) READ_DATA_PENDING(fptr)
376 #define READ_CHAR_PENDING(fptr) ((fptr)->cbuf.len)
377 #define READ_CHAR_PENDING_COUNT(fptr) ((fptr)->cbuf.len)
378 #define READ_CHAR_PENDING_PTR(fptr) ((fptr)->cbuf.ptr+(fptr)->cbuf.off)
381 #define WAIT_FD_IN_WIN32(fptr) \
382 (rb_w32_io_cancelable_p((fptr)->fd) ? 0 : rb_thread_wait_fd((fptr)->fd))
384 #define WAIT_FD_IN_WIN32(fptr)
387 #define READ_CHECK(fptr) do {\
388 if (!READ_DATA_PENDING(fptr)) {\
389 WAIT_FD_IN_WIN32(fptr);\
390 rb_io_check_closed(fptr);\
396 # define S_ISSOCK(m) _S_ISSOCK(m)
399 # define S_ISSOCK(m) (((m) & S_IFMT) == _S_IFSOCK)
402 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
408 #define rb_sys_fail_path(path) rb_sys_fail_str(path)
413 #define NEED_NEWLINE_DECORATOR_ON_READ(fptr) ((fptr)->mode & FMODE_TEXTMODE)
414 #define NEED_NEWLINE_DECORATOR_ON_WRITE(fptr) ((fptr)->mode & FMODE_TEXTMODE)
415 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
417 # define DEFAULT_TEXTMODE FMODE_TEXTMODE
418 # define TEXTMODE_NEWLINE_DECORATOR_ON_WRITE ECONV_CRLF_NEWLINE_DECORATOR
426 #define NEED_READCONV(fptr) ((fptr)->encs.enc2 != NULL || (fptr)->encs.ecflags & ~ECONV_CRLF_NEWLINE_DECORATOR)
427 #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)))
428 #define SET_BINARY_MODE(fptr) setmode((fptr)->fd, O_BINARY)
430 #define NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr) do {\
431 if (NEED_NEWLINE_DECORATOR_ON_READ(fptr)) {\
432 if (((fptr)->mode & FMODE_READABLE) &&\
433 !((fptr)->encs.ecflags & ECONV_NEWLINE_DECORATOR_MASK)) {\
434 setmode((fptr)->fd, O_BINARY);\
437 setmode((fptr)->fd, O_TEXT);\
442 #define SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(enc2, ecflags) do {\
443 if ((enc2) && ((ecflags) & ECONV_DEFAULT_NEWLINE_DECORATOR)) {\
444 (ecflags) |= ECONV_UNIVERSAL_NEWLINE_DECORATOR;\
470 if (r < 0 &&
errno) {
482 if (pos < 0 &&
errno) {
489 extra_max = (long)(pos - fptr->
rbuf.
len);
497 for (i = 0; i < fptr->
rbuf.
len; i++) {
498 if (*p ==
'\n') newlines++;
499 if (extra_max == newlines)
break;
504 while (newlines >= 0) {
506 if (newlines == 0)
break;
511 read_size = _read(fptr->
fd, buf, fptr->
rbuf.
len + newlines);
516 if (read_size == fptr->
rbuf.
len) {
538 set_binary_mode_with_seek_cur(
rb_io_t *fptr)
548 #define SET_BINARY_MODE_WITH_SEEK_CUR(fptr) set_binary_mode_with_seek_cur(fptr)
552 # define DEFAULT_TEXTMODE 0
553 #define NEED_READCONV(fptr) ((fptr)->encs.enc2 != NULL || NEED_NEWLINE_DECORATOR_ON_READ(fptr))
554 #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)))
555 #define SET_BINARY_MODE(fptr) (void)(fptr)
556 #define NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr) (void)(fptr)
557 #define SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(enc2, ecflags) ((void)(enc2), (void)(ecflags))
558 #define SET_BINARY_MODE_WITH_SEEK_CUR(fptr) (void)(fptr)
561 #if !defined HAVE_SHUTDOWN && !defined shutdown
562 #define shutdown(a,b) 0
566 #define is_socket(fd, path) rb_w32_is_socket(fd)
567 #elif !defined(S_ISSOCK)
568 #define is_socket(fd, path) 0
574 if (
fstat(fd, &sbuf) < 0)
576 return S_ISSOCK(sbuf.st_mode);
630 write_io =
RFILE(io)->fptr->tied_io_for_writing;
648 write_io =
RFILE(io)->fptr->tied_io_for_writing;
649 RFILE(io)->fptr->tied_io_for_writing = w;
650 return write_io ? write_io :
Qnil;
676 #if !(defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32))
687 if (r < 0 &&
errno) {
709 #if SIZEOF_LONG > SIZEOF_INT
743 #define io_seek(fptr, ofs, whence) (errno = 0, lseek(flush_before_seek(fptr)->fd, (ofs), (whence)))
744 #define io_tell(fptr) lseek(flush_before_seek(fptr)->fd, 0, SEEK_CUR)
872 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
878 #if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(O_NONBLOCK)
884 if (
fstat(fptr->
fd, &buf) == 0 &&
886 #
if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(
O_NONBLOCK)
887 && (r =
fcntl(fptr->
fd, F_GETFL)) != -1 &&
914 return read(iis->
fd, iis->
buf, iis->
capa);
921 return write(iis->
fd, iis->
buf, iis->
capa);
1005 return !result ? (
void*)1 : (
void*)
result;
1028 }
else if (ret == 1) {
1071 #if defined(ERESTART)
1078 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
1097 #if defined(ERESTART)
1113 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
1128 const char *senc, *denc;
1204 long n, r, offset = 0;
1209 if ((n = len) <= 0)
return n;
1246 arg.
ptr = ptr + offset;
1256 if (r == n)
return len;
1280 # define MODE_BTMODE(a,b,c) ((fmode & FMODE_BINMODE) ? (b) : \
1281 (fmode & FMODE_TEXTMODE) ? (c) : (a))
1292 #define fmode (fptr->mode)
1296 rb_raise(
rb_eArgError,
"ASCII incompatible string written for text mode IO without encoding conversion: %s",
1308 if (!
NIL_P(common_encoding)) {
1317 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
1318 #define fmode (fptr->mode)
1325 setmode(fptr->
fd, O_TEXT);
1328 rb_raise(
rb_eArgError,
"ASCII incompatible string written for text mode IO without encoding conversion: %s",
1343 if (len > 0)
return len;
1358 return (ssize_t)
io_binwrite(0, buf, (
long)size, fptr, 0);
1445 nogvl_fsync(
void *
ptr)
1531 pos =
io_seek(fptr, pos, whence);
1561 VALUE offset, ptrname;
1564 if (
rb_scan_args(argc, argv,
"11", &offset, &ptrname) == 2) {
1628 if (io ==
ARGF.current_file) {
1716 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
1814 # define rb_io_fsync rb_f_notimplement
1815 # define rb_io_sync rb_f_notimplement
1824 #ifdef HAVE_FDATASYNC
1826 nogvl_fdatasync(
void *ptr)
1830 return (
VALUE)fdatasync(fptr->
fd);
1862 #define rb_io_fdatasync rb_io_fsync
1933 static const char closed[] =
" (closed)";
1977 if (n <= 0)
return 0;
1978 if (n > len) n = (int)len;
2003 if ((n -= c) <= 0)
break;
2012 if ((n -= c) <= 0)
break;
2061 return (ssize_t)
io_bufread(buf, (
long)size, fptr);
2064 #define SMALLBUF 100
2074 #
if defined(__BEOS__) || defined(__HAIKU__)
2082 if (st.st_size >= pos && pos >= 0) {
2083 siz += st.st_size - pos;
2109 const char *sname, *dname;
2130 #define MORE_CHAR_SUSPENDED Qtrue
2131 #define MORE_CHAR_FINISHED Qnil
2135 const unsigned char *ss, *sp, *se;
2136 unsigned char *ds, *
dp, *de;
2156 ss = sp = (
const unsigned char *)fptr->
rbuf.
ptr + fptr->
rbuf.
off;
2161 fptr->
rbuf.
off += (int)(sp - ss);
2162 fptr->
rbuf.
len -= (int)(sp - ss);
2163 fptr->
cbuf.
len += (int)(dp - ds);
2168 fptr->
rbuf.
off -= putbackable;
2169 fptr->
rbuf.
len += putbackable;
2176 if (cbuf_len0 != fptr->
cbuf.
len)
2193 fptr->
cbuf.
len += (int)(dp - ds);
2200 if (cbuf_len0 != fptr->
cbuf.
len)
2247 len = (len + 1) & ~1L;
2315 if (siz == 0) siz = BUFSIZ;
2319 n =
io_fread(str, bytes, siz - bytes, fptr);
2320 if (n == 0 && bytes == 0) {
2328 if (bytes < siz)
break;
2342 oflags =
fcntl(fptr->
fd, F_GETFL);
2381 if ((len =
NUM2LONG(length)) < 0) {
2710 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
2716 if (
NIL_P(length)) {
2730 if (len == 0)
return str;
2733 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
2734 previous_mode = set_binary_mode_with_seek_cur(fptr);
2738 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
2739 if (previous_mode == O_TEXT) {
2740 setmode(fptr->
fd, O_TEXT);
2743 if (n == 0)
return Qnil;
2772 if (0 < limit && limit < searchlen)
2773 searchlen = (int)limit;
2774 e = memchr(p, delim, searchlen);
2776 int len = (int)(e-p+1);
2815 if (limit > 0 && pending > limit) pending = limit;
2816 e = memchr(p, delim, pending);
2817 if (e) pending = e - p + 1;
2830 if (e)
return delim;
2854 if (*p != term)
return TRUE;
2856 while (--i && *++p == term);
2859 const char *e = p +
cnt;
2861 while ((p += i) < e &&
rb_enc_ascget(p, e, &i, enc) == term);
2877 if (cnt >
sizeof buf) cnt =
sizeof buf;
2878 if (*p != term)
return TRUE;
2880 while (--i && *++p == term);
2904 e = memchr(p,
'\n', pending);
2906 pending = (int)(e - p + 1);
2932 if (io ==
ARGF.current_file) {
2959 else if (2 <= argc) {
2970 if (enc_io != enc_rs &&
2998 if (
NIL_P(rs) && limit < 0) {
3002 else if (limit == 0) {
3011 int c, newline = -1;
3012 const char *rsptr = 0;
3015 int extra_limit = 16;
3039 newline = (
unsigned char)rsptr[rslen - 1];
3043 while ((c =
appendline(fptr, newline, &str, &limit)) !=
EOF) {
3044 const char *s, *
p, *pp, *e;
3052 if (pp != p)
continue;
3053 if (!rspara)
rscheck(rsptr, rslen, rs);
3054 if (
memcmp(p, rsptr, rslen) == 0)
break;
3086 if (io ==
ARGF.current_file) {
3249 VALUE line, ary, rs;
3314 rb_warn(
"IO#lines is deprecated; use #each_line instead");
3368 rb_warn(
"IO#bytes is deprecated; use #each_byte instead");
3522 rb_warn(
"IO#chars is deprecated; use #each_char instead");
3632 rb_warn(
"IO#codepoints is deprecated; use #each_codepoint instead");
3817 #if SIZEOF_LONG > SIZEOF_INT
3859 if (isatty(fptr->
fd) == 0)
3864 #if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
3887 if (io != write_io) {
3889 if (fptr && 0 <= (fd = fptr->
fd)) {
3891 if (!(ret & FD_CLOEXEC))
return Qfalse;
3896 if (fptr && 0 <= (fd = fptr->
fd)) {
3898 if (!(ret & FD_CLOEXEC))
return Qfalse;
3903 #define rb_io_close_on_exec_p rb_f_notimplement
3906 #if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
3930 int flag =
RTEST(arg) ? FD_CLOEXEC : 0;
3936 if (io != write_io) {
3938 if (fptr && 0 <= (fd = fptr->
fd)) {
3940 if ((ret & FD_CLOEXEC) != flag) {
3941 ret = (ret & ~FD_CLOEXEC) | flag;
3942 ret =
fcntl(fd, F_SETFD, ret);
3950 if (fptr && 0 <= (fd = fptr->
fd)) {
3952 if ((ret & FD_CLOEXEC) != flag) {
3953 ret = (ret & ~FD_CLOEXEC) | flag;
3954 ret =
fcntl(fd, F_SETFD, ret);
3961 #define rb_io_set_close_on_exec rb_f_notimplement
3964 #define FMODE_PREP (1<<16)
3965 #define IS_PREP_STDIO(f) ((f)->mode & FMODE_PREP)
3966 #define PREP_STDIO_NAME(f) (RSTRING_PTR((f)->pathv))
3971 unsigned char *ds, *
dp, *de;
3975 unsigned char buf[1024];
3981 de = buf +
sizeof(
buf);
4021 fptr->
wbuf.
len += (int)(dp - ds);
4048 return (
void*)(
intptr_t)close(*fd);
4069 return (
void*)(
intptr_t)fclose(file);
4076 return fclose(file);
4117 else if (stdio_file) {
4131 if (!
NIL_P(err) && !noraise) {
4132 switch (
TYPE(err)) {
4188 if (!fptr)
return 0;
4229 if (io != write_io) {
4230 write_fptr =
RFILE(write_io)->fptr;
4231 if (write_fptr && 0 <= write_fptr->
fd) {
4236 fptr =
RFILE(io)->fptr;
4237 if (!fptr)
return Qnil;
4238 if (fptr->
fd < 0)
return Qnil;
4317 if (io != write_io) {
4318 write_fptr =
RFILE(write_io)->fptr;
4319 if (write_fptr && 0 <= write_fptr->
fd) {
4324 fptr =
RFILE(io)->fptr;
4370 if (io != write_io) {
4375 RFILE(io)->fptr = wfptr;
4437 if (io != write_io) {
4462 VALUE offset, ptrname;
4467 if (
rb_scan_args(argc, argv,
"11", &offset, &ptrname) == 2) {
4477 rb_warn(
"sysseek for buffered IO");
4480 pos = lseek(fptr->
fd, pos, whence);
4516 rb_warn(
"syswrite for buffered IO");
4557 if (ilen == 0)
return str;
4591 if (n == 0 && ilen > 0) {
4706 case FMODE_READWRITE:
4717 static const char bom_prefix[] =
"bom|utf-";
4718 enum {bom_prefix_len = (int)
sizeof(bom_prefix) - 1};
4720 const char *
p =
strchr(name,
':');
4721 len = p ? (long)(p - name) : (long)
strlen(name);
4723 return len > bom_prefix_len &&
STRNCASECMP(name, bom_prefix, bom_prefix_len) == 0;
4730 const char *m = modestr, *
p =
NULL;
4780 switch (oflags & (O_RDONLY|O_WRONLY|O_RDWR)) {
4792 if (oflags & O_APPEND) {
4795 if (oflags & O_TRUNC) {
4798 if (oflags & O_CREAT) {
4822 case FMODE_READWRITE:
4855 # define MODE_BINARY(a,b) ((oflags & O_BINARY) ? (b) : (a))
4857 # define MODE_BINARY(a,b) (a)
4859 int accmode = oflags & (O_RDONLY|O_WRONLY|O_RDWR);
4860 if (oflags & O_APPEND) {
4861 if (accmode == O_WRONLY) {
4864 if (accmode == O_RDWR) {
4868 switch (oflags & (O_RDONLY|O_WRONLY|O_RDWR)) {
4888 int default_ext = 0;
4900 *enc = (default_ext && intern != ext) ?
NULL : ext;
4912 rb_warn(
"Unsupported encoding %s ignored", name);
4921 int fmode = fmode_p ? *fmode_p : 0;
4928 long len = (p++) - estr;
4937 memcpy(encname, estr, len);
4938 encname[
len] =
'\0';
4949 memcpy(encname, estr, len);
4950 encname[
len] =
'\0';
4955 if (fmode_p) *fmode_p =
fmode;
4967 if (*p ==
'-' && *(p+1) ==
'\0') {
4997 if (v !=
Qnil) encoding =
v;
4999 if (v !=
Qnil) extenc =
v;
5006 rb_warn(
"Ignoring encoding parameter '%s': %s_encoding is used",
5008 extenc ==
Qundef ?
"internal" :
"external");
5016 if (
NIL_P(intenc)) {
5023 if (*p ==
'-' && *(p+1) ==
'\0') {
5034 if (extencoding == intencoding) {
5038 if (!
NIL_P(encoding)) {
5059 int fmode = *fmode_p;
5067 if (!(fmode & FMODE_BINMODE) &&
5072 #if !DEFAULT_TEXTMODE
5073 else if (!(ecflags & ECONV_NEWLINE_DECORATOR_MASK)) {
5083 if (!
NIL_P(opthash)) {
5107 int *oflags_p,
int *fmode_p,
convconfig_t *convconfig_p)
5114 int has_enc = 0, has_vmode = 0;
5152 if (
NIL_P(opthash)) {
5156 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
5159 0, TEXTMODE_NEWLINE_DECORATOR_ON_WRITE) : 0;
5174 #if DEFAULT_TEXTMODE
5175 else if (
NIL_P(vmode)) {
5182 if (!
NIL_P(vmode)) {
5193 if (!
NIL_P(*vperm_p)) {
5205 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
5208 0, TEXTMODE_NEWLINE_DECORATOR_ON_WRITE) : 0;
5226 convconfig_p->enc = enc;
5227 convconfig_p->enc2 = enc2;
5228 convconfig_p->ecflags = ecflags;
5229 convconfig_p->ecopts = ecopts;
5287 file = fdopen(fd, modestr);
5298 file = fdopen(fd, modestr);
5303 #elif defined(__sun)
5312 if (setvbuf(file,
NULL, _IOFBF, 0) != 0)
5313 rb_warn(
"setvbuf() can't be honoured (fd=%d)", fd);
5321 if (isatty(fptr->
fd))
5331 VALUE b1, b2, b3, b4;
5420 convconfig->enc, convconfig->enc2);
5424 fptr->
encs = *convconfig;
5437 const char *
p =
strchr(modestr,
':');
5449 convconfig.ecflags = 0;
5450 convconfig.ecopts =
Qnil;
5473 #if defined(__CYGWIN__) || !defined(HAVE_FORK)
5496 if (list->
fptr == fptr) {
5502 while (list->
next) {
5529 #if !defined(HAVE_FORK) && !defined(_WIN32)
5576 #define HAVE_SPAWNV 1
5577 #define spawnv(mode, cmd, args) rb_w32_aspawn((mode), (cmd), (args))
5578 #define spawn(mode, cmd) rb_w32_spawn((mode), (cmd), 0)
5581 #if defined(HAVE_FORK) || defined(HAVE_SPAWNV)
5593 popen_redirect(
struct popen_arg *
p)
5596 close(p->write_pair[1]);
5597 if (p->write_pair[0] != 0) {
5598 dup2(p->write_pair[0], 0);
5599 close(p->write_pair[0]);
5602 if (p->pair[1] != 1) {
5603 dup2(p->pair[1], 1);
5609 if (p->pair[1] != 1) {
5610 dup2(p->pair[1], 1);
5616 if (p->pair[0] != 0) {
5617 dup2(p->pair[0], 0);
5623 #if defined(__linux__)
5634 linux_get_maxfd(
void)
5637 char buf[4096], *
p, *np, *e;
5640 if (fd == -1)
return -1;
5641 ss = read(fd, buf,
sizeof(buf));
5642 if (ss == -1)
goto err;
5645 while ((
int)
sizeof(
"FDSize:\t0\n")-1 <= e-p &&
5646 (np = memchr(p,
'\n', e-p)) !=
NULL) {
5647 if (
memcmp(p,
"FDSize:",
sizeof(
"FDSize:")-1) == 0) {
5649 p +=
sizeof(
"FDSize:")-1;
5673 ret =
fcntl(0, F_MAXFD);
5675 maxhint = max = ret;
5676 #elif defined(__linux__)
5677 ret = linux_get_maxfd();
5684 for (fd = lowfd; fd <=
max; fd++) {
5685 if (!
NIL_P(noclose_fds) &&
5688 ret =
fcntl(fd, F_GETFD);
5689 if (ret != -1 && !(ret & FD_CLOEXEC)) {
5690 fcntl(fd, F_SETFD, ret|FD_CLOEXEC);
5692 #define CONTIGUOUS_CLOSED_FDS 20
5694 if (max < fd + CONTIGUOUS_CLOSED_FDS)
5695 max = fd + CONTIGUOUS_CLOSED_FDS;
5701 popen_exec(
void *pp,
char *errmsg,
size_t errmsg_len)
5703 struct popen_arg *p = (
struct popen_arg*)pp;
5719 #if defined(HAVE_FORK)
5721 char errmsg[80] = {
'\0' };
5723 #if defined(HAVE_FORK) || defined(HAVE_SPAWNV)
5724 struct popen_arg arg;
5727 #if defined(HAVE_SPAWNV)
5728 # if defined(HAVE_SPAWNVE)
5729 # define DO_SPAWN(cmd, args, envp) ((args) ? \
5730 spawnve(P_NOWAIT, (cmd), (args), (envp)) : \
5731 spawne(P_NOWAIT, (cmd), (envp)))
5733 # define DO_SPAWN(cmd, args, envp) ((args) ? \
5734 spawnv(P_NOWAIT, (cmd), (args)) : \
5735 spawn(P_NOWAIT, (cmd)))
5737 # if !defined(HAVE_FORK)
5739 # if defined(HAVE_SPAWNVE)
5744 #if !defined(HAVE_FORK)
5750 #if !defined(HAVE_FORK)
5751 const char *
cmd = 0;
5752 #if !defined(HAVE_SPAWNV)
5761 #if defined(HAVE_FORK) || defined(HAVE_SPAWNV)
5762 arg.execarg_obj = execarg_obj;
5765 arg.pair[0] = arg.pair[1] = -1;
5766 arg.write_pair[0] = arg.write_pair[1] = -1;
5767 # if !defined(HAVE_FORK)
5774 if (
rb_pipe(arg.write_pair) < 0)
5778 close(arg.write_pair[0]);
5779 close(arg.write_pair[1]);
5803 if (!
NIL_P(execarg_obj)) {
5805 # if defined(HAVE_FORK)
5809 # if defined(HAVE_SPAWNVE)
5812 while ((pid = DO_SPAWN(cmd, args, envp)) == -1) {
5814 switch (e =
errno) {
5816 # if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
5829 # if defined(HAVE_FORK)
5833 popen_redirect(&arg);
5845 # if defined(HAVE_FORK)
5851 close(arg.write_pair[0]);
5852 close(arg.write_pair[1]);
5855 # if defined(HAVE_FORK)
5864 close(arg.write_pair[0]);
5865 write_fd = arg.write_pair[1];
5867 else if (fmode & FMODE_READABLE) {
5880 if (!
NIL_P(execarg_obj)) {
5884 fp = popen(cmd, modestr);
5897 fptr->
encs = *convconfig;
5898 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
5908 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
5910 fptr->
encs.
ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
5916 if (0 <= write_fd) {
5919 write_fptr->
fd = write_fd;
5921 fptr->
mode &= ~FMODE_WRITABLE;
5926 #if defined (__CYGWIN__) || !defined(HAVE_FORK)
5937 #if !defined(HAVE_FORK)
5939 "fork() function is unimplemented on this machine");
5956 return pipe_open(execarg_obj, modestr, fmode, convconfig);
6050 const char *modestr;
6065 int ex = !
NIL_P(opt);
6073 #if SIZEOF_LONG > SIZEOF_INT
6074 if (len > INT_MAX) {
6089 if (!
NIL_P(execarg_obj)) {
6098 port =
pipe_open(execarg_obj, modestr, fmode, &convconfig);
6109 RBASIC(port)->klass = klass;
6118 VALUE *fname_p,
int *oflags_p,
int *fmode_p,
6121 VALUE opt, fname, vmode, vperm;
6125 argc =
rb_scan_args(argc, argv,
"12:", &fname, &vmode, &vperm, &opt);
6214 VALUE fname, vmode, vperm;
6219 rb_scan_args(argc, argv,
"12", &fname, &vmode, &vperm);
6230 if (
NIL_P(vperm)) perm = 0666;
6356 int redirect =
FALSE;
6364 VALUE tmp = argv[0];
6405 oflags, fmode, &convconfig, perm);
6434 if (fptr == orig)
return io;
6440 "%s can't change access mode from \"%s\" to \"%s\"",
6467 #
if defined (__CYGWIN__) || !defined(HAVE_FORK)
6528 VALUE fname, nmode, opt;
6533 if (
rb_scan_args(argc, argv,
"11:", &fname, &nmode, &opt) == 1) {
6542 fptr =
RFILE(file)->fptr;
6555 (fptr->
mode & FMODE_READWRITE)) {
6557 "%s can't change access mode from \"%s\" to \"%s\"",
6562 fptr->
encs = convconfig;
6595 else if (fptr->
stdio_file == stdout && isatty(fptr->
fd)) {
6601 if (close(fptr->
fd) < 0)
6633 #if defined (__CYGWIN__) || !defined(HAVE_FORK)
6648 if (io != write_io) {
6689 if (argc == 0)
return Qnil;
6737 for (i=0; i<
argc; i++) {
6843 if (len == 0)
return 0;
6845 return ptr[len - 1] ==
c;
6847 return rb_enc_ascget(ptr + ((len - 1) / n) * n, ptr + len, &n, enc) ==
c;
6901 for (i=0; i<
argc; i++) {
6968 for (i=0; i<
argc; i++) {
6974 else if (argc > 1) {
7054 if (fwrite(mesg,
sizeof(
char), (
size_t)len, stderr) < (
size_t)len) {
7076 if (fwrite(
RSTRING_PTR(mesg),
sizeof(
char), len, stderr) < len) {
7131 if (path && strcmp(path,
"-")) klass =
rb_cFile;
7143 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
7144 fptr->
encs.
ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
7315 int fd,
fmode, oflags = O_RDONLY;
7318 #if defined(HAVE_FCNTL) && defined(F_GETFL)
7326 argc =
rb_scan_args(argc, argv,
"11:", &fnum, &vmode, &opt);
7333 #if defined(HAVE_FCNTL) && defined(F_GETFL)
7334 oflags =
fcntl(fd, F_GETFL);
7340 #if defined(HAVE_FCNTL) && defined(F_GETFL)
7356 fp->
encs = convconfig;
7361 else if (
fileno(stdout) == fd)
7363 else if (
fileno(stderr) == fd)
7394 if (
RFILE(io)->fptr) {
7397 if (0 < argc && argc < 3) {
7417 rb_warn(
"%s::new() does not take block; use %s::open() instead",
7480 if (!
RTEST(autoclose))
7490 struct argf *p = ptr;
7500 struct argf *p = ptr;
7508 const struct argf *p = ptr;
7509 size_t size =
sizeof(*p);
7617 #define next_argv() argf_next_argv(argf)
7618 #define ARGF_GENERIC_INPUT_P() \
7619 (ARGF.current_file == rb_stdin && !RB_TYPE_P(ARGF.current_file, T_FILE))
7620 #define ARGF_FORWARD(argc, argv) do {\
7621 if (ARGF_GENERIC_INPUT_P())\
7622 return argf_forward((argc), (argv), argf);\
7624 #define NEXT_ARGF_FORWARD(argc, argv) do {\
7625 if (!next_argv()) return Qnil;\
7626 ARGF_FORWARD((argc), (argv));\
7644 int stdout_binmode = 0;
7653 if (
ARGF.init_p == 0) {
7671 if (
ARGF.next_p == 1) {
7676 if (
strlen(fn) == 1 && fn[0] ==
'-') {
7679 rb_warn(
"Can't do inplace edit for stdio; skipping");
7689 #ifndef NO_SAFE_RENAME
7699 if (*
ARGF.inplace) {
7702 #ifdef NO_SAFE_RENAME
7706 rb_warn(
"Can't rename %s to %s: %s, skipping file",
7713 rb_warn(
"Can't rename %s to %s: %s, skipping file",
7721 #ifdef NO_SAFE_RENAME
7722 rb_fatal(
"Can't do inplace edit without backup");
7724 if (unlink(fn) < 0) {
7725 rb_warn(
"Can't remove %s: %s, skipping file",
7733 #ifndef NO_SAFE_RENAME
7736 fchmod(fw, st.st_mode);
7738 chmod(fn, st.st_mode);
7740 if (st.st_uid!=st2.st_uid || st.st_gid!=st2.st_gid) {
7743 err = fchown(fw, st.st_uid, st.st_gid);
7745 err =
chown(fn, st.st_uid, st.st_gid);
7747 if (err &&
getuid() == 0 && st2.st_uid == 0) {
7749 rb_warn(
"Can't set owner/group of %s to same as %s: %s, skipping file",
7763 if (!
ARGF.binmode) {
7767 if (!
NIL_P(write_io)) {
7773 if (
ARGF.encs.enc) {
7779 if (!
ARGF.binmode) {
7781 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
7782 fptr->
encs.
ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
7793 else if (
ARGF.next_p == -1) {
7797 rb_warn(
"Can't do inplace edit for stdio");
7808 long lineno =
ARGF.lineno;
7829 ARGF.lineno = ++lineno;
7847 ARGF.last_lineno =
ARGF.lineno = n;
8039 long lineno =
ARGF.lineno;
8077 volatile VALUE port;
8093 #ifdef HAVE_SYS_SELECT_H
8094 #include <sys/select.h>
8117 if (max < fptr->fd) max = fptr->
fd;
8128 if (!
NIL_P(write)) {
8134 if (max < fptr->fd) max = fptr->
fd;
8141 if (!
NIL_P(except)) {
8148 if (max < fptr->fd) max = fptr->
fd;
8149 if (io != write_io) {
8152 if (max < fptr->fd) max = fptr->
fd;
8167 if (!pending && n == 0)
return Qnil;
8210 else if (io != write_io) {
8250 #ifdef HAVE_POSIX_FADVISE
8251 struct io_advise_struct {
8259 io_advise_internal(
void *
arg)
8261 struct io_advise_struct *ptr =
arg;
8262 return posix_fadvise(ptr->fd, ptr->offset, ptr->len, ptr->advice);
8268 #ifdef POSIX_FADV_NORMAL
8269 if (sym == sym_normal)
8270 return INT2NUM(POSIX_FADV_NORMAL);
8273 #ifdef POSIX_FADV_RANDOM
8274 if (sym == sym_random)
8275 return INT2NUM(POSIX_FADV_RANDOM);
8278 #ifdef POSIX_FADV_SEQUENTIAL
8279 if (sym == sym_sequential)
8280 return INT2NUM(POSIX_FADV_SEQUENTIAL);
8283 #ifdef POSIX_FADV_WILLNEED
8284 if (sym == sym_willneed)
8285 return INT2NUM(POSIX_FADV_WILLNEED);
8288 #ifdef POSIX_FADV_DONTNEED
8289 if (sym == sym_dontneed)
8290 return INT2NUM(POSIX_FADV_DONTNEED);
8293 #ifdef POSIX_FADV_NOREUSE
8294 if (sym == sym_noreuse)
8295 return INT2NUM(POSIX_FADV_NOREUSE);
8305 struct io_advise_struct ias;
8308 num_adv = io_advise_sym_to_const(advice);
8318 ias.advice =
NUM2INT(num_adv);
8319 ias.offset = offset;
8340 if (advice != sym_normal &&
8341 advice != sym_sequential &&
8342 advice != sym_random &&
8343 advice != sym_willneed &&
8344 advice != sym_dontneed &&
8345 advice != sym_noreuse) {
8396 VALUE advice, offset, len;
8400 rb_scan_args(argc, argv,
"12", &advice, &offset, &len);
8409 #ifdef HAVE_POSIX_FADVISE
8410 return do_io_advise(fptr, advice, off, l);
8412 ((void)off, (
void)l);
8477 if (
NIL_P(timeout)) {
8491 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
8493 # define NUM2IOCTLREQ(num) NUM2ULONG(num)
8496 # define NUM2IOCTLREQ(num) NUM2INT(num)
8528 #define DEFULT_IOCTL_NARG_LEN (256)
8532 linux_iocparm_len(ioctl_req_t
cmd)
8536 if ((cmd & 0xFFFF0000) == 0) {
8541 len = _IOC_SIZE(cmd);
8558 #define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
8562 len = IOCPARM_LEN(cmd);
8563 #elif defined(__linux__)
8564 len = linux_iocparm_len(cmd);
8575 typedef long fcntl_arg_t;
8578 typedef int fcntl_arg_t;
8589 len =
sizeof(fcntl_arg_t);
8597 #ifdef F_DUPFD_CLOEXEC
8598 case F_DUPFD_CLOEXEC:
8599 len =
sizeof(fcntl_arg_t);
8609 len =
sizeof(fcntl_arg_t);
8619 len =
sizeof(fcntl_arg_t);
8629 len =
sizeof(fcntl_arg_t);
8634 len =
sizeof(
struct f_owner_ex);
8639 len =
sizeof(
struct f_owner_ex);
8644 len =
sizeof(
struct flock);
8649 len =
sizeof(
struct flock);
8654 len =
sizeof(
struct flock);
8674 len =
sizeof(fcntl_arg_t);
8684 len =
sizeof(fcntl_arg_t);
8689 len =
sizeof(fcntl_arg_t);
8720 else if (arg ==
Qtrue) {
8804 nogvl_fcntl(
void *ptr)
8806 struct fcntl_arg *
arg = ptr;
8808 #if defined(F_DUPFD)
8812 return (
VALUE)
fcntl(arg->fd, arg->cmd, arg->narg);
8816 do_fcntl(
int fd,
int cmd,
long narg)
8819 struct fcntl_arg arg;
8826 #if defined(F_DUPFD)
8827 if (retval != -1 && cmd ==
F_DUPFD) {
8847 retval = do_fcntl(fptr->
fd, cmd, narg);
8887 return rb_fcntl(io, req, arg);
8890 #define rb_io_fcntl rb_f_notimplement
8893 #if defined(HAVE_SYSCALL) || defined(HAVE___SYSCALL)
8935 #if SIZEOF_VOIDP == 8 && defined(HAVE___SYSCALL) && SIZEOF_INT != 8
8936 # define SYSCALL __syscall
8937 # define NUM2SYSCALLID(x) NUM2LONG(x)
8938 # define RETVAL2NUM(x) LONG2NUM(x)
8939 # if SIZEOF_LONG == 8
8940 long num, retval = -1;
8941 # elif SIZEOF_LONG_LONG == 8
8942 long long num, retval = -1;
8944 # error ---->> it is asserted that __syscall takes the first argument and returns retval in 64bit signed integer. <<----
8946 #elif defined(__linux__)
8947 # define SYSCALL syscall
8948 # define NUM2SYSCALLID(x) NUM2LONG(x)
8949 # define RETVAL2NUM(x) LONG2NUM(x)
8957 long num, retval = -1;
8959 # define SYSCALL syscall
8960 # define NUM2SYSCALLID(x) NUM2INT(x)
8961 # define RETVAL2NUM(x) INT2NUM(x)
8962 int num, retval = -1;
8967 rb_warning(
"We plan to remove a syscall function at future release. DL(Fiddle) provides safer alternative.");
8975 num = NUM2SYSCALLID(argv[0]); ++
argv;
8976 for (i = argc - 1; i--; ) {
8991 retval = SYSCALL(num);
8994 retval = SYSCALL(num, arg[0]);
8997 retval = SYSCALL(num, arg[0],arg[1]);
9000 retval = SYSCALL(num, arg[0],arg[1],arg[2]);
9003 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3]);
9006 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4]);
9009 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5]);
9012 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6]);
9016 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
9020 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
9024 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
9025 arg[7], arg[8], arg[9]);
9028 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
9029 arg[7], arg[8], arg[9], arg[10]);
9032 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
9033 arg[7], arg[8], arg[9], arg[10], arg[11]);
9036 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
9037 arg[7], arg[8], arg[9], arg[10], arg[11], arg[12]);
9044 return RETVAL2NUM(retval);
9046 #undef NUM2SYSCALLID
9050 #define rb_f_syscall rb_f_notimplement
9200 int pipes[2], state;
9207 argc =
rb_scan_args(argc, argv,
"02:", &v1, &v2, &opt);
9234 #if DEFAULT_TEXTMODE
9239 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
9246 #if DEFAULT_TEXTMODE
9292 #if SIZEOF_LONG > SIZEOF_INT
9348 int orig_argc =
argc;
9459 if (!
NIL_P(offset)) {
9500 arg.
argc = (argc > 1) ? 1 : 0;
9501 if (!
NIL_P(offset)) {
9516 VALUE string, offset, opt;
9527 int mode = O_WRONLY|O_CREAT;
9531 if (
NIL_P(offset)) mode |= O_TRUNC;
9541 if (!
NIL_P(offset)) {
9658 #if defined(ERESTART)
9719 #ifdef HAVE_SENDFILE
9722 # define USE_SENDFILE
9724 # ifdef HAVE_SYS_SENDFILE_H
9725 # include <sys/sendfile.h>
9731 return sendfile(out_fd, in_fd, offset, (
size_t)count);
9734 # elif 0 || defined(__APPLE__)
9738 # define USE_SENDFILE
9740 # ifdef HAVE_SYS_UIO_H
9741 # include <sys/uio.h>
9745 simple_sendfile(
int out_fd,
int in_fd,
off_t *offset,
off_t count)
9751 r = sendfile(in_fd, out_fd, pos, &count,
NULL, 0);
9754 r = sendfile(in_fd, out_fd, pos, (
size_t)count,
NULL, &sbytes, 0);
9756 if (r != 0 && sbytes == 0)
return -1;
9763 return (ssize_t)sbytes;
9774 struct stat src_stat, dst_stat;
9788 if (!
S_ISREG(src_stat.st_mode))
9797 if ((dst_stat.st_mode & S_IFMT) != S_IFSOCK)
9801 use_pread = src_offset != (
off_t)-1;
9804 if (copy_length == (
off_t)-1) {
9806 copy_length = src_stat.st_size - src_offset;
9816 copy_length = src_stat.st_size - cur;
9821 # if SIZEOF_OFF_T > SIZEOF_SIZE_T
9825 ss = (ssize_t)copy_length;
9828 ss = simple_sendfile(stp->
dst_fd, stp->
src_fd, &src_offset, ss);
9836 if (0 < copy_length) {
9837 goto retry_sendfile;
9842 goto retry_sendfile;
9850 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
9866 goto retry_sendfile;
9868 stp->
syserr =
"sendfile";
9882 return read(fd, buf, count);
9890 if (offset == (
off_t)-1) {
9895 ss = pread(stp->
src_fd, buf, len, offset);
9909 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
9921 stp->
syserr = offset == (
off_t)-1 ?
"read" :
"pread";
9934 ss = write(stp->
dst_fd, buf+off, len);
9967 use_eof = copy_length == (
off_t)-1;
9969 use_pread = src_offset != (
off_t)-1;
9980 src_offset = (
off_t)-1;
9984 while (use_eof || 0 < copy_length) {
9985 if (!use_eof && copy_length < (
off_t)
sizeof(
buf)) {
9986 len = (size_t)copy_length;
10015 #ifdef USE_SENDFILE
10019 #ifdef USE_SENDFILE
10020 ret = nogvl_copy_stream_sendfile(stp);
10027 #ifdef USE_SENDFILE
10037 const int buflen = 16*1024;
10044 if (stp->
src_fd == -1) {
10059 l = buflen < rest ? buflen : (long)rest;
10061 if (stp->
src_fd == -1) {
10076 if (off != (
off_t)-1)
10081 stp->
total += numwrote;
10107 VALUE src_io, dst_io;
10108 rb_io_t *src_fptr = 0, *dst_fptr = 0;
10123 if (
NIL_P(src_io)) {
10125 int oflags = O_RDONLY;
10127 oflags |= O_NOCTTY;
10130 args[0] = stp->
src;
10138 src_fd = src_fptr->
fd;
10150 if (
NIL_P(dst_io)) {
10152 int oflags = O_WRONLY|O_CREAT|O_TRUNC;
10154 oflags |= O_NOCTTY;
10157 args[0] = stp->
dst;
10170 dst_fd = dst_fptr->fd;
10182 size_t len = src_fptr->
rbuf.
len;
10201 if (dst_fptr &&
io_fflush(dst_fptr) < 0) {
10208 if (src_fd == -1 || dst_fd == -1) {
10276 rb_scan_args(argc, argv,
"22", &src, &dst, &length, &src_offset);
10286 if (
NIL_P(src_offset))
10369 argc =
rb_scan_args(argc, argv,
"11:", &v1, &v2, &opt);
10597 return ARGF.current_file;
10675 VALUE tmp, str, length;
10679 if (!
NIL_P(length)) {
10698 if (
NIL_P(str)) str = tmp;
10701 if (
ARGF.next_p != -1) {
10707 else if (argc >= 1) {
10787 VALUE tmp, str, length;
10811 if (
ARGF.next_p == -1) {
11031 rb_warn(
"ARGF#lines is deprecated; use #each_line instead");
11079 rb_warn(
"ARGF#bytes is deprecated; use #each_byte instead");
11119 rb_warn(
"ARGF#chars is deprecated; use #each_char instead");
11159 rb_warn(
"ARGF#codepoints is deprecated; use #each_codepoint instead");
11191 return ARGF.filename;
11222 return ARGF.current_file;
11282 if (
ARGF.init_p &&
ARGF.next_p == 0) {
11312 if (
ARGF.next_p != -1) {
11415 return ARGF.inplace;
11645 #define rb_intern(str) rb_intern_const(str)
11649 #include <sys/cygwin.h>
11650 static struct __cygwin_perfile pf[] =
11658 cygwin_internal(CW_PERFILE, pf);
11930 #if defined (_WIN32) || defined(__CYGWIN__)
static VALUE argf_bytes(VALUE argf)
#define ARGVSTR2ARGV(argv_str)
#define RB_TYPE_P(obj, type)
static void make_readconv(rb_io_t *fptr, int size)
static VALUE rb_io_rewind(VALUE io)
static VALUE rb_io_close_read(VALUE io)
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)
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
static VALUE rb_io_open_with_args(int argc, VALUE *argv)
static VALUE argf_getpartial(int argc, VALUE *argv, VALUE argf, int nonblock)
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)
void rb_set_class_path(VALUE, VALUE, const char *)
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)
static VALUE rb_io_closed(VALUE io)
size_t strlen(const char *)
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)
static VALUE io_enc_str(VALUE str, rb_io_t *fptr)
void rb_thread_wait_fd(int)
VALUE rb_class_new_instance(int, VALUE *, VALUE)
void rb_io_check_writable(rb_io_t *fptr)
static VALUE sym_autoclose
static long setup_narg(ioctl_req_t cmd, VALUE *argp, int io_p)
static VALUE sym_encoding
const char * rb_obj_classname(VALUE)
VALUE rb_str_buf_cat_ascii(VALUE, const char *)
static VALUE argf_set_pos(VALUE argf, VALUE offset)
static VALUE rb_io_codepoints(VALUE io)
int rb_io_modestr_fmode(const char *modestr)
static VALUE argf_set_lineno(VALUE argf, VALUE val)
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)
static VALUE argf_readpartial(int argc, VALUE *argv, VALUE argf)
#define ECONV_AFTER_OUTPUT
static VALUE io_call_close(VALUE io)
static int max(int a, int b)
static int io_fflush(rb_io_t *)
#define ENCODING_MAXNAMELEN
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.
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)
static VALUE rb_io_ioctl(int argc, VALUE *argv, VALUE io)
static VALUE argf_inplace_mode_set(VALUE argf, VALUE val)
int rb_execarg_run_options(const struct rb_execarg *e, struct rb_execarg *s, char *errmsg, size_t errmsg_buflen)
static VALUE pipe_open(VALUE execarg_obj, const char *modestr, int fmode, convconfig_t *convconfig)
size_t rb_econv_memsize(rb_econv_t *)
static void must_respond_to(ID mid, VALUE val, ID id)
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 argf_readbyte(VALUE argf)
#define ARGF_FORWARD(argc, argv)
static VALUE argf_gets(int, VALUE *, VALUE)
#define rb_usascii_str_new2
#define rb_enc_codepoint(p, e, enc)
VALUE rb_io_binmode(VALUE io)
void rb_syswait(rb_pid_t pid)
static void argf_mark(void *ptr)
static VALUE io_puts_ary(VALUE ary, VALUE out, int recur)
void rb_define_global_const(const char *, VALUE)
static VALUE rb_io_binmode_p(VALUE io)
VALUE rb_str_locktmp(VALUE)
static VALUE rb_io_write_nonblock(VALUE io, VALUE str)
#define rb_check_frozen(obj)
RUBY_EXTERN void * memmove(void *, const void *, size_t)
#define READ_DATA_PENDING_COUNT(fptr)
VALUE rb_ary_shift(VALUE ary)
void * rb_thread_call_without_gvl2(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2)
static VALUE io_s_foreach(struct foreach_arg *arg)
VALUE rb_hash_lookup2(VALUE, VALUE, VALUE)
rb_encoding * rb_to_encoding(VALUE enc)
VALUE rb_str_new_cstr(const char *)
void rb_fd_fix_cloexec(int fd)
static int is_popen_fork(VALUE prog)
static VALUE io_flush_buffer_async(VALUE arg)
static VALUE io_binwrite_string(VALUE arg)
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)
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)
VALUE rb_obj_freeze(VALUE)
void rb_define_hooked_variable(const char *, VALUE *, VALUE(*)(ANYARGS), void(*)(ANYARGS))
static VALUE argf_each_line(int argc, VALUE *argv, VALUE argf)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE rb_execarg_extract_options(VALUE execarg_obj, VALUE opthash)
#define ECONV_NEWLINE_DECORATOR_MASK
unsigned long ruby_strtoul(const char *str, char **endptr, int base)
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)
static VALUE opt_i_get(ID id, VALUE *var)
VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc)
int rb_econv_prepare_options(VALUE opthash, VALUE *ecopts, int ecflags)
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)
VALUE rb_io_print(int argc, VALUE *argv, VALUE out)
static VALUE rb_io_getline_fast(rb_io_t *fptr, rb_encoding *enc, VALUE io)
void rb_lastline_set(VALUE)
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
int writeconv_pre_ecflags
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
#define MBCLEN_NEEDMORE_P(ret)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
static VALUE rb_io_readchar(VALUE io)
static VALUE argf_write(VALUE argf, VALUE str)
static int rb_sysopen_internal(struct sysopen_struct *data)
#define MEMMOVE(p1, p2, type, n)
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
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
VALUE rb_execarg_new(int argc, VALUE *argv, int accept_shell)
VALUE rb_obj_class(VALUE)
#define RETURN_ENUMERATOR(obj, argc, argv)
VALUE rb_ary_clear(VALUE ary)
static void pipe_add_fptr(rb_io_t *fptr)
VALUE rb_str_encode_ospath(VALUE)
VALUE rb_class_name(VALUE)
static VALUE argf_binmode_p(VALUE argf)
#define NEED_WRITECONV(fptr)
#define rb_enc_left_char_head(s, p, e, enc)
static VALUE rb_file_initialize(int argc, VALUE *argv, VALUE io)
static VALUE argf_write_io(VALUE argf)
#define SafeStringValue(v)
int rb_io_modestr_oflags(const char *modestr)
static int ruby_dup(int orig)
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
#define STDIO_READ_DATA_PENDING(fp)
void rb_include_module(VALUE klass, VALUE module)
#define MORE_CHAR_FINISHED
void rb_last_status_clear(void)
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 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)
VALUE rb_lastline_get(void)
static VALUE internal_write_func(void *ptr)
void rb_io_check_initialized(rb_io_t *fptr)
VALUE rb_str_unlocktmp(VALUE)
static VALUE rb_io_each_byte(VALUE io)
VALUE writeconv_pre_ecopts
VALUE rb_str_substr(VALUE, long, long)
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)
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)
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)
#define ENC_CODERANGE_BROKEN
RUBY_FUNC_EXPORTED size_t rb_io_memsize(const rb_io_t *fptr)
#define GetOpenFile(obj, fp)
VALUE rb_io_printf(int argc, VALUE *argv, VALUE out)
static ssize_t rb_write_internal2(int fd, const void *buf, size_t count)
VALUE rb_str_append(VALUE, VALUE)
VALUE rb_str_new_frozen(VALUE)
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_f_p_internal(VALUE arg)
VALUE rb_io_ascii8bit_binmode(VALUE io)
VALUE rb_f_sprintf(int, const VALUE *)
static VALUE rb_io_tell(VALUE io)
void rb_str_modify_expand(VALUE, long)
static void io_check_tty(rb_io_t *fptr)
static VALUE argf_seek_m(int argc, VALUE *argv, VALUE argf)
static void opt_i_set(VALUE val, ID id, VALUE *var)
#define ENCODING_GET(obj)
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)
static VALUE rb_io_set_autoclose(VALUE io, VALUE autoclose)
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)
static VALUE rb_io_lines(int argc, VALUE *argv, VALUE io)
#define MEMZERO(p, type, n)
VALUE rb_enumeratorize(VALUE obj, VALUE meth, int argc, VALUE *argv)
void rb_exc_raise(VALUE mesg)
#define ECONV_ERROR_HANDLER_MASK
#define SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(enc2, ecflags)
#define rb_io_set_close_on_exec
VALUE rb_io_close(VALUE io)
VALUE rb_usascii_str_new(const char *, long)
static VALUE rb_io_sysread(int argc, VALUE *argv, VALUE io)
static void io_ungetbyte(VALUE str, rb_io_t *fptr)
static VALUE rb_file_open_internal(VALUE io, VALUE filename, const char *modestr)
void rb_define_readonly_variable(const char *, VALUE *)
static int str_end_with_asciichar(VALUE str, int c)
static VALUE argf_binmode_m(VALUE argf)
int rb_to_encoding_index(VALUE enc)
rb_encoding * rb_default_external_encoding(void)
void rb_maygvl_fd_fix_cloexec(int fd)
#define rb_fd_select(n, rfds, wfds, efds, timeout)
VALUE rb_rescue(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2)
static VALUE copy_stream_fallback_body(VALUE arg)
static VALUE argf_lines(int argc, VALUE *argv, VALUE argf)
static void * nogvl_close(void *ptr)
int rb_block_given_p(void)
void rb_io_unbuffered(rb_io_t *fptr)
void rb_write_error2(const char *mesg, long len)
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)
static VALUE argf_internal_encoding(VALUE argf)
#define StringValuePtr(v)
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)
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
RUBY_EXTERN VALUE rb_mKernel
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)
static VALUE io_s_readlines(struct foreach_arg *arg)
static ssize_t maygvl_copy_stream_read(int has_gvl, struct copy_stream_struct *stp, char *buf, size_t len, off_t offset)
struct rb_execarg * rb_execarg_get(VALUE execarg_obj)
#define StringValueCStr(v)
VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd)
void rb_econv_binmode(rb_econv_t *ec)
VALUE rb_io_get_write_io(VALUE io)
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()
VALUE rb_io_ungetbyte(VALUE io, VALUE b)
void rb_define_const(VALUE, const char *, VALUE)
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)
VALUE rb_str_cat2(VALUE, const char *)
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)
VALUE rb_check_to_integer(VALUE, const char *)
static VALUE rb_io_each_line(int argc, VALUE *argv, VALUE io)
#define MODE_BINARY(a, b)
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)
void rb_last_status_set(int status, rb_pid_t pid)
rb_atomic_t cnt[RUBY_NSIG]
static VALUE rb_io_each_char(VALUE io)
VALUE rb_io_check_io(VALUE io)
int rb_thread_alone(void)
static VALUE argf_chars(VALUE argf)
static VALUE rb_io_getline(int argc, VALUE *argv, VALUE io)
void rb_gvar_readonly_setter(VALUE val, ID id, void *data, struct rb_global_variable *gvar)
#define MBCLEN_CHARFOUND_P(ret)
struct rb_io_t::rb_io_enc_t encs
void rb_close_before_exec(int lowfd, int maxhint, VALUE noclose_fds)
static void * nogvl_fclose(void *ptr)
#define OBJ_INIT_COPY(obj, orig)
#define NUM2IOCTLREQ(num)
#define READ_DATA_PENDING(fptr)
VALUE writeconv_asciicompat
static VALUE finish_writeconv(rb_io_t *fptr, int noalloc)
VALUE rb_mutex_owned_p(VALUE self)
VALUE rb_check_hash_type(VALUE)
#define NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr)
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)
static void io_setstrbuf(VALUE *str, long len)
void rb_thread_check_ints(void)
static int io_flush_buffer(rb_io_t *fptr)
VALUE rb_io_gets(VALUE io)
int rb_cloexec_dup(int oldfd)
static VALUE rb_f_printf(int argc, VALUE *argv)
static void rscheck(const char *rsptr, long rslen, VALUE rs)
void rb_str_setter(VALUE, ID, VALUE *)
static int nogvl_copy_stream_write(struct copy_stream_struct *stp, char *buf, size_t len)
#define ENC_CODERANGE_SET(obj, cr)
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)
static VALUE io_getpartial(int argc, VALUE *argv, VALUE io, int nonblock)
#define ATOMIC_CAS(var, oldval, newval)
static VALUE rb_io_seek_m(int argc, VALUE *argv, VALUE io)
VALUE rb_str_buf_cat(VALUE, const char *, long)
static void io_set_encoding_by_bom(VALUE io)
static void advice_arg_check(VALUE advice)
rb_encoding * rb_find_encoding(VALUE enc)
VALUE rb_obj_as_string(VALUE)
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)
VALUE rb_hash_aset(VALUE, VALUE, VALUE)
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)
VALUE rb_str_resize(VALUE, long)
void ruby_set_inplace_mode(const char *suffix)
#define rb_enc_mbminlen(enc)
static VALUE copy_stream_body(VALUE arg)
void rb_thread_atfork(void)
VALUE rb_thread_current(void)
static VALUE seek_before_access(VALUE argp)
static VALUE rb_io_set_pos(VALUE io, VALUE offset)
static rb_atomic_t max_file_descriptor
static VALUE rb_io_init_copy(VALUE dest, VALUE io)
static void nogvl_copy_stream_read_write(struct copy_stream_struct *stp)
void rb_econv_close(rb_econv_t *ec)
static rb_encoding * io_input_encoding(rb_io_t *fptr)
static VALUE io_close(VALUE io)
#define MBCLEN_CHARFOUND_LEN(ret)
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)
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)
static VALUE rb_io_readlines(int argc, VALUE *argv, VALUE io)
long rb_str_coderange_scan_restartable(const char *, const char *, rb_encoding *, int *)
static VALUE rb_io_s_for_fd(int argc, VALUE *argv, VALUE klass)
#define CONST_ID(var, str)
static VALUE rb_f_select(int argc, VALUE *argv, VALUE obj)
static VALUE rb_io_chars(VALUE io)
void rb_gc_register_mark_object(VALUE)
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)
void rb_write_error_str(VALUE mesg)
static VALUE argf_to_io(VALUE argf)
VALUE rb_block_call(VALUE, ID, int, VALUE *, VALUE(*)(ANYARGS), VALUE)
static void io_unread(rb_io_t *fptr)
unsigned char buf[MIME_BUF_SIZE]
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)
struct rb_execarg::@77::@79 cmd
union rb_execarg::@77 invoke
VALUE tied_io_for_writing
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)
int rb_exec_async_signal_safe(const struct rb_execarg *e, char *errmsg, size_t errmsg_buflen)
void rb_mutex_allow_trap(VALUE self, int val)
VALUE rb_mutex_synchronize(VALUE mutex, VALUE(*func)(VALUE arg), VALUE arg)
static VALUE argf_readline(int, VALUE *, VALUE)
VALUE rb_str_buf_new(long)
static VALUE rb_io_s_binwrite(int argc, VALUE *argv, VALUE io)
#define ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(n)
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_STATEFUL_DECORATOR_MASK
void rb_io_synchronized(rb_io_t *fptr)
VALUE rb_rescue2(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2,...)
static VALUE rb_io_s_write(int argc, VALUE *argv, VALUE io)
static long io_bufread(char *ptr, long len, rb_io_t *fptr)
rb_econv_t * rb_econv_open_opts(const char *source_encoding, const char *destination_encoding, int ecflags, VALUE ecopts)
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
int memcmp(const void *s1, const void *s2, size_t len)
static VALUE argf_read(int argc, VALUE *argv, VALUE argf)
VALUE rb_econv_open_exc(const char *senc, const char *denc, int ecflags)
#define rb_fd_isset(n, f)
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)
int rb_reserved_fd_p(int fd)
void rb_sys_fail(const char *mesg)
struct rb_execarg::@77::@78 sh
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)
VALUE rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts)
static VALUE rb_io_set_encoding(int argc, VALUE *argv, VALUE io)
#define READ_DATA_BUFFERED(fptr)
#define rb_io_close_on_exec_p
static VALUE bufread_call(VALUE arg)
VALUE rb_define_module_under(VALUE outer, const char *name)
RUBY_EXTERN char * strerror(int)
#define ENC_CODERANGE_VALID
static VALUE argf_tell(VALUE argf)
static VALUE argf_each_byte(VALUE argf)
static size_t argf_memsize(const void *ptr)
RUBY_EXTERN VALUE rb_cFile
static int do_ioctl(int fd, ioctl_req_t cmd, long narg)
const char * rb_class2name(VALUE)
VALUE rb_ivar_set(VALUE, ID, VALUE)
static VALUE argf_codepoints(VALUE argf)
static VALUE argf_filename_getter(ID id, VALUE *var)
void rb_econv_check_error(rb_econv_t *ec)
static VALUE rb_io_binmode_m(VALUE io)
static VALUE rb_io_isatty(VALUE io)
void rb_str_modify(VALUE)
#define NEWOBJ_OF(obj, type, klass, flags)
VALUE rb_str_cat(VALUE, const char *, long)
#define ENC_CODERANGE_7BIT
rb_encoding * rb_enc_get(VALUE obj)
struct timeval rb_time_interval(VALUE num)
static VALUE io_s_write0(struct write_arg *arg)
void rb_insecure_operation(void)
static VALUE io_flush_buffer_async2(VALUE arg)
static VALUE rb_io_lineno(VALUE io)
static long io_writable_length(rb_io_t *fptr, long l)
static VALUE io_read(int argc, VALUE *argv, VALUE io)
static void pipe_atexit(void)
static VALUE io_new_instance(VALUE args)
static VALUE rb_io_putc(VALUE io, VALUE ch)
static VALUE rb_io_bytes(VALUE io)
int rb_method_basic_definition_p(VALUE, ID)
VALUE rb_exc_new3(VALUE etype, VALUE str)
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)
VALUE rb_io_fdopen(int fd, int oflags, const char *path)
static VALUE rb_io_to_io(VALUE io)
static VALUE rb_io_inspect(VALUE obj)
VALUE rb_funcall3(VALUE, ID, int, const VALUE *)
Calls a method.
void rb_mod_sys_fail(VALUE mod, const char *mesg)
void rb_thread_sleep(int)
#define MBCLEN_INVALID_P(ret)
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)
static void rb_io_fptr_cleanup(rb_io_t *fptr, int noraise)
void rb_error_arity(int argc, int min, int max)
static void parse_mode_enc(const char *estr, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p)
#define TypedData_Make_Struct(klass, type, data_type, sval)
VALUE rb_str_catf(VALUE str, const char *format,...)
void rb_syserr_fail_str(int e, VALUE mesg)
void * rb_thread_call_with_gvl(void *(*func)(void *), void *data1)
long rb_w32_write_console(uintptr_t, int)
#define ECONV_PARTIAL_INPUT
rb_pid_t rb_fork_ruby(int *status)
RUBY_EXTERN VALUE rb_cObject
#define is_socket(fd, path)
int rb_thread_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *)
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)
VALUE rb_econv_make_exception(rb_econv_t *ec)
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
void rb_define_variable(const char *, VALUE *)
#define STRNCASECMP(s1, s2, n)
static VALUE rb_io_s_read(int argc, VALUE *argv, VALUE io)
int rb_respond_to(VALUE, ID)
void rb_io_check_readable(rb_io_t *fptr)
FILE * rb_fdopen(int fd, const char *modestr)
static rb_io_t * flush_before_seek(rb_io_t *fptr)
static VALUE rb_open_file(int argc, VALUE *argv, VALUE io)
int rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val)
VALUE rb_ary_dup(VALUE ary)
RUBY_EXTERN int dup2(int, int)
void rb_notimplement(void)
void rb_define_virtual_variable(const char *, VALUE(*)(ANYARGS), void(*)(ANYARGS))
const char * rb_econv_asciicompat_encoding(const char *encname)
void rb_thread_fd_close(int)
VALUE rb_ary_concat(VALUE x, VALUE y)
static long remain_size(rb_io_t *fptr)
VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE)
static VALUE argf_argv_getter(ID id, VALUE *var)
VALUE rb_ary_join(VALUE ary, VALUE sep)
VALUE rb_ary_new2(long capa)
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_str_new(const char *, long)
VALUE rb_io_addstr(VALUE io, VALUE str)
static long ioctl_narg_len(ioctl_req_t cmd)
static VALUE internal_read_func(void *ptr)
#define ECONV_NEWLINE_DECORATOR_READ_MASK
void rb_execarg_setenv(VALUE execarg_obj, VALUE env)
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)
#define ECONV_NEWLINE_DECORATOR_WRITE_MASK
#define rb_enc_asciicompat(enc)
VALUE rb_io_puts(int argc, VALUE *argv, VALUE out)
static VALUE rb_io_readbyte(VALUE io)
VALUE rb_obj_alloc(VALUE)
const char * rb_id2name(ID id)
#define READ_CHAR_PENDING_PTR(fptr)
#define MakeOpenFile(obj, fp)
#define MORE_CHAR_SUSPENDED
static VALUE sym_sequential
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)
VALUE rb_hash_aref(VALUE, VALUE)
VALUE rb_funcall2(VALUE, ID, int, const VALUE *)
Calls a method.
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
#define ECONV_DEFAULT_NEWLINE_DECORATOR
VALUE rb_uninterruptible(VALUE(*b_proc)(ANYARGS), VALUE data)
int rb_io_read_pending(rb_io_t *fptr)
#define NEED_NEWLINE_DECORATOR_ON_READ(fptr)
static VALUE rb_io_fileno(VALUE io)
ssize_t rb_io_bufread(VALUE io, void *buf, size_t size)
#define MODE_BTMODE(a, b, c)
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)
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 RUBY_METHOD_FUNC(func)
#define READ_CHAR_PENDING_COUNT(fptr)
static VALUE rb_io_getline_1(VALUE rs, long limit, VALUE io)
void rb_stdio_set_default_encoding(void)
void rb_io_read_check(rb_io_t *fptr)
static VALUE rb_ioctl(VALUE io, VALUE req, VALUE arg)
static VALUE io_read_nonblock(int argc, VALUE *argv, VALUE io)
static void * nogvl_copy_stream_func(void *arg)
static const char * rb_io_oflags_modestr(int oflags)
#define DEFULT_IOCTL_NARG_LEN
int rb_econv_putbackable(rb_econv_t *ec)
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)
VALUE rb_check_string_type(VALUE)
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)
int rb_enc_str_coderange(VALUE)
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)
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_file_open(const char *fname, const char *modestr)
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_thread_fd_writable(int)
void rb_warn(const char *fmt,...)
static VALUE rb_io_s_foreach(int argc, VALUE *argv, VALUE self)
void rb_econv_putback(rb_econv_t *ec, unsigned char *p, int n)
VALUE rb_econv_str_convert(rb_econv_t *ec, VALUE src, int flags)
static VALUE rb_io_open(VALUE filename, VALUE vmode, VALUE vperm, VALUE opt)
VALUE rb_convert_type(VALUE, int, const char *, const char *)
VALUE rb_check_convert_type(VALUE, int, const char *, const char *)
VALUE rb_io_set_write_io(VALUE io, VALUE w)
static VALUE argf_initialize_copy(VALUE argf, VALUE orig)
VALUE rb_io_ungetc(VALUE io, VALUE c)
static VALUE argf_getc(VALUE argf)
#define ECONV_UNIVERSAL_NEWLINE_DECORATOR
static int maygvl_close(int fd, int keepgvl)
static VALUE argf_skip(VALUE argf)
void rb_io_check_closed(rb_io_t *fptr)
#define SET_BINARY_MODE(fptr)
char * strrchr(const char *, const char)
static int maygvl_fclose(FILE *file, int keepgvl)
static VALUE argf_forward_call(VALUE arg)
void rb_read_check(FILE *fp)
void rb_write_error(const char *mesg)
static int io_fillbuf(rb_io_t *fptr)
int rb_thread_interrupted(VALUE thval)
rb_encoding * rb_enc_from_index(int index)
static void unsupported_encoding(const char *name)
static VALUE rb_io_s_new(int argc, VALUE *argv, VALUE klass)
void rb_execarg_fixup(VALUE execarg_obj)
static void clear_readconv(rb_io_t *fptr)
void rb_str_set_len(VALUE, long)