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;
1839 return (ssize_t)
io_bufread(buf, (
long)size, fptr);
1842 #define SMALLBUF 100
1852 #
if defined(__BEOS__) || defined(__HAIKU__)
1860 if (st.st_size >= pos && pos >= 0) {
1861 siz += st.st_size - pos;
1887 const char *sname, *dname;
1889 ecopts = fptr->
encs.ecopts;
1890 if (fptr->
encs.enc2) {
1908 #define MORE_CHAR_SUSPENDED Qtrue
1909 #define MORE_CHAR_FINISHED Qnil
1913 const unsigned char *ss, *sp, *se;
1914 unsigned char *ds, *
dp, *de;
1934 ss = sp = (
const unsigned char *)fptr->
rbuf.
ptr + fptr->
rbuf.
off;
1939 fptr->
rbuf.
off += (int)(sp - ss);
1940 fptr->
rbuf.
len -= (int)(sp - ss);
1941 fptr->
cbuf.
len += (int)(dp - ds);
1946 fptr->
rbuf.
off -= putbackable;
1947 fptr->
rbuf.
len += putbackable;
1954 if (cbuf_len0 != fptr->
cbuf.
len)
1971 fptr->
cbuf.
len += (int)(dp - ds);
1978 if (cbuf_len0 != fptr->
cbuf.
len)
2086 if (siz == 0) siz = BUFSIZ;
2091 if (n == 0 && bytes == 0) {
2097 if (bytes < siz)
break;
2112 oflags =
fcntl(fptr->
fd, F_GETFL);
2136 if ((len =
NUM2LONG(length)) < 0) {
2455 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
2461 if (
NIL_P(length)) {
2475 if (len == 0)
return str;
2478 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
2479 previous_mode = set_binary_mode_with_seek_cur(fptr);
2482 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
2483 if (previous_mode == O_TEXT) {
2484 setmode(fptr->
fd, O_TEXT);
2488 if (fptr->
fd < 0)
return Qnil;
2521 if (0 < limit && limit < searchlen)
2522 searchlen = (int)limit;
2523 e = memchr(p, delim, searchlen);
2525 int len = (int)(e-p+1);
2564 if (limit > 0 && pending > limit) pending = limit;
2565 e = memchr(p, delim, pending);
2566 if (e) pending = e - p + 1;
2579 if (e)
return delim;
2603 if (*p != term)
return TRUE;
2605 while (--i && *++p == term);
2608 const char *e = p +
cnt;
2610 while ((p += i) < e &&
rb_enc_ascget(p, e, &i, enc) == term);
2626 if (cnt >
sizeof buf) cnt =
sizeof buf;
2627 if (*p != term)
return TRUE;
2629 while (--i && *++p == term);
2653 e = memchr(p,
'\n', pending);
2655 pending = (int)(e - p + 1);
2681 if (io ==
ARGF.current_file) {
2708 else if (2 <= argc) {
2719 if (enc_io != enc_rs &&
2747 if (
NIL_P(rs) && limit < 0) {
2751 else if (limit == 0) {
2760 int c, newline = -1;
2761 const char *rsptr = 0;
2764 int extra_limit = 16;
2788 newline = (
unsigned char)rsptr[rslen - 1];
2792 while ((c =
appendline(fptr, newline, &str, &limit)) !=
EOF) {
2793 const char *s, *
p, *pp, *e;
2801 if (pp != p)
continue;
2802 if (!rspara)
rscheck(rsptr, rslen, rs);
2803 if (
memcmp(p, rsptr, rslen) == 0)
break;
2835 if (io ==
ARGF.current_file) {
2998 VALUE line, ary, rs;
3304 if (fptr->
encs.enc) {
3523 #if SIZEOF_LONG > SIZEOF_INT
3565 if (isatty(fptr->
fd) == 0)
3570 #if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
3593 if (io != write_io) {
3595 if (fptr && 0 <= (fd = fptr->
fd)) {
3597 if (!(ret & FD_CLOEXEC))
return Qfalse;
3602 if (fptr && 0 <= (fd = fptr->
fd)) {
3604 if (!(ret & FD_CLOEXEC))
return Qfalse;
3609 #define rb_io_close_on_exec_p rb_f_notimplement
3612 #if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
3628 int flag =
RTEST(arg) ? FD_CLOEXEC : 0;
3634 if (io != write_io) {
3636 if (fptr && 0 <= (fd = fptr->
fd)) {
3638 if ((ret & FD_CLOEXEC) != flag) {
3639 ret = (ret & ~FD_CLOEXEC) | flag;
3640 ret =
fcntl(fd, F_SETFD, ret);
3648 if (fptr && 0 <= (fd = fptr->
fd)) {
3650 if ((ret & FD_CLOEXEC) != flag) {
3651 ret = (ret & ~FD_CLOEXEC) | flag;
3652 ret =
fcntl(fd, F_SETFD, ret);
3659 #define rb_io_set_close_on_exec rb_f_notimplement
3662 #define FMODE_PREP (1<<16)
3663 #define IS_PREP_STDIO(f) ((f)->mode & FMODE_PREP)
3664 #define PREP_STDIO_NAME(f) (RSTRING_PTR((f)->pathv))
3669 unsigned char *ds, *
dp, *de;
3673 unsigned char buf[1024];
3679 de = buf +
sizeof(
buf);
3716 fptr->
wbuf.
len += (int)(dp - ds);
3772 else if (0 <= fptr->
fd) {
3776 if (close(fptr->
fd) < 0 &&
NIL_P(err))
3784 if (!
NIL_P(err) && !noraise) {
3841 if (!fptr)
return 0;
3882 if (io != write_io) {
3883 write_fptr =
RFILE(write_io)->fptr;
3884 if (write_fptr && 0 <= write_fptr->
fd) {
3889 fptr =
RFILE(io)->fptr;
3890 if (!fptr)
return Qnil;
3891 if (fptr->
fd < 0)
return Qnil;
3894 #if defined __APPLE__ && defined(__MACH__) && \
3895 (!defined(MAC_OS_X_VERSION_MIN_ALLOWED) || MAC_OS_X_VERSION_MIN_ALLOWED <= 1050)
3975 if (io != write_io) {
3976 write_fptr =
RFILE(write_io)->fptr;
3977 if (write_fptr && 0 <= write_fptr->
fd) {
3982 fptr =
RFILE(io)->fptr;
4028 if (io != write_io) {
4032 RFILE(io)->fptr = wfptr;
4091 if (io != write_io) {
4115 VALUE offset, ptrname;
4120 if (
rb_scan_args(argc, argv,
"11", &offset, &ptrname) == 2) {
4130 rb_warn(
"sysseek for buffered IO");
4133 pos = lseek(fptr->
fd, pos, whence);
4167 rb_warn(
"syswrite for buffered IO");
4207 if (ilen == 0)
return str;
4228 if (n == 0 && ilen > 0) {
4281 fptr->
encs.ecflags = 0;
4342 case FMODE_READWRITE:
4355 static const char bom_prefix[] =
"bom|utf-";
4356 enum {bom_prefix_len = (int)
sizeof(bom_prefix) - 1};
4358 const char *
p =
strchr(name,
':');
4361 return len > bom_prefix_len &&
STRNCASECMP(name, bom_prefix, bom_prefix_len) == 0;
4368 const char *m = modestr, *
p =
NULL;
4418 switch (oflags & (O_RDONLY|O_WRONLY|O_RDWR)) {
4430 if (oflags & O_APPEND) {
4433 if (oflags & O_TRUNC) {
4436 if (oflags & O_CREAT) {
4460 case FMODE_READWRITE:
4493 # define MODE_BINARY(a,b) ((oflags & O_BINARY) ? (b) : (a))
4495 # define MODE_BINARY(a,b) (a)
4497 int accmode = oflags & (O_RDONLY|O_WRONLY|O_RDWR);
4498 if (oflags & O_APPEND) {
4499 if (accmode == O_WRONLY) {
4502 if (accmode == O_RDWR) {
4506 switch (oflags & (O_RDONLY|O_WRONLY|O_RDWR)) {
4526 int default_ext = 0;
4537 *enc = (default_ext && intern != ext) ?
NULL : ext;
4558 long len = (p++) - estr;
4567 memcpy(encname, estr, len);
4568 encname[
len] =
'\0';
4579 memcpy(encname, estr, len);
4580 encname[
len] =
'\0';
4590 rb_warn(
"Unsupported encoding %s ignored", estr);
4596 if (*p ==
'-' && *(p+1) ==
'\0') {
4603 rb_warn(
"Unsupported encoding %s ignored", p);
4604 else if (idx2 == idx) {
4605 rb_warn(
"Ignoring internal encoding %s: it is identical to external encoding %s", p, estr);
4627 const char *
p =
strchr(modestr,
':');
4644 if (v !=
Qnil) encoding =
v;
4646 if (v !=
Qnil) extenc =
v;
4653 rb_warn(
"Ignoring encoding parameter '%s': %s_encoding is used",
4655 extenc ==
Qundef ?
"internal" :
"external");
4663 if (
NIL_P(intenc)) {
4670 if (*p ==
'-' && *(p+1) ==
'\0') {
4681 if (extencoding == intencoding) {
4685 if (!
NIL_P(encoding)) {
4706 int fmode = *fmode_p;
4714 if (!(fmode & FMODE_BINMODE) &&
4719 #if !DEFAULT_TEXTMODE
4720 else if (!(ecflags & ECONV_NEWLINE_DECORATOR_MASK)) {
4730 if (!
NIL_P(opthash)) {
4746 int *oflags_p,
int *fmode_p,
convconfig_t *convconfig_p)
4753 int has_enc = 0, has_vmode = 0;
4791 if (
NIL_P(opthash)) {
4795 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
4798 0, TEXTMODE_NEWLINE_DECORATOR_ON_WRITE) : 0;
4810 #if DEFAULT_TEXTMODE
4811 else if (
NIL_P(vmode)) {
4818 if (!
NIL_P(vmode)) {
4829 if (!
NIL_P(*vperm_p)) {
4841 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
4844 0, TEXTMODE_NEWLINE_DECORATOR_ON_WRITE) : 0;
4862 convconfig_p->enc = enc;
4863 convconfig_p->enc2 = enc2;
4864 convconfig_p->ecflags = ecflags;
4865 convconfig_p->ecopts = ecopts;
4924 file = fdopen(fd, modestr);
4935 file = fdopen(fd, modestr);
4949 if (setvbuf(file,
NULL, _IOFBF, 0) != 0)
4950 rb_warn(
"setvbuf() can't be honoured (fd=%d)", fd);
4958 if (isatty(fptr->
fd))
4968 VALUE b1, b2, b3, b4;
5054 convconfig->enc, convconfig->enc2);
5058 fptr->
encs = *convconfig;
5071 const char *
p =
strchr(modestr,
':');
5083 convconfig.ecflags = 0;
5084 convconfig.ecopts =
Qnil;
5107 #if defined(__CYGWIN__) || !defined(HAVE_FORK)
5130 if (list->
fptr == fptr) {
5136 while (list->
next) {
5163 #if !defined(HAVE_FORK) && !defined(_WIN32)
5218 popen_redirect(
struct popen_arg *
p)
5221 close(p->write_pair[1]);
5222 if (p->write_pair[0] != 0) {
5223 dup2(p->write_pair[0], 0);
5224 close(p->write_pair[0]);
5227 if (p->pair[1] != 1) {
5228 dup2(p->pair[1], 1);
5234 if (p->pair[1] != 1) {
5235 dup2(p->pair[1], 1);
5241 if (p->pair[0] != 0) {
5242 dup2(p->pair[0], 0);
5255 for (fd = lowfd; fd <=
max; fd++) {
5256 if (!
NIL_P(noclose_fds) &&
5260 ret =
fcntl(fd, F_GETFD);
5261 if (ret != -1 && !(ret & FD_CLOEXEC)) {
5262 fcntl(fd, F_SETFD, ret|FD_CLOEXEC);
5267 #define CONTIGUOUS_CLOSED_FDS 20
5269 if (max < fd + CONTIGUOUS_CLOSED_FDS)
5270 max = fd + CONTIGUOUS_CLOSED_FDS;
5276 popen_exec(
void *pp,
char *errmsg,
size_t errmsg_len)
5278 struct popen_arg *p = (
struct popen_arg*)pp;
5293 #if defined(HAVE_FORK)
5295 struct popen_arg arg;
5296 char errmsg[80] = {
'\0' };
5297 #elif defined(_WIN32)
5298 volatile VALUE argbuf;
5300 int pair[2], write_pair[2];
5302 #if !defined(HAVE_FORK)
5308 const char *cmd = 0;
5320 else if (eargp->
argc) {
5331 #if defined(HAVE_FORK)
5334 arg.pair[0] = arg.pair[1] = -1;
5335 arg.write_pair[0] = arg.write_pair[1] = -1;
5338 if (
rb_pipe(arg.write_pair) < 0)
5342 close(arg.write_pair[0]);
5343 close(arg.write_pair[1]);
5369 pid =
rb_fork_err(&status, popen_exec, &arg, arg.execp->redirect_fds, errmsg,
sizeof(errmsg));
5376 popen_redirect(&arg);
5389 close(arg.write_pair[0]);
5390 close(arg.write_pair[1]);
5400 close(arg.write_pair[0]);
5401 write_fd = arg.write_pair[1];
5403 else if (fmode & FMODE_READABLE) {
5411 #elif defined(_WIN32)
5415 if (argc >= (
int)(
FIXNUM_MAX /
sizeof(
char *))) {
5420 for (i = 0; i <
argc; ++
i) {
5425 switch (fmode & (FMODE_READABLE|FMODE_WRITABLE)) {
5426 case FMODE_READABLE|FMODE_WRITABLE:
5431 close(write_pair[0]);
5432 close(write_pair[1]);
5441 case FMODE_READABLE:
5447 case FMODE_WRITABLE:
5460 while ((pid = (args ?
5466 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
5478 if ((fmode & (FMODE_READABLE|FMODE_WRITABLE)) == (FMODE_READABLE|FMODE_WRITABLE)) {
5479 close(write_pair[0]);
5480 close(write_pair[1]);
5493 if ((fmode & FMODE_READABLE) && (fmode & FMODE_WRITABLE)) {
5496 close(write_pair[0]);
5497 write_fd = write_pair[1];
5499 else if (fmode & FMODE_READABLE) {
5516 fp = popen(cmd, modestr);
5529 fptr->
encs = *convconfig;
5530 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
5540 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
5542 fptr->
encs.ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
5548 if (0 <= write_fd) {
5551 write_fptr->
fd = write_fd;
5553 fptr->
mode &= ~FMODE_WRITABLE;
5558 #if defined (__CYGWIN__) || !defined(HAVE_FORK)
5571 return pipe_open(&earg, prog, modestr, fmode, convconfig);
5583 #if !defined(HAVE_FORK)
5585 "fork() function is unimplemented on this machine");
5587 return pipe_open(0, 0, modestr, fmode, convconfig);
5591 return pipe_open(&earg, prog, modestr, fmode, convconfig);
5680 const char *modestr;
5681 VALUE pname, pmode, port, tmp, opt;
5685 argc =
rb_scan_args(argc, argv,
"11:", &pname, &pmode, &opt);
5693 #if SIZEOF_LONG > SIZEOF_INT
5694 if (len > INT_MAX) {
5705 port =
pipe_open_s(pname, modestr, fmode, &convconfig);
5717 RBASIC(port)->klass = klass;
5726 VALUE *fname_p,
int *oflags_p,
int *fmode_p,
5729 VALUE opt, fname, vmode, vperm;
5733 argc =
rb_scan_args(argc, argv,
"12:", &fname, &vmode, &vperm, &opt);
5821 VALUE fname, vmode, vperm;
5826 rb_scan_args(argc, argv,
"12", &fname, &vmode, &vperm);
5837 if (
NIL_P(vperm)) perm = 0666;
5975 int redirect =
FALSE;
5983 VALUE tmp = argv[0];
6024 oflags, fmode, &convconfig, perm);
6053 if (fptr == orig)
return io;
6059 "%s can't change access mode from \"%s\" to \"%s\"",
6086 #
if defined (__CYGWIN__) || !defined(HAVE_FORK)
6096 if (
dup2(fd2, fd) < 0)
6104 if (
dup2(fd2, fd) < 0)
6152 if (
rb_scan_args(argc, argv,
"11", &fname, &nmode) == 1) {
6161 fptr =
RFILE(file)->fptr;
6167 if (!
NIL_P(nmode)) {
6171 (fptr->
mode & FMODE_READWRITE)) {
6173 "%s can't change access mode from \"%s\" to \"%s\"",
6179 fptr->
encs.ecflags = 0;
6208 if (close(fptr->
fd) < 0)
6227 if (dest == io)
return dest;
6240 #if defined (__CYGWIN__) || !defined(HAVE_FORK)
6255 if (io != write_io) {
6296 if (argc == 0)
return Qnil;
6344 for (i=0; i<
argc; i++) {
6450 if (len == 0)
return 0;
6452 return ptr[len - 1] == c;
6454 return rb_enc_ascget(ptr + ((len - 1) / n) * n, ptr + len, &n, enc) == c;
6506 for (i=0; i<
argc; i++) {
6585 for (i=0; i<
argc; i++) {
6591 else if (argc > 1) {
6643 (void)fwrite(mesg,
sizeof(
char),
len, stderr);
6700 if (path && strcmp(path,
"-")) klass =
rb_cFile;
6712 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
6713 fptr->
encs.ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
6826 int fd,
fmode, oflags = O_RDONLY;
6829 #if defined(HAVE_FCNTL) && defined(F_GETFL)
6837 argc =
rb_scan_args(argc, argv,
"11:", &fnum, &vmode, &opt);
6844 #if defined(HAVE_FCNTL) && defined(F_GETFL)
6845 oflags =
fcntl(fd, F_GETFL);
6851 #if defined(HAVE_FCNTL) && defined(F_GETFL)
6867 fp->
encs = convconfig;
6872 else if (
fileno(stdout) == fd)
6874 else if (
fileno(stderr) == fd)
6911 if (
RFILE(io)->fptr) {
6914 if (0 < argc && argc < 3) {
6934 rb_warn(
"%s::new() does not take block; use %s::open() instead",
6997 if (!
RTEST(autoclose))
7007 struct argf *p = ptr;
7017 struct argf *p = ptr;
7118 #define next_argv() argf_next_argv(argf)
7119 #define ARGF_GENERIC_INPUT_P() \
7120 (ARGF.current_file == rb_stdin && TYPE(ARGF.current_file) != T_FILE)
7121 #define ARGF_FORWARD(argc, argv) do {\
7122 if (ARGF_GENERIC_INPUT_P())\
7123 return argf_forward((argc), (argv), argf);\
7125 #define NEXT_ARGF_FORWARD(argc, argv) do {\
7126 if (!next_argv()) return Qnil;\
7127 ARGF_FORWARD((argc), (argv));\
7145 int stdout_binmode = 0;
7154 if (
ARGF.init_p == 0) {
7172 if (
ARGF.next_p == 1) {
7177 if (
strlen(fn) == 1 && fn[0] ==
'-') {
7180 rb_warn(
"Can't do inplace edit for stdio; skipping");
7190 #ifndef NO_SAFE_RENAME
7200 if (*
ARGF.inplace) {
7203 #ifdef NO_SAFE_RENAME
7207 rb_warn(
"Can't rename %s to %s: %s, skipping file",
7214 rb_warn(
"Can't rename %s to %s: %s, skipping file",
7222 #ifdef NO_SAFE_RENAME
7223 rb_fatal(
"Can't do inplace edit without backup");
7225 if (unlink(fn) < 0) {
7226 rb_warn(
"Can't remove %s: %s, skipping file",
7234 #ifndef NO_SAFE_RENAME
7237 fchmod(fw, st.st_mode);
7239 chmod(fn, st.st_mode);
7241 if (st.st_uid!=st2.st_uid || st.st_gid!=st2.st_gid) {
7244 err = fchown(fw, st.st_uid, st.st_gid);
7246 err =
chown(fn, st.st_uid, st.st_gid);
7248 if (err &&
getuid() == 0 && st2.st_uid == 0) {
7250 rb_warn(
"Can't set owner/group of %s to same as %s: %s, skipping file",
7264 if (!
ARGF.binmode) {
7268 if (!
NIL_P(write_io)) {
7274 if (
ARGF.encs.enc) {
7280 if (!
ARGF.binmode) {
7282 #ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
7283 fptr->
encs.ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
7294 else if (
ARGF.next_p == -1) {
7298 rb_warn(
"Can't do inplace edit for stdio");
7309 long lineno =
ARGF.lineno;
7330 ARGF.lineno = ++lineno;
7348 ARGF.last_lineno =
ARGF.lineno = n;
7540 long lineno =
ARGF.lineno;
7578 volatile VALUE port;
7593 #ifdef HAVE_SYS_SELECT_H
7594 #include <sys/select.h>
7617 if (max < fptr->fd) max = fptr->
fd;
7628 if (!
NIL_P(write)) {
7634 if (max < fptr->fd) max = fptr->
fd;
7641 if (!
NIL_P(except)) {
7648 if (max < fptr->fd) max = fptr->
fd;
7649 if (io != write_io) {
7652 if (max < fptr->fd) max = fptr->
fd;
7667 if (!pending && n == 0)
return Qnil;
7710 else if (io != write_io) {
7750 #ifdef HAVE_POSIX_FADVISE
7751 struct io_advise_struct {
7759 io_advise_internal(
void *
arg)
7761 struct io_advise_struct *ptr =
arg;
7762 return posix_fadvise(ptr->fd, ptr->offset, ptr->len, ptr->advice);
7768 #ifdef POSIX_FADV_NORMAL
7769 if (sym == sym_normal)
7770 return INT2NUM(POSIX_FADV_NORMAL);
7773 #ifdef POSIX_FADV_RANDOM
7774 if (sym == sym_random)
7775 return INT2NUM(POSIX_FADV_RANDOM);
7778 #ifdef POSIX_FADV_SEQUENTIAL
7779 if (sym == sym_sequential)
7780 return INT2NUM(POSIX_FADV_SEQUENTIAL);
7783 #ifdef POSIX_FADV_WILLNEED
7784 if (sym == sym_willneed)
7785 return INT2NUM(POSIX_FADV_WILLNEED);
7788 #ifdef POSIX_FADV_DONTNEED
7789 if (sym == sym_dontneed)
7790 return INT2NUM(POSIX_FADV_DONTNEED);
7793 #ifdef POSIX_FADV_NOREUSE
7794 if (sym == sym_noreuse)
7795 return INT2NUM(POSIX_FADV_NOREUSE);
7805 struct io_advise_struct ias;
7808 num_adv = io_advise_sym_to_const(advice);
7814 if (num_adv ==
Qnil)
7818 ias.advice =
NUM2INT(num_adv);
7819 ias.offset = offset;
7839 if (advice != sym_normal &&
7840 advice != sym_sequential &&
7841 advice != sym_random &&
7842 advice != sym_willneed &&
7843 advice != sym_dontneed &&
7844 advice != sym_noreuse) {
7899 rb_scan_args(argc, argv,
"12", &advice, &offset, &len);
7908 #ifdef HAVE_POSIX_FADVISE
7909 return do_io_advise(fptr, advice, off, l);
7976 if (
NIL_P(timeout)) {
7990 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
7992 #define NUM2IOCTLREQ(num) NUM2ULONG(num)
7995 #define NUM2IOCTLREQ(num) NUM2INT(num)
8026 #define DEFULT_IOCTL_NARG_LEN (256)
8030 linux_iocparm_len(ioctl_req_t
cmd)
8034 if ((cmd & 0xFFFF0000) == 0) {
8039 len = _IOC_SIZE(cmd);
8056 #define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
8060 len = IOCPARM_LEN(cmd);
8061 #elif defined(__linux__)
8062 len = linux_iocparm_len(cmd);
8073 typedef long fcntl_arg_t;
8076 typedef int fcntl_arg_t;
8087 len =
sizeof(fcntl_arg_t);
8095 #ifdef F_DUPFD_CLOEXEC
8096 case F_DUPFD_CLOEXEC:
8097 len =
sizeof(fcntl_arg_t);
8107 len =
sizeof(fcntl_arg_t);
8117 len =
sizeof(fcntl_arg_t);
8127 len =
sizeof(fcntl_arg_t);
8132 len =
sizeof(
struct f_owner_ex);
8137 len =
sizeof(
struct f_owner_ex);
8142 len =
sizeof(
struct flock);
8147 len =
sizeof(
struct flock);
8152 len =
sizeof(
struct flock);
8172 len =
sizeof(fcntl_arg_t);
8182 len =
sizeof(fcntl_arg_t);
8187 len =
sizeof(fcntl_arg_t);
8218 else if (arg ==
Qtrue) {
8300 static VALUE nogvl_fcntl(
void *ptr)
8302 struct fcntl_arg *
arg = ptr;
8304 #if defined(F_DUPFD)
8305 if (arg->cmd == F_DUPFD)
8308 return (
VALUE)
fcntl(arg->fd, arg->cmd, arg->narg);
8312 do_fcntl(
int fd,
int cmd,
long narg)
8315 struct fcntl_arg arg;
8322 #if defined(F_DUPFD)
8323 if (retval != -1 && cmd == F_DUPFD) {
8343 retval = do_fcntl(fptr->
fd, cmd, narg);
8383 return rb_fcntl(io, req, arg);
8386 #define rb_io_fcntl rb_f_notimplement
8389 #if defined(HAVE_SYSCALL) || defined(HAVE___SYSCALL)
8431 #if SIZEOF_VOIDP == 8 && defined(HAVE___SYSCALL) && SIZEOF_INT != 8
8432 # define SYSCALL __syscall
8433 # define NUM2SYSCALLID(x) NUM2LONG(x)
8434 # define RETVAL2NUM(x) LONG2NUM(x)
8435 # if SIZEOF_LONG == 8
8436 long num, retval = -1;
8437 # elif SIZEOF_LONG_LONG == 8
8438 long long num, retval = -1;
8440 # error ---->> it is asserted that __syscall takes the first argument and returns retval in 64bit signed integer. <<----
8443 # define SYSCALL syscall
8444 # define NUM2SYSCALLID(x) NUM2LONG(x)
8445 # define RETVAL2NUM(x) LONG2NUM(x)
8453 long num, retval = -1;
8455 # define SYSCALL syscall
8456 # define NUM2SYSCALLID(x) NUM2INT(x)
8457 # define RETVAL2NUM(x) INT2NUM(x)
8458 int num, retval = -1;
8463 rb_warning(
"We plan to remove a syscall function at future release. DL(Fiddle) provides safer alternative.");
8471 num = NUM2SYSCALLID(argv[0]); ++
argv;
8472 for (i = argc - 1; i--; ) {
8487 retval = SYSCALL(num);
8490 retval = SYSCALL(num, arg[0]);
8493 retval = SYSCALL(num, arg[0],arg[1]);
8496 retval = SYSCALL(num, arg[0],arg[1],arg[2]);
8499 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3]);
8502 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4]);
8505 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5]);
8508 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6]);
8512 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8516 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8520 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8521 arg[7], arg[8], arg[9]);
8524 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8525 arg[7], arg[8], arg[9], arg[10]);
8528 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8529 arg[7], arg[8], arg[9], arg[10], arg[11]);
8532 retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
8533 arg[7], arg[8], arg[9], arg[10], arg[11], arg[12]);
8540 return RETVAL2NUM(retval);
8542 #undef NUM2SYSCALLID
8546 #define rb_f_syscall rb_f_notimplement
8559 int ecflags = fptr->
encs.ecflags;
8605 fptr->
encs.enc = enc;
8606 fptr->
encs.enc2 = enc2;
8607 fptr->
encs.ecflags = ecflags;
8608 fptr->
encs.ecopts = ecopts;
8683 int pipes[2],
state;
8690 argc =
rb_scan_args(argc, argv,
"02:", &v1, &v2, &opt);
8717 #if DEFAULT_TEXTMODE
8722 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
8728 fptr->
mode |= fmode;
8729 #if DEFAULT_TEXTMODE
8735 fptr2->
mode |= fmode;
8775 #if SIZEOF_LONG > SIZEOF_INT
8831 int orig_argc =
argc;
8938 if (!
NIL_P(offset)) {
8979 arg.
argc = (argc > 1) ? 1 : 0;
8980 if (!
NIL_P(offset)) {
8995 VALUE string, offset, opt;
9006 int mode = O_WRONLY|O_CREAT;
9010 if (
NIL_P(offset)) mode |= O_TRUNC;
9020 if (!
NIL_P(offset)) {
9144 #if defined(ERESTART)
9205 #ifdef HAVE_SENDFILE
9208 # define USE_SENDFILE
9210 # ifdef HAVE_SYS_SENDFILE_H
9211 # include <sys/sendfile.h>
9217 return sendfile(out_fd, in_fd, offset, (
size_t)count);
9220 # elif 0 || defined(__APPLE__)
9224 # define USE_SENDFILE
9226 # ifdef HAVE_SYS_UIO_H
9227 # include <sys/uio.h>
9231 simple_sendfile(
int out_fd,
int in_fd,
off_t *offset,
off_t count)
9237 r = sendfile(in_fd, out_fd, pos, &count, NULL, 0);
9240 r = sendfile(in_fd, out_fd, pos, (
size_t)count, NULL, &sbytes, 0);
9242 if (r != 0 && sbytes == 0)
return -1;
9249 return (ssize_t)sbytes;
9260 struct stat src_stat, dst_stat;
9274 if (!
S_ISREG(src_stat.st_mode))
9283 if ((dst_stat.st_mode & S_IFMT) != S_IFSOCK)
9287 use_pread = src_offset != (
off_t)-1;
9290 if (copy_length == (
off_t)-1) {
9292 copy_length = src_stat.st_size - src_offset;
9297 if (cur == (
off_t)-1 && errno) {
9302 copy_length = src_stat.st_size - cur;
9307 # if SIZEOF_OFF_T > SIZEOF_SIZE_T
9311 ss = (ssize_t)copy_length;
9314 ss = simple_sendfile(stp->
dst_fd, stp->
src_fd, &src_offset, ss);
9317 ss = simple_sendfile(stp->
dst_fd, stp->
src_fd, NULL, ss);
9322 if (0 < copy_length) {
9323 goto retry_sendfile;
9328 goto retry_sendfile;
9336 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
9352 goto retry_sendfile;
9354 stp->
syserr =
"sendfile";
9368 return read(fd, buf, count);
9376 if (offset == (
off_t)-1) {
9381 ss = pread(stp->
src_fd, buf, len, offset);
9395 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
9407 stp->
syserr = offset == (
off_t)-1 ?
"read" :
"pread";
9420 ss = write(stp->
dst_fd, buf+off, len);
9453 use_eof = copy_length == (
off_t)-1;
9455 use_pread = src_offset != (
off_t)-1;
9466 src_offset = (
off_t)-1;
9470 while (use_eof || 0 < copy_length) {
9471 if (!use_eof && copy_length < (
off_t)
sizeof(
buf)) {
9472 len = (size_t)copy_length;
9506 ret = nogvl_copy_stream_sendfile(stp);
9523 const int buflen = 16*1024;
9545 l = buflen < rest ? buflen : (
long)rest;
9560 if (off != (
off_t)-1)
9565 stp->
total += numwrote;
9591 VALUE src_io, dst_io;
9592 rb_io_t *src_fptr = 0, *dst_fptr = 0;
9607 if (
NIL_P(src_io)) {
9609 int oflags = O_RDONLY;
9622 src_fd = src_fptr->
fd;
9634 if (
NIL_P(dst_io)) {
9636 int oflags = O_WRONLY|O_CREAT|O_TRUNC;
9654 dst_fd = dst_fptr->fd;
9666 size_t len = src_fptr->
rbuf.
len;
9685 if (dst_fptr &&
io_fflush(dst_fptr) < 0) {
9692 if (src_fd == -1 || dst_fd == -1) {
9759 rb_scan_args(argc, argv,
"22", &src, &dst, &length, &src_offset);
9769 if (
NIL_P(src_offset))
9794 if (fptr->
encs.enc2) {
9852 argc =
rb_scan_args(argc, argv,
"11:", &v1, &v2, &opt);
10080 return ARGF.current_file;
10156 VALUE tmp, str, length;
10160 if (!
NIL_P(length)) {
10179 if (
NIL_P(str)) str = tmp;
10182 if (
ARGF.next_p != -1) {
10188 else if (argc >= 1) {
10265 VALUE tmp, str, length;
10289 if (
ARGF.next_p == -1) {
10627 return ARGF.filename;
10658 return ARGF.current_file;
10718 if (
ARGF.init_p &&
ARGF.next_p == 0) {
10748 if (
ARGF.next_p != -1) {
10851 return ARGF.inplace;
11113 #define rb_intern(str) rb_intern_const(str)
11117 #include <sys/cygwin.h>
11118 static struct __cygwin_perfile pf[] =
11126 cygwin_internal(CW_PERFILE, pf);
11397 #if defined (_WIN32) || defined(__CYGWIN__)
11417 #if defined(O_NDELAY) || defined(O_NONBLOCK)
11418 # ifndef O_NONBLOCK
11419 # define O_NONBLOCK O_NDELAY
11431 # define O_BINARY 0