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 #define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
107 #define IO_RBUF_CAPA_MIN 8192
108 #define IO_CBUF_CAPA_MIN (128*1024)
109 #define IO_RBUF_CAPA_FOR(fptr) (NEED_READCONV(fptr) ? IO_CBUF_CAPA_MIN : IO_RBUF_CAPA_MIN)
110 #define IO_WBUF_CAPA_MIN 8192
115 #define open rb_w32_uopen
155 rb_bug(
"rb_update_max_fd: invalid fd (%d) given.", fd);
165 int flags, flags2, ret;
166 flags =
fcntl(fd, F_GETFD);
171 flags2 = flags & ~FD_CLOEXEC;
173 flags2 = flags | FD_CLOEXEC;
174 if (flags != flags2) {
175 ret =
fcntl(fd, F_SETFD, flags2);
177 rb_bug(
"rb_maygvl_fd_fix_cloexec: fcntl(%d, F_SETFD, %d) failed: %s", fd, flags2,
strerror(
errno));
188 #if defined(HAVE_FCNTL) && defined(F_DUPFD_CLOEXEC)
189 static int try_dupfd_cloexec = 1;
190 if (try_dupfd_cloexec) {
191 ret =
fcntl(fd, F_DUPFD_CLOEXEC, minfd);
198 if (
errno == EINVAL) {
199 ret =
fcntl(fd, F_DUPFD, minfd);
201 try_dupfd_cloexec = 0;
206 ret =
fcntl(fd, F_DUPFD, minfd);
208 #elif defined(F_DUPFD)
209 ret =
fcntl(fd, F_DUPFD, minfd);
214 if (ret == -1)
return -1;
219 #define argf_of(obj) (*(struct argf *)DATA_PTR(obj))
220 #define ARGF argf_of(argf)
222 #ifdef _STDIO_USES_IOSTREAM
224 # define STDIO_READ_DATA_PENDING(fp) ((fp)->_IO_read_ptr != (fp)->_IO_read_end)
226 # define STDIO_READ_DATA_PENDING(fp) ((fp)->_gptr < (fp)->_egptr)
228 #elif defined(FILE_COUNT)
229 # define STDIO_READ_DATA_PENDING(fp) ((fp)->FILE_COUNT > 0)
230 #elif defined(FILE_READEND)
231 # define STDIO_READ_DATA_PENDING(fp) ((fp)->FILE_READPTR < (fp)->FILE_READEND)
232 #elif defined(__BEOS__) || defined(__HAIKU__)
233 # define STDIO_READ_DATA_PENDING(fp) ((fp)->_state._eof == 0)
235 # define STDIO_READ_DATA_PENDING(fp) (!feof(fp))
238 #define GetWriteIO(io) rb_io_get_write_io(io)
240 #define READ_DATA_PENDING(fptr) ((fptr)->rbuf.len)
241 #define READ_DATA_PENDING_COUNT(fptr) ((fptr)->rbuf.len)
242 #define READ_DATA_PENDING_PTR(fptr) ((fptr)->rbuf.ptr+(fptr)->rbuf.off)
243 #define READ_DATA_BUFFERED(fptr) READ_DATA_PENDING(fptr)
245 #define READ_CHAR_PENDING(fptr) ((fptr)->cbuf.len)
246 #define READ_CHAR_PENDING_COUNT(fptr) ((fptr)->cbuf.len)
247 #define READ_CHAR_PENDING_PTR(fptr) ((fptr)->cbuf.ptr+(fptr)->cbuf.off)
250 #define WAIT_FD_IN_WIN32(fptr) \
251 (rb_w32_io_cancelable_p((fptr)->fd) ? 0 : rb_thread_wait_fd((fptr)->fd))
253 #define WAIT_FD_IN_WIN32(fptr)
256 #define READ_CHECK(fptr) do {\
257 if (!READ_DATA_PENDING(fptr)) {\
258 WAIT_FD_IN_WIN32(fptr);\
259 rb_io_check_closed(fptr);\
265 # define S_ISSOCK(m) _S_ISSOCK(m)
268 # define S_ISSOCK(m) (((m) & S_IFMT) == _S_IFSOCK)
271 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
277 #define rb_sys_fail_path(path) rb_sys_fail_str(path)
282 #define NEED_NEWLINE_DECORATOR_ON_READ(fptr) ((fptr)->mode & FMODE_TEXTMODE)
283 #define NEED_NEWLINE_DECORATOR_ON_WRITE(fptr) ((fptr)->mode & FMODE_TEXTMODE)
284 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
286 # define DEFAULT_TEXTMODE FMODE_TEXTMODE
287 # define TEXTMODE_NEWLINE_DECORATOR_ON_WRITE ECONV_CRLF_NEWLINE_DECORATOR
295 #define NEED_READCONV(fptr) ((fptr)->encs.enc2 != NULL || (fptr)->encs.ecflags & ~ECONV_CRLF_NEWLINE_DECORATOR)
296 #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)))
297 #define SET_BINARY_MODE(fptr) setmode((fptr)->fd, O_BINARY)
299 #define NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr) do {\
300 if (NEED_NEWLINE_DECORATOR_ON_READ(fptr)) {\
301 if (((fptr)->mode & FMODE_READABLE) &&\
302 !((fptr)->encs.ecflags & ECONV_NEWLINE_DECORATOR_MASK)) {\
303 setmode((fptr)->fd, O_BINARY);\
306 setmode((fptr)->fd, O_TEXT);\
311 #define SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(enc2, ecflags) do {\
312 if ((enc2) && ((ecflags) & ECONV_DEFAULT_NEWLINE_DECORATOR)) {\
313 (ecflags) |= ECONV_UNIVERSAL_NEWLINE_DECORATOR;\
339 if (r < 0 &&
errno) {
351 if (pos < 0 &&
errno) {
366 for (i = 0; i < fptr->
rbuf.
len; i++) {
367 if (*p ==
'\n') newlines++;
368 if (extra_max == newlines)
break;
373 while (newlines >= 0) {
375 if (newlines == 0)
break;
380 read_size = _read(fptr->
fd, buf, fptr->
rbuf.
len + newlines);
385 if (read_size == fptr->
rbuf.
len) {
407 set_binary_mode_with_seek_cur(
rb_io_t *fptr)
412 return setmode(fptr->
fd, O_BINARY);
415 return setmode(fptr->
fd, O_BINARY);
417 #define SET_BINARY_MODE_WITH_SEEK_CUR(fptr) set_binary_mode_with_seek_cur(fptr)
421 # define DEFAULT_TEXTMODE 0
422 #define NEED_READCONV(fptr) ((fptr)->encs.enc2 != NULL || NEED_NEWLINE_DECORATOR_ON_READ(fptr))
423 #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)))
424 #define SET_BINARY_MODE(fptr) (void)(fptr)
425 #define NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr) (void)(fptr)
426 #define SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(enc2, ecflags) ((void)(enc2), (void)(ecflags))
427 #define SET_BINARY_MODE_WITH_SEEK_CUR(fptr) (void)(fptr)
430 #if !defined HAVE_SHUTDOWN && !defined shutdown
431 #define shutdown(a,b) 0
435 #define is_socket(fd, path) rb_w32_is_socket(fd)
436 #elif !defined(S_ISSOCK)
437 #define is_socket(fd, path) 0
443 if (
fstat(fd, &sbuf) < 0)
445 return S_ISSOCK(sbuf.st_mode);
499 write_io =
RFILE(io)->fptr->tied_io_for_writing;
517 write_io =
RFILE(io)->fptr->tied_io_for_writing;
518 RFILE(io)->fptr->tied_io_for_writing = w;
519 return write_io ? write_io :
Qnil;
545 #if !(defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32))
556 if (r < 0 &&
errno) {
578 #if SIZEOF_LONG > SIZEOF_INT
612 #define io_seek(fptr, ofs, whence) (errno = 0, lseek(flush_before_seek(fptr)->fd, (ofs), (whence)))
613 #define io_tell(fptr) lseek(flush_before_seek(fptr)->fd, 0, SEEK_CUR)
621 #define FMODE_SYNCWRITE (FMODE_SYNC|FMODE_WRITABLE)
660 if (fptr->
encs.enc) {
661 return fptr->
encs.enc;
669 if (fptr->
encs.enc2) {
670 return fptr->
encs.enc2;
744 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
750 #if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(O_NONBLOCK)
756 if (
fstat(fptr->
fd, &buf) == 0 &&
758 #
if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(
O_NONBLOCK)
759 && (r =
fcntl(fptr->
fd, F_GETFL)) != -1 &&
786 return read(iis->
fd, iis->
buf, iis->
capa);
793 return write(iis->
fd, iis->
buf, iis->
capa);
892 #if defined(ERESTART)
899 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
918 #if defined(ERESTART)
925 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
940 const char *senc, *denc;
948 ecopts = fptr->
encs.ecopts;
960 enc = fptr->
encs.enc2 ? fptr->
encs.enc2 : fptr->
encs.enc;
982 ecopts = fptr->
encs.ecopts;
1016 long n, r, offset = 0;
1018 if ((n = len) <= 0)
return n;
1052 arg.
ptr = ptr + offset;
1062 if (r == n)
return len;
1086 # define MODE_BTMODE(a,b,c) ((fmode & FMODE_BINMODE) ? (b) : \
1087 (fmode & FMODE_TEXTMODE) ? (c) : (a))
1098 #define fmode (fptr->mode)
1102 rb_raise(
rb_eArgError,
"ASCII incompatible string written for text mode IO without encoding conversion: %s",
1108 if (fptr->
encs.enc2)
1114 if (!
NIL_P(common_encoding)) {
1123 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
1124 #define fmode (fptr->mode)
1131 setmode(fptr->
fd, O_TEXT);
1134 rb_raise(
rb_eArgError,
"ASCII incompatible string written for text mode IO without encoding conversion: %s",
1149 if (len > 0)
return len;
1164 return (ssize_t)
io_binwrite(0, buf, (
long)size, fptr, 0);
1325 pos =
io_seek(fptr, pos, whence);
1355 VALUE offset, ptrname;
1358 if (
rb_scan_args(argc, argv,
"11", &offset, &ptrname) == 2) {
1420 if (io ==
ARGF.current_file) {
1508 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
1574 static VALUE nogvl_fsync(
void *
ptr)
1612 #define rb_io_fsync rb_f_notimplement
1615 #ifdef HAVE_FDATASYNC
1616 static VALUE nogvl_fdatasync(
void *ptr)
1620 return (
VALUE)fdatasync(fptr->
fd);
1652 #define rb_io_fdatasync rb_io_fsync
1723 static const char closed[] =
" (closed)";
1767 if (n <= 0)
return 0;
1768 if (n > len) n = (int)len;
1793 if ((n -= c) <= 0)
break;
1803 if ((n -= c) <= 0)
break;
1834 return (ssize_t)
io_bufread(buf, (
long)size, fptr);
1837 #define SMALLBUF 100
1847 #
if defined(__BEOS__) || defined(__HAIKU__)
1855 if (st.st_size >= pos && pos >= 0) {
1856 siz += st.st_size - pos;
1882 const char *sname, *dname;
1884 ecopts = fptr->
encs.ecopts;
1885 if (fptr->
encs.enc2) {
1903 #define MORE_CHAR_SUSPENDED Qtrue
1904 #define MORE_CHAR_FINISHED Qnil
1908 const unsigned char *ss, *sp, *se;
1909 unsigned char *ds, *
dp, *de;
1929 ss = sp = (
const unsigned char *)fptr->
rbuf.
ptr + fptr->
rbuf.
off;
1934 fptr->
rbuf.
off += (int)(sp - ss);
1935 fptr->
rbuf.
len -= (int)(sp - ss);
1936 fptr->
cbuf.
len += (int)(dp - ds);
1941 fptr->
rbuf.
off -= putbackable;
1942 fptr->
rbuf.
len += putbackable;
1949 if (cbuf_len0 != fptr->
cbuf.
len)
1966 fptr->
cbuf.
len += (int)(dp - ds);
1973 if (cbuf_len0 != fptr->
cbuf.
len)
2081 if (siz == 0) siz = BUFSIZ;
2086 if (n == 0 && bytes == 0) {
2092 if (bytes < siz)
break;
2107 oflags =
fcntl(fptr->
fd, F_GETFL);
2131 if ((len =
NUM2LONG(length)) < 0) {
2450 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
2456 if (
NIL_P(length)) {
2470 if (len == 0)
return str;
2473 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
2474 previous_mode = set_binary_mode_with_seek_cur(fptr);
2477 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
2478 if (previous_mode == O_TEXT) {
2479 setmode(fptr->
fd, O_TEXT);
2483 if (fptr->
fd < 0)
return Qnil;
2516 if (0 < limit && limit < searchlen)
2517 searchlen = (int)limit;
2518 e = memchr(p, delim, searchlen);
2520 int len = (int)(e-p+1);
2559 if (limit > 0 && pending > limit) pending = limit;
2560 e = memchr(p, delim, pending);
2561 if (e) pending = e - p + 1;
2574 if (e)
return delim;
2598 if (*p != term)
return TRUE;
2600 while (--i && *++p == term);
2603 const char *e = p +
cnt;
2605 while ((p += i) < e &&
rb_enc_ascget(p, e, &i, enc) == term);
2621 if (cnt >
sizeof buf) cnt =
sizeof buf;
2622 if (*p != term)
return TRUE;
2624 while (--i && *++p == term);
2648 e = memchr(p,
'\n', pending);
2650 pending = (int)(e - p + 1);
2676 if (io ==
ARGF.current_file) {
2703 else if (2 <= argc) {
2714 if (enc_io != enc_rs &&
2742 if (
NIL_P(rs) && limit < 0) {
2746 else if (limit == 0) {
2755 int c, newline = -1;
2756 const char *rsptr = 0;
2759 int extra_limit = 16;
2783 newline = (
unsigned char)rsptr[rslen - 1];
2787 while ((c =
appendline(fptr, newline, &str, &limit)) !=
EOF) {
2788 const char *s, *
p, *pp, *e;
2796 if (pp != p)
continue;
2797 if (!rspara)
rscheck(rsptr, rslen, rs);
2798 if (
memcmp(p, rsptr, rslen) == 0)
break;
2830 if (io ==
ARGF.current_file) {
2993 VALUE line, ary, rs;
3299 if (fptr->
encs.enc) {
3518 #if SIZEOF_LONG > SIZEOF_INT
3560 if (isatty(fptr->
fd) == 0)
3565 #if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
3588 if (io != write_io) {
3590 if (fptr && 0 <= (fd = fptr->
fd)) {
3592 if (!(ret & FD_CLOEXEC))
return Qfalse;
3597 if (fptr && 0 <= (fd = fptr->
fd)) {
3599 if (!(ret & FD_CLOEXEC))
return Qfalse;
3604 #define rb_io_close_on_exec_p rb_f_notimplement
3607 #if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
3623 int flag =
RTEST(arg) ? FD_CLOEXEC : 0;
3629 if (io != write_io) {
3631 if (fptr && 0 <= (fd = fptr->
fd)) {
3633 if ((ret & FD_CLOEXEC) != flag) {
3634 ret = (ret & ~FD_CLOEXEC) | flag;
3635 ret =
fcntl(fd, F_SETFD, ret);
3643 if (fptr && 0 <= (fd = fptr->
fd)) {
3645 if ((ret & FD_CLOEXEC) != flag) {
3646 ret = (ret & ~FD_CLOEXEC) | flag;
3647 ret =
fcntl(fd, F_SETFD, ret);
3654 #define rb_io_set_close_on_exec rb_f_notimplement
3657 #define FMODE_PREP (1<<16)
3658 #define IS_PREP_STDIO(f) ((f)->mode & FMODE_PREP)
3659 #define PREP_STDIO_NAME(f) (RSTRING_PTR((f)->pathv))
3664 unsigned char *ds, *
dp, *de;
3668 unsigned char buf[1024];
3674 de = buf +
sizeof(
buf);
3711 fptr->
wbuf.
len += (int)(dp - ds);
3767 else if (0 <= fptr->
fd) {
3771 if (close(fptr->
fd) < 0 &&
NIL_P(err))
3779 if (!
NIL_P(err) && !noraise) {
3836 if (!fptr)
return 0;
3877 if (io != write_io) {
3878 write_fptr =
RFILE(write_io)->fptr;
3879 if (write_fptr && 0 <= write_fptr->
fd) {
3884 fptr =
RFILE(io)->fptr;
3885 if (!fptr)
return Qnil;
3886 if (fptr->
fd < 0)
return Qnil;
3889 #if defined __APPLE__ && defined(__MACH__) && \
3890 (!defined(MAC_OS_X_VERSION_MIN_ALLOWED) || MAC_OS_X_VERSION_MIN_ALLOWED <= 1050)
3970 if (io != write_io) {
3971 write_fptr =
RFILE(write_io)->fptr;
3972 if (write_fptr && 0 <= write_fptr->
fd) {
3977 fptr =
RFILE(io)->fptr;
4023 if (io != write_io) {
4027 RFILE(io)->fptr = wfptr;
4086 if (io != write_io) {
4110 VALUE offset, ptrname;
4115 if (
rb_scan_args(argc, argv,
"11", &offset, &ptrname) == 2) {
4125 rb_warn(
"sysseek for buffered IO");
4128 pos = lseek(fptr->
fd, pos, whence);
4162 rb_warn(
"syswrite for buffered IO");
4202 if (ilen == 0)
return str;
4223 if (n == 0 && ilen > 0) {
4276 fptr->
encs.ecflags = 0;
4337 case FMODE_READWRITE:
4350 static const char bom_prefix[] =
"bom|utf-";
4351 enum {bom_prefix_len = (int)
sizeof(bom_prefix) - 1};
4353 const char *
p =
strchr(name,
':');
4356 return len > bom_prefix_len &&
STRNCASECMP(name, bom_prefix, bom_prefix_len) == 0;
4363 const char *m = modestr, *
p =
NULL;
4413 switch (oflags & (O_RDONLY|O_WRONLY|O_RDWR)) {
4425 if (oflags & O_APPEND) {
4428 if (oflags & O_TRUNC) {
4431 if (oflags & O_CREAT) {
4455 case FMODE_READWRITE:
4488 # define MODE_BINARY(a,b) ((oflags & O_BINARY) ? (b) : (a))
4490 # define MODE_BINARY(a,b) (a)
4492 int accmode = oflags & (O_RDONLY|O_WRONLY|O_RDWR);
4493 if (oflags & O_APPEND) {
4494 if (accmode == O_WRONLY) {
4497 if (accmode == O_RDWR) {
4501 switch (oflags & (O_RDONLY|O_WRONLY|O_RDWR)) {
4521 int default_ext = 0;
4532 *enc = (default_ext && intern != ext) ?
NULL : ext;
4553 long len = (p++) - estr;
4562 memcpy(encname, estr, len);
4563 encname[
len] =
'\0';
4574 memcpy(encname, estr, len);
4575 encname[
len] =
'\0';
4585 rb_warn(
"Unsupported encoding %s ignored", estr);
4591 if (*p ==
'-' && *(p+1) ==
'\0') {
4598 rb_warn(
"Unsupported encoding %s ignored", p);
4599 else if (idx2 == idx) {
4600 rb_warn(
"Ignoring internal encoding %s: it is identical to external encoding %s", p, estr);
4622 const char *
p =
strchr(modestr,
':');
4639 if (v !=
Qnil) encoding =
v;
4641 if (v !=
Qnil) extenc =
v;
4648 rb_warn(
"Ignoring encoding parameter '%s': %s_encoding is used",
4650 extenc ==
Qundef ?
"internal" :
"external");
4658 if (
NIL_P(intenc)) {
4665 if (*p ==
'-' && *(p+1) ==
'\0') {
4676 if (extencoding == intencoding) {
4680 if (!
NIL_P(encoding)) {
4701 int fmode = *fmode_p;
4709 if (!(fmode & FMODE_BINMODE) &&
4714 #if !DEFAULT_TEXTMODE
4715 else if (!(ecflags & ECONV_NEWLINE_DECORATOR_MASK)) {
4725 if (!
NIL_P(opthash)) {
4741 int *oflags_p,
int *fmode_p,
convconfig_t *convconfig_p)
4748 int has_enc = 0, has_vmode = 0;
4786 if (
NIL_P(opthash)) {
4790 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
4793 0, TEXTMODE_NEWLINE_DECORATOR_ON_WRITE) : 0;
4805 #if DEFAULT_TEXTMODE
4806 else if (
NIL_P(vmode)) {
4813 if (!
NIL_P(vmode)) {
4824 if (!
NIL_P(*vperm_p)) {
4836 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
4839 0, TEXTMODE_NEWLINE_DECORATOR_ON_WRITE) : 0;
4857 convconfig_p->enc = enc;
4858 convconfig_p->enc2 = enc2;
4859 convconfig_p->ecflags = ecflags;
4860 convconfig_p->ecopts = ecopts;
4919 file = fdopen(fd, modestr);
4930 file = fdopen(fd, modestr);
4944 if (setvbuf(file,
NULL, _IOFBF, 0) != 0)
4945 rb_warn(
"setvbuf() can't be honoured (fd=%d)", fd);
4953 if (isatty(fptr->
fd))
4963 VALUE b1, b2, b3, b4;
5049 convconfig->enc, convconfig->enc2);
5053 fptr->
encs = *convconfig;
5066 const char *
p =
strchr(modestr,
':');
5078 convconfig.ecflags = 0;
5079 convconfig.ecopts =
Qnil;
5102 #if defined(__CYGWIN__) || !defined(HAVE_FORK)
5125 if (list->
fptr == fptr) {
5131 while (list->
next) {
5158 #if !defined(HAVE_FORK) && !defined(_WIN32)
5213 popen_redirect(
struct popen_arg *
p)
5216 close(p->write_pair[1]);
5217 if (p->write_pair[0] != 0) {
5218 dup2(p->write_pair[0], 0);
5219 close(p->write_pair[0]);
5222 if (p->pair[1] != 1) {
5223 dup2(p->pair[1], 1);
5229 if (p->pair[1] != 1) {
5230 dup2(p->pair[1], 1);
5236 if (p->pair[0] != 0) {
5237 dup2(p->pair[0], 0);
5250 for (fd = lowfd; fd <=
max; fd++) {
5251 if (!
NIL_P(noclose_fds) &&
5255 ret =
fcntl(fd, F_GETFD);
5256 if (ret != -1 && !(ret & FD_CLOEXEC)) {
5257 fcntl(fd, F_SETFD, ret|FD_CLOEXEC);
5262 #define CONTIGUOUS_CLOSED_FDS 20
5264 if (max < fd + CONTIGUOUS_CLOSED_FDS)
5265 max = fd + CONTIGUOUS_CLOSED_FDS;
5271 popen_exec(
void *pp,
char *errmsg,
size_t errmsg_len)
5273 struct popen_arg *p = (
struct popen_arg*)pp;
5288 #if defined(HAVE_FORK)
5290 struct popen_arg arg;
5291 char errmsg[80] = {
'\0' };
5292 #elif defined(_WIN32)
5293 volatile VALUE argbuf;
5295 int pair[2], write_pair[2];
5297 #if !defined(HAVE_FORK)
5303 const char *cmd = 0;
5315 else if (eargp->
argc) {
5326 #if defined(HAVE_FORK)
5329 arg.pair[0] = arg.pair[1] = -1;
5330 arg.write_pair[0] = arg.write_pair[1] = -1;
5333 if (
rb_pipe(arg.write_pair) < 0)
5337 close(arg.write_pair[0]);
5338 close(arg.write_pair[1]);
5364 pid =
rb_fork_err(&status, popen_exec, &arg, arg.execp->redirect_fds, errmsg,
sizeof(errmsg));
5371 popen_redirect(&arg);
5384 close(arg.write_pair[0]);
5385 close(arg.write_pair[1]);
5395 close(arg.write_pair[0]);
5396 write_fd = arg.write_pair[1];
5398 else if (fmode & FMODE_READABLE) {
5406 #elif defined(_WIN32)
5410 if (argc >= (
int)(
FIXNUM_MAX /
sizeof(
char *))) {
5415 for (i = 0; i <
argc; ++
i) {
5420 switch (fmode & (FMODE_READABLE|FMODE_WRITABLE)) {
5421 case FMODE_READABLE|FMODE_WRITABLE:
5426 close(write_pair[0]);
5427 close(write_pair[1]);
5436 case FMODE_READABLE:
5442 case FMODE_WRITABLE:
5455 while ((pid = (args ?
5461 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
5473 if ((fmode & (FMODE_READABLE|FMODE_WRITABLE)) == (FMODE_READABLE|FMODE_WRITABLE)) {
5474 close(write_pair[0]);
5475 close(write_pair[1]);
5488 if ((fmode & FMODE_READABLE) && (fmode & FMODE_WRITABLE)) {
5491 close(write_pair[0]);
5492 write_fd = write_pair[1];
5494 else if (fmode & FMODE_READABLE) {
5511 fp = popen(cmd, modestr);
5524 fptr->
encs = *convconfig;
5525 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
5535 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
5537 fptr->
encs.ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
5543 if (0 <= write_fd) {
5546 write_fptr->
fd = write_fd;
5548 fptr->
mode &= ~FMODE_WRITABLE;
5553 #if defined (__CYGWIN__) || !defined(HAVE_FORK)
5566 return pipe_open(&earg, prog, modestr, fmode, convconfig);
5578 #if !defined(HAVE_FORK)
5580 "fork() function is unimplemented on this machine");
5582 return pipe_open(0, 0, modestr, fmode, convconfig);
5586 return pipe_open(&earg, prog, modestr, fmode, convconfig);
5675 const char *modestr;
5676 VALUE pname, pmode, port, tmp, opt;
5680 argc =
rb_scan_args(argc, argv,
"11:", &pname, &pmode, &opt);
5688 #if SIZEOF_LONG > SIZEOF_INT
5689 if (len > INT_MAX) {
5700 port =
pipe_open_s(pname, modestr, fmode, &convconfig);
5712 RBASIC(port)->klass = klass;
5721 VALUE *fname_p,
int *oflags_p,
int *fmode_p,
5724 VALUE opt, fname, vmode, vperm;
5728 argc =
rb_scan_args(argc, argv,
"12:", &fname, &vmode, &vperm, &opt);
5816 VALUE fname, vmode, vperm;
5821 rb_scan_args(argc, argv,
"12", &fname, &vmode, &vperm);
5832 if (
NIL_P(vperm)) perm = 0666;
5970 int redirect =
FALSE;
5978 VALUE tmp = argv[0];
6019 oflags, fmode, &convconfig, perm);
6048 if (fptr == orig)
return io;
6054 "%s can't change access mode from \"%s\" to \"%s\"",
6081 #
if defined (__CYGWIN__) || !defined(HAVE_FORK)
6091 if (
dup2(fd2, fd) < 0)
6099 if (
dup2(fd2, fd) < 0)
6147 if (
rb_scan_args(argc, argv,
"11", &fname, &nmode) == 1) {
6156 fptr =
RFILE(file)->fptr;
6162 if (!
NIL_P(nmode)) {
6166 (fptr->
mode & FMODE_READWRITE)) {
6168 "%s can't change access mode from \"%s\" to \"%s\"",
6174 fptr->
encs.ecflags = 0;
6203 if (close(fptr->
fd) < 0)
6222 if (dest == io)
return dest;
6235 #if defined (__CYGWIN__) || !defined(HAVE_FORK)
6250 if (io != write_io) {
6291 if (argc == 0)
return Qnil;
6339 for (i=0; i<
argc; i++) {
6445 if (len == 0)
return 0;
6447 return ptr[len - 1] == c;
6449 return rb_enc_ascget(ptr + ((len - 1) / n) * n, ptr + len, &n, enc) == c;
6501 for (i=0; i<
argc; i++) {
6580 for (i=0; i<
argc; i++) {
6586 else if (argc > 1) {
6638 (void)fwrite(mesg,
sizeof(
char),
len, stderr);
6695 if (path && strcmp(path,
"-")) klass =
rb_cFile;
6707 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
6708 fptr->
encs.ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
6821 int fd,
fmode, oflags = O_RDONLY;
6824 #if defined(HAVE_FCNTL) && defined(F_GETFL)
6832 argc =
rb_scan_args(argc, argv,
"11:", &fnum, &vmode, &opt);
6839 #if defined(HAVE_FCNTL) && defined(F_GETFL)
6840 oflags =
fcntl(fd, F_GETFL);
6846 #if defined(HAVE_FCNTL) && defined(F_GETFL)
6862 fp->
encs = convconfig;
6867 else if (
fileno(stdout) == fd)
6869 else if (
fileno(stderr) == fd)
6906 if (
RFILE(io)->fptr) {
6909 if (0 < argc && argc < 3) {
6929 rb_warn(
"%s::new() does not take block; use %s::open() instead",
6992 if (!
RTEST(autoclose))
7002 struct argf *p = ptr;
7012 struct argf *p = ptr;
7113 #define next_argv() argf_next_argv(argf)
7114 #define ARGF_GENERIC_INPUT_P() \
7115 (ARGF.current_file == rb_stdin && TYPE(ARGF.current_file) != T_FILE)
7116 #define ARGF_FORWARD(argc, argv) do {\
7117 if (ARGF_GENERIC_INPUT_P())\
7118 return argf_forward((argc), (argv), argf);\
7120 #define NEXT_ARGF_FORWARD(argc, argv) do {\
7121 if (!next_argv()) return Qnil;\
7122 ARGF_FORWARD((argc), (argv));\
7140 int stdout_binmode = 0;
7149 if (
ARGF.init_p == 0) {
7167 if (
ARGF.next_p == 1) {
7172 if (
strlen(fn) == 1 && fn[0] ==
'-') {
7175 rb_warn(
"Can't do inplace edit for stdio; skipping");
7185 #ifndef NO_SAFE_RENAME
7195 if (*
ARGF.inplace) {
7198 #ifdef NO_SAFE_RENAME
7202 rb_warn(
"Can't rename %s to %s: %s, skipping file",
7209 rb_warn(
"Can't rename %s to %s: %s, skipping file",
7217 #ifdef NO_SAFE_RENAME
7218 rb_fatal(
"Can't do inplace edit without backup");
7220 if (unlink(fn) < 0) {
7221 rb_warn(
"Can't remove %s: %s, skipping file",
7229 #ifndef NO_SAFE_RENAME
7232 fchmod(fw, st.st_mode);
7234 chmod(fn, st.st_mode);
7236 if (st.st_uid!=st2.st_uid || st.st_gid!=st2.st_gid) {
7239 err = fchown(fw, st.st_uid, st.st_gid);
7241 err =
chown(fn, st.st_uid, st.st_gid);
7243 if (err &&
getuid() == 0 && st2.st_uid == 0) {
7245 rb_warn(
"Can't set owner/group of %s to same as %s: %s, skipping file",
7259 if (!
ARGF.binmode) {
7263 if (!
NIL_P(write_io)) {
7269 if (
ARGF.encs.enc) {
7275 if (!
ARGF.binmode) {
7277 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
7278 fptr->
encs.ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
7289 else if (
ARGF.next_p == -1) {
7293 rb_warn(
"Can't do inplace edit for stdio");
7304 long lineno =
ARGF.lineno;
7325 ARGF.lineno = ++lineno;
7343 ARGF.last_lineno =
ARGF.lineno = n;
7535 long lineno =
ARGF.lineno;
7573 volatile VALUE port;
7588 #ifdef HAVE_SYS_SELECT_H
7589 #include <sys/select.h>
7612 if (max < fptr->fd) max = fptr->
fd;
7623 if (!
NIL_P(write)) {
7629 if (max < fptr->fd) max = fptr->
fd;
7636 if (!
NIL_P(except)) {
7643 if (max < fptr->fd) max = fptr->
fd;
7644 if (io != write_io) {
7647 if (max < fptr->fd) max = fptr->
fd;
7662 if (!pending && n == 0)
return Qnil;
7705 else if (io != write_io) {
7745 #ifdef HAVE_POSIX_FADVISE
7746 struct io_advise_struct {
7754 io_advise_internal(
void *
arg)
7756 struct io_advise_struct *ptr =
arg;
7757 return posix_fadvise(ptr->fd, ptr->offset, ptr->len, ptr->advice);
7763 #ifdef POSIX_FADV_NORMAL
7764 if (sym == sym_normal)
7765 return INT2NUM(POSIX_FADV_NORMAL);
7768 #ifdef POSIX_FADV_RANDOM
7769 if (sym == sym_random)
7770 return INT2NUM(POSIX_FADV_RANDOM);
7773 #ifdef POSIX_FADV_SEQUENTIAL
7774 if (sym == sym_sequential)
7775 return INT2NUM(POSIX_FADV_SEQUENTIAL);
7778 #ifdef POSIX_FADV_WILLNEED
7779 if (sym == sym_willneed)
7780 return INT2NUM(POSIX_FADV_WILLNEED);
7783 #ifdef POSIX_FADV_DONTNEED
7784 if (sym == sym_dontneed)
7785 return INT2NUM(POSIX_FADV_DONTNEED);
7788 #ifdef POSIX_FADV_NOREUSE
7789 if (sym == sym_noreuse)
7790 return INT2NUM(POSIX_FADV_NOREUSE);
7800 struct io_advise_struct ias;
7803 num_adv = io_advise_sym_to_const(advice);
7809 if (num_adv ==
Qnil)
7813 ias.advice =
NUM2INT(num_adv);
7814 ias.offset = offset;
7834 if (advice != sym_normal &&
7835 advice != sym_sequential &&
7836 advice != sym_random &&
7837 advice != sym_willneed &&
7838 advice != sym_dontneed &&
7839 advice != sym_noreuse) {
7894 rb_scan_args(argc, argv,
"12", &advice, &offset, &len);
7903 #ifdef HAVE_POSIX_FADVISE
7904 return do_io_advise(fptr, advice, off, l);
7971 if (
NIL_P(timeout)) {
7985 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
7987 #define NUM2IOCTLREQ(num) NUM2ULONG(num)
7990 #define NUM2IOCTLREQ(num) NUM2INT(num)
8021 #define DEFULT_IOCTL_NARG_LEN (256)
8025 linux_iocparm_len(ioctl_req_t
cmd)
8029 if ((cmd & 0xFFFF0000) == 0) {
8034 len = _IOC_SIZE(cmd);
8051 #define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
8055 len = IOCPARM_LEN(cmd);
8056 #elif defined(__linux__)
8057 len = linux_iocparm_len(cmd);
8068 typedef long fcntl_arg_t;
8071 typedef int fcntl_arg_t;
8082 len =
sizeof(fcntl_arg_t);
8090 #ifdef F_DUPFD_CLOEXEC
8091 case F_DUPFD_CLOEXEC:
8092 len =
sizeof(fcntl_arg_t);
8102 len =
sizeof(fcntl_arg_t);
8112 len =
sizeof(fcntl_arg_t);
8122 len =
sizeof(fcntl_arg_t);
8127 len =
sizeof(
struct f_owner_ex);
8132 len =
sizeof(
struct f_owner_ex);
8137 len =
sizeof(
struct flock);
8142 len =
sizeof(
struct flock);
8147 len =
sizeof(
struct flock);
8167 len =
sizeof(fcntl_arg_t);
8177 len =
sizeof(fcntl_arg_t);
8182 len =
sizeof(fcntl_arg_t);
8213 else if (arg ==
Qtrue) {
8295 static VALUE nogvl_fcntl(
void *ptr)
8297 struct fcntl_arg *
arg = ptr;
8299 #if defined(F_DUPFD)
8300 if (arg->cmd == F_DUPFD)
8303 return (
VALUE)
fcntl(arg->fd, arg->cmd, arg->narg);
8307 do_fcntl(
int fd,
int cmd,
long narg)
8310 struct fcntl_arg arg;
8317 #if defined(F_DUPFD)
8318 if (retval != -1 && cmd == F_DUPFD) {
8338 retval = do_fcntl(fptr->
fd, cmd, narg);
8378 return rb_fcntl(io, req, arg);
8381 #define rb_io_fcntl rb_f_notimplement
8384 #if defined(HAVE_SYSCALL) || defined(HAVE___SYSCALL)
8426 #if SIZEOF_VOIDP == 8 && defined(HAVE___SYSCALL) && SIZEOF_INT != 8
8427 # define SYSCALL __syscall
8428 # define NUM2SYSCALLID(x) NUM2LONG(x)
8429 # define RETVAL2NUM(x) LONG2NUM(x)
8430 # if SIZEOF_LONG == 8
8431 long num, retval = -1;
8432 # elif SIZEOF_LONG_LONG == 8
8433 long long num, retval = -1;
8435 # error ---->> it is asserted that __syscall takes the first argument and returns retval in 64bit signed integer. <<----
8438 # define SYSCALL syscall
8439 # define NUM2SYSCALLID(x) NUM2LONG(x)
8440 # define RETVAL2NUM(x) LONG2NUM(x)
8448 long num, retval = -1;
8450 # define SYSCALL syscall
8451 # define NUM2SYSCALLID(x) NUM2INT(x)
8452 # define RETVAL2NUM(x) INT2NUM(x)
8453 int num, retval = -1;
8458 rb_warning(
"We plan to remove a syscall function at future release. DL(Fiddle) provides safer alternative.");
8466 num = NUM2SYSCALLID(argv[0]); ++
argv;
8467 for (i = argc - 1; i--; ) {
8482 retval = SYSCALL(num);
8485 retval = SYSCALL(num, arg[0]);
8488 retval = SYSCALL(num, arg[0],arg[1]);
8491 retval = SYSCALL(num, arg[0],arg[1],arg[2]);
8494 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3]);
8497 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4]);
8500 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5]);
8503 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6]);
8507 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8511 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8515 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8516 arg[7], arg[8], arg[9]);
8519 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8520 arg[7], arg[8], arg[9], arg[10]);
8523 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8524 arg[7], arg[8], arg[9], arg[10], arg[11]);
8527 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8528 arg[7], arg[8], arg[9], arg[10], arg[11], arg[12]);
8535 return RETVAL2NUM(retval);
8537 #undef NUM2SYSCALLID
8541 #define rb_f_syscall rb_f_notimplement
8554 int ecflags = fptr->
encs.ecflags;
8600 fptr->
encs.enc = enc;
8601 fptr->
encs.enc2 = enc2;
8602 fptr->
encs.ecflags = ecflags;
8603 fptr->
encs.ecopts = ecopts;
8678 int pipes[2],
state;
8685 argc =
rb_scan_args(argc, argv,
"02:", &v1, &v2, &opt);
8712 #if DEFAULT_TEXTMODE
8717 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
8723 fptr->
mode |= fmode;
8724 #if DEFAULT_TEXTMODE
8730 fptr2->
mode |= fmode;
8770 #if SIZEOF_LONG > SIZEOF_INT
8826 int orig_argc =
argc;
8933 if (!
NIL_P(offset)) {
8974 arg.
argc = (argc > 1) ? 1 : 0;
8975 if (!
NIL_P(offset)) {
8990 VALUE string, offset, opt;
9001 int mode = O_WRONLY|O_CREAT;
9005 if (
NIL_P(offset)) mode |= O_TRUNC;
9015 if (!
NIL_P(offset)) {
9139 #if defined(ERESTART)
9200 #ifdef HAVE_SENDFILE
9203 # define USE_SENDFILE
9205 # ifdef HAVE_SYS_SENDFILE_H
9206 # include <sys/sendfile.h>
9212 return sendfile(out_fd, in_fd, offset, (
size_t)count);
9215 # elif 0 || defined(__APPLE__)
9219 # define USE_SENDFILE
9221 # ifdef HAVE_SYS_UIO_H
9222 # include <sys/uio.h>
9226 simple_sendfile(
int out_fd,
int in_fd,
off_t *offset,
off_t count)
9232 r = sendfile(in_fd, out_fd, pos, &count, NULL, 0);
9235 r = sendfile(in_fd, out_fd, pos, (
size_t)count, NULL, &sbytes, 0);
9237 if (r != 0 && sbytes == 0)
return -1;
9244 return (ssize_t)sbytes;
9255 struct stat src_stat, dst_stat;
9269 if (!
S_ISREG(src_stat.st_mode))
9278 if ((dst_stat.st_mode & S_IFMT) != S_IFSOCK)
9282 use_pread = src_offset != (
off_t)-1;
9285 if (copy_length == (
off_t)-1) {
9287 copy_length = src_stat.st_size - src_offset;
9292 if (cur == (
off_t)-1 && errno) {
9297 copy_length = src_stat.st_size - cur;
9302 # if SIZEOF_OFF_T > SIZEOF_SIZE_T
9306 ss = (ssize_t)copy_length;
9309 ss = simple_sendfile(stp->
dst_fd, stp->
src_fd, &src_offset, ss);
9312 ss = simple_sendfile(stp->
dst_fd, stp->
src_fd, NULL, ss);
9317 if (0 < copy_length) {
9318 goto retry_sendfile;
9323 goto retry_sendfile;
9331 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
9347 goto retry_sendfile;
9349 stp->
syserr =
"sendfile";
9363 return read(fd, buf, count);
9371 if (offset == (
off_t)-1) {
9376 ss = pread(stp->
src_fd, buf, len, offset);
9390 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
9402 stp->
syserr = offset == (
off_t)-1 ?
"read" :
"pread";
9415 ss = write(stp->
dst_fd, buf+off, len);
9448 use_eof = copy_length == (
off_t)-1;
9450 use_pread = src_offset != (
off_t)-1;
9461 src_offset = (
off_t)-1;
9465 while (use_eof || 0 < copy_length) {
9466 if (!use_eof && copy_length < (
off_t)
sizeof(
buf)) {
9467 len = (size_t)copy_length;
9501 ret = nogvl_copy_stream_sendfile(stp);
9518 const int buflen = 16*1024;
9540 l = buflen < rest ? buflen : (
long)rest;
9555 if (off != (
off_t)-1)
9560 stp->
total += numwrote;
9586 VALUE src_io, dst_io;
9587 rb_io_t *src_fptr = 0, *dst_fptr = 0;
9602 if (
NIL_P(src_io)) {
9604 int oflags = O_RDONLY;
9617 src_fd = src_fptr->
fd;
9629 if (
NIL_P(dst_io)) {
9631 int oflags = O_WRONLY|O_CREAT|O_TRUNC;
9649 dst_fd = dst_fptr->fd;
9661 size_t len = src_fptr->
rbuf.
len;
9680 if (dst_fptr &&
io_fflush(dst_fptr) < 0) {
9687 if (src_fd == -1 || dst_fd == -1) {
9754 rb_scan_args(argc, argv,
"22", &src, &dst, &length, &src_offset);
9764 if (
NIL_P(src_offset))
9789 if (fptr->
encs.enc2) {
9847 argc =
rb_scan_args(argc, argv,
"11:", &v1, &v2, &opt);
10075 return ARGF.current_file;
10151 VALUE tmp, str, length;
10155 if (!
NIL_P(length)) {
10174 if (
NIL_P(str)) str = tmp;
10177 if (
ARGF.next_p != -1) {
10183 else if (argc >= 1) {
10260 VALUE tmp, str, length;
10284 if (
ARGF.next_p == -1) {
10622 return ARGF.filename;
10653 return ARGF.current_file;
10713 if (
ARGF.init_p &&
ARGF.next_p == 0) {
10743 if (
ARGF.next_p != -1) {
10846 return ARGF.inplace;
11108 #define rb_intern(str) rb_intern_const(str)
11112 #include <sys/cygwin.h>
11113 static struct __cygwin_perfile pf[] =
11121 cygwin_internal(CW_PERFILE, pf);
11392 #if defined (_WIN32) || defined(__CYGWIN__)
11412 #if defined(O_NDELAY) || defined(O_NONBLOCK)
11413 # ifndef O_NONBLOCK
11414 # define O_NONBLOCK O_NDELAY
11426 # define O_BINARY 0