21 #define free(x) xfree(x)
23 #if defined(DOSISH) || defined(__CYGWIN__)
27 #include <sys/types.h>
28 #if defined HAVE_NET_SOCKET_H
29 # include <net/socket.h>
30 #elif defined HAVE_SYS_SOCKET_H
31 # include <sys/socket.h>
34 #if defined(__BOW__) || defined(__CYGWIN__) || defined(_WIN32) || defined(__EMX__) || defined(__BEOS__) || defined(__HAIKU__)
35 # define NO_SAFE_RENAME
38 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(sun) || defined(_nec_ews)
46 #include <sys/types.h>
47 #if defined(HAVE_SYS_IOCTL_H) && !defined(_WIN32)
48 #include <sys/ioctl.h>
50 #if defined(HAVE_FCNTL_H) || defined(_WIN32)
52 #elif defined(HAVE_SYS_FCNTL_H)
53 #include <sys/fcntl.h>
56 #if !HAVE_OFF_T && !defined(off_t)
63 #if defined(HAVE_SYS_PARAM_H) && !(defined(__EMX__) || defined(__HIUX_MPP__))
64 # include <sys/param.h>
77 #elif defined HAVE_SYS_SYSCALL_H
78 #include <sys/syscall.h>
81 #if defined(__BEOS__) || defined(__HAIKU__)
83 # define NOFILE (OPEN_MAX)
90 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
93 #if SIZEOF_OFF_T > SIZEOF_LONG && !defined(HAVE_LONG_LONG)
94 # error off_t is bigger than long, but you have no long long...
98 # ifdef _POSIX_PIPE_BUF
99 # define PIPE_BUF _POSIX_PIPE_BUF
101 # define PIPE_BUF 512
105 #if defined(HAVE___SYSCALL) && (defined(__APPLE__) || defined(__OpenBSD__))
107 off_t __syscall(quad_t number, ...);
110 #define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
112 #define IO_RBUF_CAPA_MIN 8192
113 #define IO_CBUF_CAPA_MIN (128*1024)
114 #define IO_RBUF_CAPA_FOR(fptr) (NEED_READCONV(fptr) ? IO_CBUF_CAPA_MIN : IO_RBUF_CAPA_MIN)
115 #define IO_WBUF_CAPA_MIN 8192
120 #define open rb_w32_uopen
160 rb_bug(
"rb_update_max_fd: invalid fd (%d) given.", fd);
170 int flags, flags2, ret;
171 flags =
fcntl(fd, F_GETFD);
176 flags2 = flags & ~FD_CLOEXEC;
178 flags2 = flags | FD_CLOEXEC;
179 if (flags != flags2) {
180 ret =
fcntl(fd, F_SETFD, flags2);
182 rb_bug(
"rb_maygvl_fd_fix_cloexec: fcntl(%d, F_SETFD, %d) failed: %s", fd, flags2,
strerror(
errno));
193 #if defined(HAVE_FCNTL) && defined(F_DUPFD_CLOEXEC)
194 static int try_dupfd_cloexec = 1;
195 if (try_dupfd_cloexec) {
196 ret =
fcntl(fd, F_DUPFD_CLOEXEC, minfd);
203 if (
errno == EINVAL) {
204 ret =
fcntl(fd, F_DUPFD, minfd);
206 try_dupfd_cloexec = 0;
211 ret =
fcntl(fd, F_DUPFD, minfd);
213 #elif defined(F_DUPFD)
214 ret =
fcntl(fd, F_DUPFD, minfd);
219 if (ret == -1)
return -1;
224 #define argf_of(obj) (*(struct argf *)DATA_PTR(obj))
225 #define ARGF argf_of(argf)
227 #ifdef _STDIO_USES_IOSTREAM
229 # define STDIO_READ_DATA_PENDING(fp) ((fp)->_IO_read_ptr != (fp)->_IO_read_end)
231 # define STDIO_READ_DATA_PENDING(fp) ((fp)->_gptr < (fp)->_egptr)
233 #elif defined(FILE_COUNT)
234 # define STDIO_READ_DATA_PENDING(fp) ((fp)->FILE_COUNT > 0)
235 #elif defined(FILE_READEND)
236 # define STDIO_READ_DATA_PENDING(fp) ((fp)->FILE_READPTR < (fp)->FILE_READEND)
237 #elif defined(__BEOS__) || defined(__HAIKU__)
238 # define STDIO_READ_DATA_PENDING(fp) ((fp)->_state._eof == 0)
240 # define STDIO_READ_DATA_PENDING(fp) (!feof(fp))
243 #define GetWriteIO(io) rb_io_get_write_io(io)
245 #define READ_DATA_PENDING(fptr) ((fptr)->rbuf.len)
246 #define READ_DATA_PENDING_COUNT(fptr) ((fptr)->rbuf.len)
247 #define READ_DATA_PENDING_PTR(fptr) ((fptr)->rbuf.ptr+(fptr)->rbuf.off)
248 #define READ_DATA_BUFFERED(fptr) READ_DATA_PENDING(fptr)
250 #define READ_CHAR_PENDING(fptr) ((fptr)->cbuf.len)
251 #define READ_CHAR_PENDING_COUNT(fptr) ((fptr)->cbuf.len)
252 #define READ_CHAR_PENDING_PTR(fptr) ((fptr)->cbuf.ptr+(fptr)->cbuf.off)
255 #define WAIT_FD_IN_WIN32(fptr) \
256 (rb_w32_io_cancelable_p((fptr)->fd) ? 0 : rb_thread_wait_fd((fptr)->fd))
258 #define WAIT_FD_IN_WIN32(fptr)
261 #define READ_CHECK(fptr) do {\
262 if (!READ_DATA_PENDING(fptr)) {\
263 WAIT_FD_IN_WIN32(fptr);\
264 rb_io_check_closed(fptr);\
270 # define S_ISSOCK(m) _S_ISSOCK(m)
273 # define S_ISSOCK(m) (((m) & S_IFMT) == _S_IFSOCK)
276 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
282 #define rb_sys_fail_path(path) rb_sys_fail_str(path)
287 #define NEED_NEWLINE_DECORATOR_ON_READ(fptr) ((fptr)->mode & FMODE_TEXTMODE)
288 #define NEED_NEWLINE_DECORATOR_ON_WRITE(fptr) ((fptr)->mode & FMODE_TEXTMODE)
289 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
291 # define DEFAULT_TEXTMODE FMODE_TEXTMODE
292 # define TEXTMODE_NEWLINE_DECORATOR_ON_WRITE ECONV_CRLF_NEWLINE_DECORATOR
300 #define NEED_READCONV(fptr) ((fptr)->encs.enc2 != NULL || (fptr)->encs.ecflags & ~ECONV_CRLF_NEWLINE_DECORATOR)
301 #define NEED_WRITECONV(fptr) (((fptr)->encs.enc != NULL && (fptr)->encs.enc != rb_ascii8bit_encoding()) || ((fptr)->encs.ecflags & ((ECONV_DECORATOR_MASK & ~ECONV_CRLF_NEWLINE_DECORATOR)|ECONV_STATEFUL_DECORATOR_MASK)))
302 #define SET_BINARY_MODE(fptr) setmode((fptr)->fd, O_BINARY)
304 #define NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr) do {\
305 if (NEED_NEWLINE_DECORATOR_ON_READ(fptr)) {\
306 if (((fptr)->mode & FMODE_READABLE) &&\
307 !((fptr)->encs.ecflags & ECONV_NEWLINE_DECORATOR_MASK)) {\
308 setmode((fptr)->fd, O_BINARY);\
311 setmode((fptr)->fd, O_TEXT);\
316 #define SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(enc2, ecflags) do {\
317 if ((enc2) && ((ecflags) & ECONV_DEFAULT_NEWLINE_DECORATOR)) {\
318 (ecflags) |= ECONV_UNIVERSAL_NEWLINE_DECORATOR;\
344 if (r < 0 &&
errno) {
356 if (pos < 0 &&
errno) {
371 for (i = 0; i < fptr->
rbuf.
len; i++) {
372 if (*p ==
'\n') newlines++;
373 if (extra_max == newlines)
break;
378 while (newlines >= 0) {
380 if (newlines == 0)
break;
385 read_size = _read(fptr->
fd, buf, fptr->
rbuf.
len + newlines);
390 if (read_size == fptr->
rbuf.
len) {
412 set_binary_mode_with_seek_cur(
rb_io_t *fptr)
417 return setmode(fptr->
fd, O_BINARY);
420 return setmode(fptr->
fd, O_BINARY);
422 #define SET_BINARY_MODE_WITH_SEEK_CUR(fptr) set_binary_mode_with_seek_cur(fptr)
426 # define DEFAULT_TEXTMODE 0
427 #define NEED_READCONV(fptr) ((fptr)->encs.enc2 != NULL || NEED_NEWLINE_DECORATOR_ON_READ(fptr))
428 #define NEED_WRITECONV(fptr) (((fptr)->encs.enc != NULL && (fptr)->encs.enc != rb_ascii8bit_encoding()) || NEED_NEWLINE_DECORATOR_ON_WRITE(fptr) || ((fptr)->encs.ecflags & (ECONV_DECORATOR_MASK|ECONV_STATEFUL_DECORATOR_MASK)))
429 #define SET_BINARY_MODE(fptr) (void)(fptr)
430 #define NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr) (void)(fptr)
431 #define SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(enc2, ecflags) ((void)(enc2), (void)(ecflags))
432 #define SET_BINARY_MODE_WITH_SEEK_CUR(fptr) (void)(fptr)
435 #if !defined HAVE_SHUTDOWN && !defined shutdown
436 #define shutdown(a,b) 0
440 #define is_socket(fd, path) rb_w32_is_socket(fd)
441 #elif !defined(S_ISSOCK)
442 #define is_socket(fd, path) 0
448 if (
fstat(fd, &sbuf) < 0)
450 return S_ISSOCK(sbuf.st_mode);
504 write_io =
RFILE(io)->fptr->tied_io_for_writing;
522 write_io =
RFILE(io)->fptr->tied_io_for_writing;
523 RFILE(io)->fptr->tied_io_for_writing = w;
524 return write_io ? write_io :
Qnil;
550 #if !(defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32))
561 if (r < 0 &&
errno) {
583 #if SIZEOF_LONG > SIZEOF_INT
617 #define io_seek(fptr, ofs, whence) (errno = 0, lseek(flush_before_seek(fptr)->fd, (ofs), (whence)))
618 #define io_tell(fptr) lseek(flush_before_seek(fptr)->fd, 0, SEEK_CUR)
626 #define FMODE_SYNCWRITE (FMODE_SYNC|FMODE_WRITABLE)
665 if (fptr->
encs.enc) {
666 return fptr->
encs.enc;
674 if (fptr->
encs.enc2) {
675 return fptr->
encs.enc2;
749 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
755 #if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(O_NONBLOCK)
761 if (
fstat(fptr->
fd, &buf) == 0 &&
763 #
if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(
O_NONBLOCK)
764 && (r =
fcntl(fptr->
fd, F_GETFL)) != -1 &&
791 return read(iis->
fd, iis->
buf, iis->
capa);
798 return write(iis->
fd, iis->
buf, iis->
capa);
897 #if defined(ERESTART)
904 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
923 #if defined(ERESTART)
930 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
945 const char *senc, *denc;
953 ecopts = fptr->
encs.ecopts;
965 enc = fptr->
encs.enc2 ? fptr->
encs.enc2 : fptr->
encs.enc;
987 ecopts = fptr->
encs.ecopts;
1021 long n, r, offset = 0;
1023 if ((n = len) <= 0)
return n;
1057 arg.
ptr = ptr + offset;
1067 if (r == n)
return len;
1091 # define MODE_BTMODE(a,b,c) ((fmode & FMODE_BINMODE) ? (b) : \
1092 (fmode & FMODE_TEXTMODE) ? (c) : (a))
1103 #define fmode (fptr->mode)
1107 rb_raise(
rb_eArgError,
"ASCII incompatible string written for text mode IO without encoding conversion: %s",
1113 if (fptr->
encs.enc2)
1119 if (!
NIL_P(common_encoding)) {
1128 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
1129 #define fmode (fptr->mode)
1136 setmode(fptr->
fd, O_TEXT);
1139 rb_raise(
rb_eArgError,
"ASCII incompatible string written for text mode IO without encoding conversion: %s",
1154 if (len > 0)
return len;
1169 return (ssize_t)
io_binwrite(0, buf, (
long)size, fptr, 0);
1330 pos =
io_seek(fptr, pos, whence);
1360 VALUE offset, ptrname;
1363 if (
rb_scan_args(argc, argv,
"11", &offset, &ptrname) == 2) {
1425 if (io ==
ARGF.current_file) {
1513 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
1579 static VALUE nogvl_fsync(
void *
ptr)
1617 #define rb_io_fsync rb_f_notimplement
1620 #ifdef HAVE_FDATASYNC
1621 static VALUE nogvl_fdatasync(
void *ptr)
1625 return (
VALUE)fdatasync(fptr->
fd);
1657 #define rb_io_fdatasync rb_io_fsync
1728 static const char closed[] =
" (closed)";
1772 if (n <= 0)
return 0;
1773 if (n > len) n = (int)len;
1798 if ((n -= c) <= 0)
break;
1808 if ((n -= c) <= 0)
break;
1855 return (ssize_t)
io_bufread(buf, (
long)size, fptr);
1858 #define SMALLBUF 100
1868 #
if defined(__BEOS__) || defined(__HAIKU__)
1876 if (st.st_size >= pos && pos >= 0) {
1877 siz += st.st_size - pos;
1903 const char *sname, *dname;
1905 ecopts = fptr->
encs.ecopts;
1906 if (fptr->
encs.enc2) {
1924 #define MORE_CHAR_SUSPENDED Qtrue
1925 #define MORE_CHAR_FINISHED Qnil
1929 const unsigned char *ss, *sp, *se;
1930 unsigned char *ds, *
dp, *de;
1950 ss = sp = (
const unsigned char *)fptr->
rbuf.
ptr + fptr->
rbuf.
off;
1955 fptr->
rbuf.
off += (int)(sp - ss);
1956 fptr->
rbuf.
len -= (int)(sp - ss);
1957 fptr->
cbuf.
len += (int)(dp - ds);
1962 fptr->
rbuf.
off -= putbackable;
1963 fptr->
rbuf.
len += putbackable;
1970 if (cbuf_len0 != fptr->
cbuf.
len)
1987 fptr->
cbuf.
len += (int)(dp - ds);
1994 if (cbuf_len0 != fptr->
cbuf.
len)
2102 if (siz == 0) siz = BUFSIZ;
2107 if (n == 0 && bytes == 0) {
2113 if (bytes < siz)
break;
2128 oflags =
fcntl(fptr->
fd, F_GETFL);
2167 if ((len =
NUM2LONG(length)) < 0) {
2488 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
2494 if (
NIL_P(length)) {
2508 if (len == 0)
return str;
2511 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
2512 previous_mode = set_binary_mode_with_seek_cur(fptr);
2515 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
2516 if (previous_mode == O_TEXT) {
2517 setmode(fptr->
fd, O_TEXT);
2521 if (fptr->
fd < 0)
return Qnil;
2554 if (0 < limit && limit < searchlen)
2555 searchlen = (int)limit;
2556 e = memchr(p, delim, searchlen);
2558 int len = (int)(e-p+1);
2597 if (limit > 0 && pending > limit) pending = limit;
2598 e = memchr(p, delim, pending);
2599 if (e) pending = e - p + 1;
2612 if (e)
return delim;
2636 if (*p != term)
return TRUE;
2638 while (--i && *++p == term);
2641 const char *e = p +
cnt;
2643 while ((p += i) < e &&
rb_enc_ascget(p, e, &i, enc) == term);
2659 if (cnt >
sizeof buf) cnt =
sizeof buf;
2660 if (*p != term)
return TRUE;
2662 while (--i && *++p == term);
2686 e = memchr(p,
'\n', pending);
2688 pending = (int)(e - p + 1);
2714 if (io ==
ARGF.current_file) {
2741 else if (2 <= argc) {
2752 if (enc_io != enc_rs &&
2780 if (
NIL_P(rs) && limit < 0) {
2784 else if (limit == 0) {
2793 int c, newline = -1;
2794 const char *rsptr = 0;
2797 int extra_limit = 16;
2821 newline = (
unsigned char)rsptr[rslen - 1];
2825 while ((c =
appendline(fptr, newline, &str, &limit)) !=
EOF) {
2826 const char *s, *
p, *pp, *e;
2834 if (pp != p)
continue;
2835 if (!rspara)
rscheck(rsptr, rslen, rs);
2836 if (
memcmp(p, rsptr, rslen) == 0)
break;
2868 if (io ==
ARGF.current_file) {
3031 VALUE line, ary, rs;
3341 if (fptr->
encs.enc) {
3560 #if SIZEOF_LONG > SIZEOF_INT
3602 if (isatty(fptr->
fd) == 0)
3607 #if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
3630 if (io != write_io) {
3632 if (fptr && 0 <= (fd = fptr->
fd)) {
3634 if (!(ret & FD_CLOEXEC))
return Qfalse;
3639 if (fptr && 0 <= (fd = fptr->
fd)) {
3641 if (!(ret & FD_CLOEXEC))
return Qfalse;
3646 #define rb_io_close_on_exec_p rb_f_notimplement
3649 #if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
3665 int flag =
RTEST(arg) ? FD_CLOEXEC : 0;
3671 if (io != write_io) {
3673 if (fptr && 0 <= (fd = fptr->
fd)) {
3675 if ((ret & FD_CLOEXEC) != flag) {
3676 ret = (ret & ~FD_CLOEXEC) | flag;
3677 ret =
fcntl(fd, F_SETFD, ret);
3685 if (fptr && 0 <= (fd = fptr->
fd)) {
3687 if ((ret & FD_CLOEXEC) != flag) {
3688 ret = (ret & ~FD_CLOEXEC) | flag;
3689 ret =
fcntl(fd, F_SETFD, ret);
3696 #define rb_io_set_close_on_exec rb_f_notimplement
3699 #define FMODE_PREP (1<<16)
3700 #define IS_PREP_STDIO(f) ((f)->mode & FMODE_PREP)
3701 #define PREP_STDIO_NAME(f) (RSTRING_PTR((f)->pathv))
3706 unsigned char *ds, *
dp, *de;
3710 unsigned char buf[1024];
3716 de = buf +
sizeof(
buf);
3753 fptr->
wbuf.
len += (int)(dp - ds);
3809 else if (0 <= fptr->
fd) {
3813 if (close(fptr->
fd) < 0 &&
NIL_P(err))
3821 if (!
NIL_P(err) && !noraise) {
3878 if (!fptr)
return 0;
3919 if (io != write_io) {
3920 write_fptr =
RFILE(write_io)->fptr;
3921 if (write_fptr && 0 <= write_fptr->
fd) {
3926 fptr =
RFILE(io)->fptr;
3927 if (!fptr)
return Qnil;
3928 if (fptr->
fd < 0)
return Qnil;
3931 #if defined __APPLE__ && defined(__MACH__) && \
3932 (!defined(MAC_OS_X_VERSION_MIN_ALLOWED) || MAC_OS_X_VERSION_MIN_ALLOWED <= 1050)
4012 if (io != write_io) {
4013 write_fptr =
RFILE(write_io)->fptr;
4014 if (write_fptr && 0 <= write_fptr->
fd) {
4019 fptr =
RFILE(io)->fptr;
4065 if (io != write_io) {
4070 RFILE(io)->fptr = wfptr;
4132 if (io != write_io) {
4157 VALUE offset, ptrname;
4162 if (
rb_scan_args(argc, argv,
"11", &offset, &ptrname) == 2) {
4172 rb_warn(
"sysseek for buffered IO");
4175 pos = lseek(fptr->
fd, pos, whence);
4209 rb_warn(
"syswrite for buffered IO");
4250 if (ilen == 0)
return str;
4274 if (n == 0 && ilen > 0) {
4327 fptr->
encs.ecflags = 0;
4388 case FMODE_READWRITE:
4401 static const char bom_prefix[] =
"bom|utf-";
4402 enum {bom_prefix_len = (int)
sizeof(bom_prefix) - 1};
4404 const char *
p =
strchr(name,
':');
4407 return len > bom_prefix_len &&
STRNCASECMP(name, bom_prefix, bom_prefix_len) == 0;
4414 const char *m = modestr, *
p =
NULL;
4464 switch (oflags & (O_RDONLY|O_WRONLY|O_RDWR)) {
4476 if (oflags & O_APPEND) {
4479 if (oflags & O_TRUNC) {
4482 if (oflags & O_CREAT) {
4506 case FMODE_READWRITE:
4539 # define MODE_BINARY(a,b) ((oflags & O_BINARY) ? (b) : (a))
4541 # define MODE_BINARY(a,b) (a)
4543 int accmode = oflags & (O_RDONLY|O_WRONLY|O_RDWR);
4544 if (oflags & O_APPEND) {
4545 if (accmode == O_WRONLY) {
4548 if (accmode == O_RDWR) {
4552 switch (oflags & (O_RDONLY|O_WRONLY|O_RDWR)) {
4572 int default_ext = 0;
4583 *enc = (default_ext && intern != ext) ?
NULL : ext;
4604 long len = (p++) - estr;
4613 memcpy(encname, estr, len);
4614 encname[
len] =
'\0';
4625 memcpy(encname, estr, len);
4626 encname[
len] =
'\0';
4636 rb_warn(
"Unsupported encoding %s ignored", estr);
4642 if (*p ==
'-' && *(p+1) ==
'\0') {
4649 rb_warn(
"Unsupported encoding %s ignored", p);
4650 else if (idx2 == idx) {
4651 rb_warn(
"Ignoring internal encoding %s: it is identical to external encoding %s", p, estr);
4673 const char *
p =
strchr(modestr,
':');
4690 if (v !=
Qnil) encoding =
v;
4692 if (v !=
Qnil) extenc =
v;
4699 rb_warn(
"Ignoring encoding parameter '%s': %s_encoding is used",
4701 extenc ==
Qundef ?
"internal" :
"external");
4709 if (
NIL_P(intenc)) {
4716 if (*p ==
'-' && *(p+1) ==
'\0') {
4727 if (extencoding == intencoding) {
4731 if (!
NIL_P(encoding)) {
4752 int fmode = *fmode_p;
4760 if (!(fmode & FMODE_BINMODE) &&
4765 #if !DEFAULT_TEXTMODE
4766 else if (!(ecflags & ECONV_NEWLINE_DECORATOR_MASK)) {
4776 if (!
NIL_P(opthash)) {
4792 int *oflags_p,
int *fmode_p,
convconfig_t *convconfig_p)
4799 int has_enc = 0, has_vmode = 0;
4837 if (
NIL_P(opthash)) {
4841 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
4844 0, TEXTMODE_NEWLINE_DECORATOR_ON_WRITE) : 0;
4856 #if DEFAULT_TEXTMODE
4857 else if (
NIL_P(vmode)) {
4864 if (!
NIL_P(vmode)) {
4875 if (!
NIL_P(*vperm_p)) {
4887 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
4890 0, TEXTMODE_NEWLINE_DECORATOR_ON_WRITE) : 0;
4908 convconfig_p->enc = enc;
4909 convconfig_p->enc2 = enc2;
4910 convconfig_p->ecflags = ecflags;
4911 convconfig_p->ecopts = ecopts;
4970 file = fdopen(fd, modestr);
4981 file = fdopen(fd, modestr);
4995 if (setvbuf(file,
NULL, _IOFBF, 0) != 0)
4996 rb_warn(
"setvbuf() can't be honoured (fd=%d)", fd);
5004 if (isatty(fptr->
fd))
5014 VALUE b1, b2, b3, b4;
5100 convconfig->enc, convconfig->enc2);
5104 fptr->
encs = *convconfig;
5117 const char *
p =
strchr(modestr,
':');
5129 convconfig.ecflags = 0;
5130 convconfig.ecopts =
Qnil;
5153 #if defined(__CYGWIN__) || !defined(HAVE_FORK)
5176 if (list->
fptr == fptr) {
5182 while (list->
next) {
5209 #if !defined(HAVE_FORK) && !defined(_WIN32)
5264 popen_redirect(
struct popen_arg *
p)
5267 close(p->write_pair[1]);
5268 if (p->write_pair[0] != 0) {
5269 dup2(p->write_pair[0], 0);
5270 close(p->write_pair[0]);
5273 if (p->pair[1] != 1) {
5274 dup2(p->pair[1], 1);
5280 if (p->pair[1] != 1) {
5281 dup2(p->pair[1], 1);
5287 if (p->pair[0] != 0) {
5288 dup2(p->pair[0], 0);
5301 for (fd = lowfd; fd <=
max; fd++) {
5302 if (!
NIL_P(noclose_fds) &&
5306 ret =
fcntl(fd, F_GETFD);
5307 if (ret != -1 && !(ret & FD_CLOEXEC)) {
5308 fcntl(fd, F_SETFD, ret|FD_CLOEXEC);
5313 #define CONTIGUOUS_CLOSED_FDS 20
5315 if (max < fd + CONTIGUOUS_CLOSED_FDS)
5316 max = fd + CONTIGUOUS_CLOSED_FDS;
5322 popen_exec(
void *pp,
char *errmsg,
size_t errmsg_len)
5324 struct popen_arg *p = (
struct popen_arg*)pp;
5339 #if defined(HAVE_FORK)
5341 struct popen_arg arg;
5342 char errmsg[80] = {
'\0' };
5343 #elif defined(_WIN32)
5344 volatile VALUE argbuf;
5346 int pair[2], write_pair[2];
5348 #if !defined(HAVE_FORK)
5354 const char *cmd = 0;
5366 else if (eargp->
argc) {
5377 #if defined(HAVE_FORK)
5380 arg.pair[0] = arg.pair[1] = -1;
5381 arg.write_pair[0] = arg.write_pair[1] = -1;
5384 if (
rb_pipe(arg.write_pair) < 0)
5388 close(arg.write_pair[0]);
5389 close(arg.write_pair[1]);
5415 pid =
rb_fork_err(&status, popen_exec, &arg, arg.execp->redirect_fds, errmsg,
sizeof(errmsg));
5422 popen_redirect(&arg);
5435 close(arg.write_pair[0]);
5436 close(arg.write_pair[1]);
5446 close(arg.write_pair[0]);
5447 write_fd = arg.write_pair[1];
5449 else if (fmode & FMODE_READABLE) {
5457 #elif defined(_WIN32)
5461 if (argc >= (
int)(
FIXNUM_MAX /
sizeof(
char *))) {
5466 for (i = 0; i <
argc; ++
i) {
5471 switch (fmode & (FMODE_READABLE|FMODE_WRITABLE)) {
5472 case FMODE_READABLE|FMODE_WRITABLE:
5477 close(write_pair[0]);
5478 close(write_pair[1]);
5487 case FMODE_READABLE:
5493 case FMODE_WRITABLE:
5506 while ((pid = (args ?
5512 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
5524 if ((fmode & (FMODE_READABLE|FMODE_WRITABLE)) == (FMODE_READABLE|FMODE_WRITABLE)) {
5525 close(write_pair[0]);
5526 close(write_pair[1]);
5539 if ((fmode & FMODE_READABLE) && (fmode & FMODE_WRITABLE)) {
5542 close(write_pair[0]);
5543 write_fd = write_pair[1];
5545 else if (fmode & FMODE_READABLE) {
5562 fp = popen(cmd, modestr);
5575 fptr->
encs = *convconfig;
5576 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
5586 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
5588 fptr->
encs.ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
5594 if (0 <= write_fd) {
5597 write_fptr->
fd = write_fd;
5599 fptr->
mode &= ~FMODE_WRITABLE;
5604 #if defined (__CYGWIN__) || !defined(HAVE_FORK)
5617 return pipe_open(&earg, prog, modestr, fmode, convconfig);
5629 #if !defined(HAVE_FORK)
5631 "fork() function is unimplemented on this machine");
5633 return pipe_open(0, 0, modestr, fmode, convconfig);
5637 return pipe_open(&earg, prog, modestr, fmode, convconfig);
5726 const char *modestr;
5727 VALUE pname, pmode, port, tmp, opt;
5731 argc =
rb_scan_args(argc, argv,
"11:", &pname, &pmode, &opt);
5739 #if SIZEOF_LONG > SIZEOF_INT
5740 if (len > INT_MAX) {
5751 port =
pipe_open_s(pname, modestr, fmode, &convconfig);
5763 RBASIC(port)->klass = klass;
5772 VALUE *fname_p,
int *oflags_p,
int *fmode_p,
5775 VALUE opt, fname, vmode, vperm;
5779 argc =
rb_scan_args(argc, argv,
"12:", &fname, &vmode, &vperm, &opt);
5867 VALUE fname, vmode, vperm;
5872 rb_scan_args(argc, argv,
"12", &fname, &vmode, &vperm);
5883 if (
NIL_P(vperm)) perm = 0666;
6021 int redirect =
FALSE;
6029 VALUE tmp = argv[0];
6070 oflags, fmode, &convconfig, perm);
6099 if (fptr == orig)
return io;
6105 "%s can't change access mode from \"%s\" to \"%s\"",
6132 #
if defined (__CYGWIN__) || !defined(HAVE_FORK)
6142 if (
dup2(fd2, fd) < 0)
6150 if (
dup2(fd2, fd) < 0)
6198 if (
rb_scan_args(argc, argv,
"11", &fname, &nmode) == 1) {
6207 fptr =
RFILE(file)->fptr;
6213 if (!
NIL_P(nmode)) {
6217 (fptr->
mode & FMODE_READWRITE)) {
6219 "%s can't change access mode from \"%s\" to \"%s\"",
6225 fptr->
encs.ecflags = 0;
6254 if (close(fptr->
fd) < 0)
6273 if (dest == io)
return dest;
6286 #if defined (__CYGWIN__) || !defined(HAVE_FORK)
6301 if (io != write_io) {
6342 if (argc == 0)
return Qnil;
6390 for (i=0; i<
argc; i++) {
6496 if (len == 0)
return 0;
6498 return ptr[len - 1] == c;
6500 return rb_enc_ascget(ptr + ((len - 1) / n) * n, ptr + len, &n, enc) == c;
6552 for (i=0; i<
argc; i++) {
6631 for (i=0; i<
argc; i++) {
6637 else if (argc > 1) {
6689 (void)fwrite(mesg,
sizeof(
char),
len, stderr);
6746 if (path && strcmp(path,
"-")) klass =
rb_cFile;
6758 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
6759 fptr->
encs.ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
6872 int fd,
fmode, oflags = O_RDONLY;
6875 #if defined(HAVE_FCNTL) && defined(F_GETFL)
6883 argc =
rb_scan_args(argc, argv,
"11:", &fnum, &vmode, &opt);
6890 #if defined(HAVE_FCNTL) && defined(F_GETFL)
6891 oflags =
fcntl(fd, F_GETFL);
6897 #if defined(HAVE_FCNTL) && defined(F_GETFL)
6913 fp->
encs = convconfig;
6918 else if (
fileno(stdout) == fd)
6920 else if (
fileno(stderr) == fd)
6957 if (
RFILE(io)->fptr) {
6960 if (0 < argc && argc < 3) {
6980 rb_warn(
"%s::new() does not take block; use %s::open() instead",
7043 if (!
RTEST(autoclose))
7053 struct argf *p = ptr;
7063 struct argf *p = ptr;
7164 #define next_argv() argf_next_argv(argf)
7165 #define ARGF_GENERIC_INPUT_P() \
7166 (ARGF.current_file == rb_stdin && TYPE(ARGF.current_file) != T_FILE)
7167 #define ARGF_FORWARD(argc, argv) do {\
7168 if (ARGF_GENERIC_INPUT_P())\
7169 return argf_forward((argc), (argv), argf);\
7171 #define NEXT_ARGF_FORWARD(argc, argv) do {\
7172 if (!next_argv()) return Qnil;\
7173 ARGF_FORWARD((argc), (argv));\
7191 int stdout_binmode = 0;
7200 if (
ARGF.init_p == 0) {
7218 if (
ARGF.next_p == 1) {
7223 if (
strlen(fn) == 1 && fn[0] ==
'-') {
7226 rb_warn(
"Can't do inplace edit for stdio; skipping");
7236 #ifndef NO_SAFE_RENAME
7246 if (*
ARGF.inplace) {
7249 #ifdef NO_SAFE_RENAME
7253 rb_warn(
"Can't rename %s to %s: %s, skipping file",
7260 rb_warn(
"Can't rename %s to %s: %s, skipping file",
7268 #ifdef NO_SAFE_RENAME
7269 rb_fatal(
"Can't do inplace edit without backup");
7271 if (unlink(fn) < 0) {
7272 rb_warn(
"Can't remove %s: %s, skipping file",
7280 #ifndef NO_SAFE_RENAME
7283 fchmod(fw, st.st_mode);
7285 chmod(fn, st.st_mode);
7287 if (st.st_uid!=st2.st_uid || st.st_gid!=st2.st_gid) {
7290 err = fchown(fw, st.st_uid, st.st_gid);
7292 err =
chown(fn, st.st_uid, st.st_gid);
7294 if (err &&
getuid() == 0 && st2.st_uid == 0) {
7296 rb_warn(
"Can't set owner/group of %s to same as %s: %s, skipping file",
7310 if (!
ARGF.binmode) {
7314 if (!
NIL_P(write_io)) {
7320 if (
ARGF.encs.enc) {
7326 if (!
ARGF.binmode) {
7328 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
7329 fptr->
encs.ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
7340 else if (
ARGF.next_p == -1) {
7344 rb_warn(
"Can't do inplace edit for stdio");
7355 long lineno =
ARGF.lineno;
7376 ARGF.lineno = ++lineno;
7394 ARGF.last_lineno =
ARGF.lineno = n;
7586 long lineno =
ARGF.lineno;
7624 volatile VALUE port;
7639 #ifdef HAVE_SYS_SELECT_H
7640 #include <sys/select.h>
7663 if (max < fptr->fd) max = fptr->
fd;
7674 if (!
NIL_P(write)) {
7680 if (max < fptr->fd) max = fptr->
fd;
7687 if (!
NIL_P(except)) {
7694 if (max < fptr->fd) max = fptr->
fd;
7695 if (io != write_io) {
7698 if (max < fptr->fd) max = fptr->
fd;
7713 if (!pending && n == 0)
return Qnil;
7756 else if (io != write_io) {
7796 #ifdef HAVE_POSIX_FADVISE
7797 struct io_advise_struct {
7805 io_advise_internal(
void *
arg)
7807 struct io_advise_struct *ptr =
arg;
7808 return posix_fadvise(ptr->fd, ptr->offset, ptr->len, ptr->advice);
7814 #ifdef POSIX_FADV_NORMAL
7815 if (sym == sym_normal)
7816 return INT2NUM(POSIX_FADV_NORMAL);
7819 #ifdef POSIX_FADV_RANDOM
7820 if (sym == sym_random)
7821 return INT2NUM(POSIX_FADV_RANDOM);
7824 #ifdef POSIX_FADV_SEQUENTIAL
7825 if (sym == sym_sequential)
7826 return INT2NUM(POSIX_FADV_SEQUENTIAL);
7829 #ifdef POSIX_FADV_WILLNEED
7830 if (sym == sym_willneed)
7831 return INT2NUM(POSIX_FADV_WILLNEED);
7834 #ifdef POSIX_FADV_DONTNEED
7835 if (sym == sym_dontneed)
7836 return INT2NUM(POSIX_FADV_DONTNEED);
7839 #ifdef POSIX_FADV_NOREUSE
7840 if (sym == sym_noreuse)
7841 return INT2NUM(POSIX_FADV_NOREUSE);
7851 struct io_advise_struct ias;
7854 num_adv = io_advise_sym_to_const(advice);
7860 if (num_adv ==
Qnil)
7864 ias.advice =
NUM2INT(num_adv);
7865 ias.offset = offset;
7885 if (advice != sym_normal &&
7886 advice != sym_sequential &&
7887 advice != sym_random &&
7888 advice != sym_willneed &&
7889 advice != sym_dontneed &&
7890 advice != sym_noreuse) {
7945 rb_scan_args(argc, argv,
"12", &advice, &offset, &len);
7954 #ifdef HAVE_POSIX_FADVISE
7955 return do_io_advise(fptr, advice, off, l);
8022 if (
NIL_P(timeout)) {
8036 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
8038 #define NUM2IOCTLREQ(num) NUM2ULONG(num)
8041 #define NUM2IOCTLREQ(num) NUM2INT(num)
8072 #define DEFULT_IOCTL_NARG_LEN (256)
8076 linux_iocparm_len(ioctl_req_t
cmd)
8080 if ((cmd & 0xFFFF0000) == 0) {
8085 len = _IOC_SIZE(cmd);
8102 #define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
8106 len = IOCPARM_LEN(cmd);
8107 #elif defined(__linux__)
8108 len = linux_iocparm_len(cmd);
8119 typedef long fcntl_arg_t;
8122 typedef int fcntl_arg_t;
8133 len =
sizeof(fcntl_arg_t);
8141 #ifdef F_DUPFD_CLOEXEC
8142 case F_DUPFD_CLOEXEC:
8143 len =
sizeof(fcntl_arg_t);
8153 len =
sizeof(fcntl_arg_t);
8163 len =
sizeof(fcntl_arg_t);
8173 len =
sizeof(fcntl_arg_t);
8178 len =
sizeof(
struct f_owner_ex);
8183 len =
sizeof(
struct f_owner_ex);
8188 len =
sizeof(
struct flock);
8193 len =
sizeof(
struct flock);
8198 len =
sizeof(
struct flock);
8218 len =
sizeof(fcntl_arg_t);
8228 len =
sizeof(fcntl_arg_t);
8233 len =
sizeof(fcntl_arg_t);
8264 else if (arg ==
Qtrue) {
8346 static VALUE nogvl_fcntl(
void *ptr)
8348 struct fcntl_arg *
arg = ptr;
8350 #if defined(F_DUPFD)
8351 if (arg->cmd == F_DUPFD)
8354 return (
VALUE)
fcntl(arg->fd, arg->cmd, arg->narg);
8358 do_fcntl(
int fd,
int cmd,
long narg)
8361 struct fcntl_arg arg;
8368 #if defined(F_DUPFD)
8369 if (retval != -1 && cmd == F_DUPFD) {
8389 retval = do_fcntl(fptr->
fd, cmd, narg);
8429 return rb_fcntl(io, req, arg);
8432 #define rb_io_fcntl rb_f_notimplement
8435 #if defined(HAVE_SYSCALL) || defined(HAVE___SYSCALL)
8477 #if SIZEOF_VOIDP == 8 && defined(HAVE___SYSCALL) && SIZEOF_INT != 8
8478 # define SYSCALL __syscall
8479 # define NUM2SYSCALLID(x) NUM2LONG(x)
8480 # define RETVAL2NUM(x) LONG2NUM(x)
8481 # if SIZEOF_LONG == 8
8482 long num, retval = -1;
8483 # elif SIZEOF_LONG_LONG == 8
8484 long long num, retval = -1;
8486 # error ---->> it is asserted that __syscall takes the first argument and returns retval in 64bit signed integer. <<----
8489 # define SYSCALL syscall
8490 # define NUM2SYSCALLID(x) NUM2LONG(x)
8491 # define RETVAL2NUM(x) LONG2NUM(x)
8499 long num, retval = -1;
8501 # define SYSCALL syscall
8502 # define NUM2SYSCALLID(x) NUM2INT(x)
8503 # define RETVAL2NUM(x) INT2NUM(x)
8504 int num, retval = -1;
8509 rb_warning(
"We plan to remove a syscall function at future release. DL(Fiddle) provides safer alternative.");
8517 num = NUM2SYSCALLID(argv[0]); ++
argv;
8518 for (i = argc - 1; i--; ) {
8533 retval = SYSCALL(num);
8536 retval = SYSCALL(num, arg[0]);
8539 retval = SYSCALL(num, arg[0],arg[1]);
8542 retval = SYSCALL(num, arg[0],arg[1],arg[2]);
8545 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3]);
8548 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4]);
8551 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5]);
8554 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6]);
8558 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8562 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8566 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8567 arg[7], arg[8], arg[9]);
8570 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8571 arg[7], arg[8], arg[9], arg[10]);
8574 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8575 arg[7], arg[8], arg[9], arg[10], arg[11]);
8578 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8579 arg[7], arg[8], arg[9], arg[10], arg[11], arg[12]);
8586 return RETVAL2NUM(retval);
8588 #undef NUM2SYSCALLID
8592 #define rb_f_syscall rb_f_notimplement
8605 int ecflags = fptr->
encs.ecflags;
8651 fptr->
encs.enc = enc;
8652 fptr->
encs.enc2 = enc2;
8653 fptr->
encs.ecflags = ecflags;
8654 fptr->
encs.ecopts = ecopts;
8729 int pipes[2],
state;
8736 argc =
rb_scan_args(argc, argv,
"02:", &v1, &v2, &opt);
8763 #if DEFAULT_TEXTMODE
8768 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
8774 fptr->
mode |= fmode;
8775 #if DEFAULT_TEXTMODE
8781 fptr2->
mode |= fmode;
8821 #if SIZEOF_LONG > SIZEOF_INT
8877 int orig_argc =
argc;
8984 if (!
NIL_P(offset)) {
9025 arg.
argc = (argc > 1) ? 1 : 0;
9026 if (!
NIL_P(offset)) {
9041 VALUE string, offset, opt;
9052 int mode = O_WRONLY|O_CREAT;
9056 if (
NIL_P(offset)) mode |= O_TRUNC;
9066 if (!
NIL_P(offset)) {
9190 #if defined(ERESTART)
9251 #ifdef HAVE_SENDFILE
9254 # define USE_SENDFILE
9256 # ifdef HAVE_SYS_SENDFILE_H
9257 # include <sys/sendfile.h>
9263 return sendfile(out_fd, in_fd, offset, (
size_t)count);
9266 # elif 0 || defined(__APPLE__)
9270 # define USE_SENDFILE
9272 # ifdef HAVE_SYS_UIO_H
9273 # include <sys/uio.h>
9277 simple_sendfile(
int out_fd,
int in_fd,
off_t *offset,
off_t count)
9283 r = sendfile(in_fd, out_fd, pos, &count, NULL, 0);
9286 r = sendfile(in_fd, out_fd, pos, (
size_t)count, NULL, &sbytes, 0);
9288 if (r != 0 && sbytes == 0)
return -1;
9295 return (ssize_t)sbytes;
9306 struct stat src_stat, dst_stat;
9320 if (!
S_ISREG(src_stat.st_mode))
9329 if ((dst_stat.st_mode & S_IFMT) != S_IFSOCK)
9333 use_pread = src_offset != (
off_t)-1;
9336 if (copy_length == (
off_t)-1) {
9338 copy_length = src_stat.st_size - src_offset;
9343 if (cur == (
off_t)-1 && errno) {
9348 copy_length = src_stat.st_size - cur;
9353 # if SIZEOF_OFF_T > SIZEOF_SIZE_T
9357 ss = (ssize_t)copy_length;
9360 ss = simple_sendfile(stp->
dst_fd, stp->
src_fd, &src_offset, ss);
9363 ss = simple_sendfile(stp->
dst_fd, stp->
src_fd, NULL, ss);
9368 if (0 < copy_length) {
9369 goto retry_sendfile;
9374 goto retry_sendfile;
9382 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
9398 goto retry_sendfile;
9400 stp->
syserr =
"sendfile";
9414 return read(fd, buf, count);
9422 if (offset == (
off_t)-1) {
9427 ss = pread(stp->
src_fd, buf, len, offset);
9441 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
9453 stp->
syserr = offset == (
off_t)-1 ?
"read" :
"pread";
9466 ss = write(stp->
dst_fd, buf+off, len);
9499 use_eof = copy_length == (
off_t)-1;
9501 use_pread = src_offset != (
off_t)-1;
9512 src_offset = (
off_t)-1;
9516 while (use_eof || 0 < copy_length) {
9517 if (!use_eof && copy_length < (
off_t)
sizeof(
buf)) {
9518 len = (size_t)copy_length;
9552 ret = nogvl_copy_stream_sendfile(stp);
9569 const int buflen = 16*1024;
9591 l = buflen < rest ? buflen : (
long)rest;
9606 if (off != (
off_t)-1)
9611 stp->
total += numwrote;
9637 VALUE src_io, dst_io;
9638 rb_io_t *src_fptr = 0, *dst_fptr = 0;
9653 if (
NIL_P(src_io)) {
9655 int oflags = O_RDONLY;
9668 src_fd = src_fptr->
fd;
9680 if (
NIL_P(dst_io)) {
9682 int oflags = O_WRONLY|O_CREAT|O_TRUNC;
9700 dst_fd = dst_fptr->fd;
9712 size_t len = src_fptr->
rbuf.
len;
9731 if (dst_fptr &&
io_fflush(dst_fptr) < 0) {
9738 if (src_fd == -1 || dst_fd == -1) {
9805 rb_scan_args(argc, argv,
"22", &src, &dst, &length, &src_offset);
9815 if (
NIL_P(src_offset))
9840 if (fptr->
encs.enc2) {
9898 argc =
rb_scan_args(argc, argv,
"11:", &v1, &v2, &opt);
10126 return ARGF.current_file;
10202 VALUE tmp, str, length;
10206 if (!
NIL_P(length)) {
10225 if (
NIL_P(str)) str = tmp;
10228 if (
ARGF.next_p != -1) {
10234 else if (argc >= 1) {
10311 VALUE tmp, str, length;
10335 if (
ARGF.next_p == -1) {
10673 return ARGF.filename;
10704 return ARGF.current_file;
10764 if (
ARGF.init_p &&
ARGF.next_p == 0) {
10794 if (
ARGF.next_p != -1) {
10897 return ARGF.inplace;
11159 #define rb_intern(str) rb_intern_const(str)
11163 #include <sys/cygwin.h>
11164 static struct __cygwin_perfile pf[] =
11172 cygwin_internal(CW_PERFILE, pf);
11443 #if defined (_WIN32) || defined(__CYGWIN__)
11463 #if defined(O_NDELAY) || defined(O_NONBLOCK)
11464 # ifndef O_NONBLOCK
11465 # define O_NONBLOCK O_NDELAY
11477 # define O_BINARY 0