* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,

ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
  Use own buffering mechanism instead of stdio.

* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
  EOF flag removed.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2004-12-06 08:40:30 +00:00
Родитель 35091fdda5
Коммит 04f36c2bba
12 изменённых файлов: 540 добавлений и 622 удалений

Просмотреть файл

@ -1,3 +1,12 @@
Mon Dec 6 17:32:38 2004 Tanaka Akira <akr@m17n.org>
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
Mon Dec 6 17:15:17 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* test/socket/test_socket.rb (TestBasicSocket#test_setsockopt):

Просмотреть файл

@ -40,15 +40,12 @@ io_ready_p(io)
VALUE io;
{
OpenFile *fptr;
FILE *fp;
int n;
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
fp = fptr->f;
if (feof(fp)) return Qfalse;
if (rb_read_pending(fp)) return Qtrue;
if (ioctl(fileno(fp), FIONREAD, &n)) rb_sys_fail(0);
if (rb_io_read_pending(fptr)) return Qtrue;
if (ioctl(fptr->fd, FIONREAD, &n)) rb_sys_fail(0);
if (n > 0) return INT2NUM(n);
return Qnil;
}
@ -68,7 +65,6 @@ io_wait(argc, argv, io)
{
OpenFile *fptr;
fd_set rd;
FILE *fp;
int fd, n;
VALUE timeout;
struct timeval *tp, timerec;
@ -84,16 +80,14 @@ io_wait(argc, argv, io)
tp = &timerec;
}
fp = fptr->f;
if (feof(fp)) return Qfalse;
if (rb_read_pending(fp)) return Qtrue;
fd = fileno(fp);
if (rb_io_read_pending(fptr)) return Qtrue;
fd = fptr->fd;
FD_ZERO(&rd);
FD_SET(fd, &rd);
if (rb_thread_select(fd + 1, &rd, NULL, NULL, tp) < 0)
rb_sys_fail(0);
rb_io_check_closed(fptr);
if (ioctl(fileno(fp), FIONREAD, &n)) rb_sys_fail(0);
if (ioctl(fptr->fd, FIONREAD, &n)) rb_sys_fail(0);
if (n > 0) return io;
return Qnil;
}

Просмотреть файл

@ -429,7 +429,7 @@ ossl_ssl_setup(VALUE self)
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
rb_io_check_writable(fptr);
SSL_set_fd(ssl, TO_SOCKET(fileno(fptr->f)));
SSL_set_fd(ssl, TO_SOCKET(fptr->fd));
}
return Qtrue;
@ -505,7 +505,7 @@ ossl_ssl_read(int argc, VALUE *argv, VALUE self)
if (ssl) {
if(SSL_pending(ssl) <= 0)
rb_thread_wait_fd(fileno(fptr->f));
rb_thread_wait_fd(fptr->fd);
for (;;){
nread = SSL_read(ssl, RSTRING(str)->ptr, RSTRING(str)->len);
switch(SSL_get_error(ssl, nread)){

Просмотреть файл

@ -427,11 +427,13 @@ pty_getpty(argc, argv, self)
establishShell(argc, argv, &info);
rfptr->mode = rb_io_mode_flags("r");
rfptr->f = fdopen(info.fd, "r");
rfptr->fd = info.fd;
rfptr->f = rb_fdopen(info.fd, "r");
rfptr->path = strdup(SlaveName);
wfptr->mode = rb_io_mode_flags("w") | FMODE_SYNC;
wfptr->f = fdopen(dup(info.fd), "w");
wfptr->fd = dup(info.fd);
wfptr->f = rb_fdopen(wfptr->fd, "w");
wfptr->path = strdup(SlaveName);
res = rb_ary_new2(3);

Просмотреть файл

@ -182,8 +182,8 @@ init_sock(sock, fd)
OpenFile *fp;
MakeOpenFile(sock, fp);
fp->f = rb_fdopen(fd, "r");
fp->f2 = rb_fdopen(fd, "w");
fp->fd = fd;
fp->f = rb_fdopen(fd, "r+");
fp->mode = FMODE_READWRITE;
if (do_not_reverse_lookup) {
fp->mode |= FMODE_NOREVLOOKUP;
@ -228,7 +228,7 @@ bsock_shutdown(argc, argv, sock)
}
}
GetOpenFile(sock, fptr);
if (shutdown(fileno(fptr->f), how) == -1)
if (shutdown(fptr->fd, how) == -1)
rb_sys_fail(0);
return INT2FIX(0);
@ -244,7 +244,7 @@ bsock_close_read(sock)
rb_raise(rb_eSecurityError, "Insecure: can't close socket");
}
GetOpenFile(sock, fptr);
shutdown(fileno(fptr->f), 0);
shutdown(fptr->fd, 0);
if (!(fptr->mode & FMODE_WRITABLE)) {
return rb_io_close(sock);
}
@ -266,7 +266,7 @@ bsock_close_write(sock)
if (!(fptr->mode & FMODE_READABLE)) {
return rb_io_close(sock);
}
shutdown(fileno(fptr->f2), 1);
shutdown(fptr->fd, 1);
fptr->mode &= ~FMODE_WRITABLE;
return Qnil;
@ -306,7 +306,7 @@ bsock_setsockopt(sock, lev, optname, val)
break;
}
if (setsockopt(fileno(fptr->f), level, option, v, vlen) < 0)
if (setsockopt(fptr->fd, level, option, v, vlen) < 0)
rb_sys_fail(fptr->path);
return INT2FIX(0);
@ -328,7 +328,7 @@ bsock_getsockopt(sock, lev, optname)
buf = ALLOCA_N(char,len);
GetOpenFile(sock, fptr);
if (getsockopt(fileno(fptr->f), level, option, buf, &len) < 0)
if (getsockopt(fptr->fd, level, option, buf, &len) < 0)
rb_sys_fail(fptr->path);
return rb_str_new(buf, len);
@ -346,7 +346,7 @@ bsock_getsockname(sock)
OpenFile *fptr;
GetOpenFile(sock, fptr);
if (getsockname(fileno(fptr->f), (struct sockaddr*)buf, &len) < 0)
if (getsockname(fptr->fd, (struct sockaddr*)buf, &len) < 0)
rb_sys_fail("getsockname(2)");
return rb_str_new(buf, len);
}
@ -360,7 +360,7 @@ bsock_getpeername(sock)
OpenFile *fptr;
GetOpenFile(sock, fptr);
if (getpeername(fileno(fptr->f), (struct sockaddr*)buf, &len) < 0)
if (getpeername(fptr->fd, (struct sockaddr*)buf, &len) < 0)
rb_sys_fail("getpeername(2)");
return rb_str_new(buf, len);
}
@ -374,15 +374,13 @@ bsock_send(argc, argv, sock)
VALUE mesg, to;
VALUE flags;
OpenFile *fptr;
FILE *f;
int fd, n;
rb_secure(4);
rb_scan_args(argc, argv, "21", &mesg, &flags, &to);
GetOpenFile(sock, fptr);
f = GetWriteFile(fptr);
fd = fileno(f);
fd = fptr->fd;
rb_thread_fd_writable(fd);
StringValue(mesg);
retry:
@ -465,10 +463,10 @@ s_recvfrom(sock, argc, argv, from)
else flags = NUM2INT(flg);
GetOpenFile(sock, fptr);
if (rb_read_pending(fptr->f)) {
if (rb_io_read_pending(fptr)) {
rb_raise(rb_eIOError, "recv for buffered IO");
}
fd = fileno(fptr->f);
fd = fptr->fd;
buflen = NUM2INT(len);
str = rb_tainted_str_new(0, buflen);
@ -1123,8 +1121,7 @@ socks_s_close(sock)
rb_raise(rb_eSecurityError, "Insecure: can't close socket");
}
GetOpenFile(sock, fptr);
shutdown(fileno(fptr->f), 2);
shutdown(fileno(fptr->f2), 2);
shutdown(fptr->fd, 2);
return rb_io_close(sock);
}
#endif
@ -1276,7 +1273,7 @@ tcp_accept(sock)
GetOpenFile(sock, fptr);
fromlen = sizeof(from);
return s_accept(rb_cTCPSocket, fileno(fptr->f),
return s_accept(rb_cTCPSocket, fptr->fd,
(struct sockaddr*)&from, &fromlen);
}
@ -1290,7 +1287,7 @@ tcp_sysaccept(sock)
GetOpenFile(sock, fptr);
fromlen = sizeof(from);
return s_accept(0, fileno(fptr->f), (struct sockaddr*)&from, &fromlen);
return s_accept(0, fptr->fd, (struct sockaddr*)&from, &fromlen);
}
#ifdef HAVE_SYS_UN_H
@ -1367,7 +1364,7 @@ ip_addr(sock)
GetOpenFile(sock, fptr);
if (getsockname(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0)
if (getsockname(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
rb_sys_fail("getsockname(2)");
return ipaddr((struct sockaddr*)&addr, fptr->mode & FMODE_NOREVLOOKUP);
}
@ -1382,7 +1379,7 @@ ip_peeraddr(sock)
GetOpenFile(sock, fptr);
if (getpeername(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0)
if (getpeername(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
rb_sys_fail("getpeername(2)");
return ipaddr((struct sockaddr*)&addr, fptr->mode & FMODE_NOREVLOOKUP);
}
@ -1464,7 +1461,7 @@ udp_connect(sock, host, port)
rb_secure(3);
GetOpenFile(sock, fptr);
arg.res = sock_addrinfo(host, port, SOCK_DGRAM, 0);
arg.fd = fileno(fptr->f);
arg.fd = fptr->fd;
ret = rb_ensure(udp_connect_internal, (VALUE)&arg,
RUBY_METHOD_FUNC(freeaddrinfo), (VALUE)arg.res);
if (!ret) rb_sys_fail("connect(2)");
@ -1482,7 +1479,7 @@ udp_bind(sock, host, port)
GetOpenFile(sock, fptr);
res0 = sock_addrinfo(host, port, SOCK_DGRAM, 0);
for (res = res0; res; res = res->ai_next) {
if (bind(fileno(fptr->f), res->ai_addr, res->ai_addrlen) < 0) {
if (bind(fptr->fd, res->ai_addr, res->ai_addrlen) < 0) {
continue;
}
freeaddrinfo(res0);
@ -1501,7 +1498,6 @@ udp_send(argc, argv, sock)
{
VALUE mesg, flags, host, port;
OpenFile *fptr;
FILE *f;
int n;
struct addrinfo *res0, *res;
@ -1513,17 +1509,16 @@ udp_send(argc, argv, sock)
GetOpenFile(sock, fptr);
res0 = sock_addrinfo(host, port, SOCK_DGRAM, 0);
f = GetWriteFile(fptr);
StringValue(mesg);
for (res = res0; res; res = res->ai_next) {
retry:
n = sendto(fileno(f), RSTRING(mesg)->ptr, RSTRING(mesg)->len, NUM2INT(flags),
n = sendto(fptr->fd, RSTRING(mesg)->ptr, RSTRING(mesg)->len, NUM2INT(flags),
res->ai_addr, res->ai_addrlen);
if (n >= 0) {
freeaddrinfo(res0);
return INT2FIX(n);
}
if (rb_io_wait_writable(fileno(f))) {
if (rb_io_wait_writable(fptr->fd)) {
goto retry;
}
}
@ -1550,7 +1545,7 @@ unix_path(sock)
if (fptr->path == 0) {
struct sockaddr_un addr;
socklen_t len = sizeof(addr);
if (getsockname(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0)
if (getsockname(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
rb_sys_fail(0);
fptr->path = strdup(addr.sun_path);
}
@ -1606,7 +1601,7 @@ unix_send_io(sock, val)
if (rb_obj_is_kind_of(val, rb_cIO)) {
OpenFile *valfptr;
GetOpenFile(val, valfptr);
fd = fileno(valfptr->f);
fd = valfptr->fd;
}
else if (FIXNUM_P(val)) {
fd = FIX2INT(val);
@ -1640,7 +1635,7 @@ unix_send_io(sock, val)
msg.msg_accrightslen = sizeof(fd);
#endif
if (sendmsg(fileno(fptr->f), &msg, 0) == -1)
if (sendmsg(fptr->fd, &msg, 0) == -1)
rb_sys_fail("sendmsg(2)");
return Qnil;
@ -1692,7 +1687,7 @@ unix_recv_io(argc, argv, sock)
GetOpenFile(sock, fptr);
thread_read_select(fileno(fptr->f));
thread_read_select(fptr->fd);
msg.msg_name = NULL;
msg.msg_namelen = 0;
@ -1716,7 +1711,7 @@ unix_recv_io(argc, argv, sock)
fd = -1;
#endif
if (recvmsg(fileno(fptr->f), &msg, 0) == -1)
if (recvmsg(fptr->fd, &msg, 0) == -1)
rb_sys_fail("recvmsg(2)");
if (
@ -1765,7 +1760,7 @@ unix_accept(sock)
GetOpenFile(sock, fptr);
fromlen = sizeof(struct sockaddr_un);
return s_accept(rb_cUNIXSocket, fileno(fptr->f),
return s_accept(rb_cUNIXSocket, fptr->fd,
(struct sockaddr*)&from, &fromlen);
}
@ -1779,7 +1774,7 @@ unix_sysaccept(sock)
GetOpenFile(sock, fptr);
fromlen = sizeof(struct sockaddr_un);
return s_accept(0, fileno(fptr->f), (struct sockaddr*)&from, &fromlen);
return s_accept(0, fptr->fd, (struct sockaddr*)&from, &fromlen);
}
#ifdef HAVE_SYS_UN_H
@ -1802,7 +1797,7 @@ unix_addr(sock)
GetOpenFile(sock, fptr);
if (getsockname(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0)
if (getsockname(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
rb_sys_fail("getsockname(2)");
if (len == 0)
addr.sun_path[0] = '\0';
@ -1819,7 +1814,7 @@ unix_peeraddr(sock)
GetOpenFile(sock, fptr);
if (getpeername(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0)
if (getpeername(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
rb_sys_fail("getsockname(2)");
if (len == 0)
addr.sun_path[0] = '\0';
@ -1987,7 +1982,7 @@ sock_connect(sock, addr)
StringValue(addr);
GetOpenFile(sock, fptr);
fd = fileno(fptr->f);
fd = fptr->fd;
rb_str_locktmp(addr);
n = ruby_connect(fd, (struct sockaddr*)RSTRING(addr)->ptr, RSTRING(addr)->len, 0);
rb_str_unlocktmp(addr);
@ -2006,7 +2001,7 @@ sock_bind(sock, addr)
StringValue(addr);
GetOpenFile(sock, fptr);
if (bind(fileno(fptr->f), (struct sockaddr*)RSTRING(addr)->ptr, RSTRING(addr)->len) < 0)
if (bind(fptr->fd, (struct sockaddr*)RSTRING(addr)->ptr, RSTRING(addr)->len) < 0)
rb_sys_fail("bind(2)");
return INT2FIX(0);
@ -2020,7 +2015,7 @@ sock_listen(sock, log)
rb_secure(4);
GetOpenFile(sock, fptr);
if (listen(fileno(fptr->f), NUM2INT(log)) < 0)
if (listen(fptr->fd, NUM2INT(log)) < 0)
rb_sys_fail("listen(2)");
return INT2FIX(0);
@ -2045,7 +2040,7 @@ sock_accept(sock)
socklen_t len = sizeof buf;
GetOpenFile(sock, fptr);
sock2 = s_accept(rb_cSocket,fileno(fptr->f),(struct sockaddr*)buf,&len);
sock2 = s_accept(rb_cSocket,fptr->fd,(struct sockaddr*)buf,&len);
return rb_assoc_new(sock2, rb_str_new(buf, len));
}
@ -2060,7 +2055,7 @@ sock_sysaccept(sock)
socklen_t len = sizeof buf;
GetOpenFile(sock, fptr);
sock2 = s_accept(0,fileno(fptr->f),(struct sockaddr*)buf,&len);
sock2 = s_accept(0,fptr->fd,(struct sockaddr*)buf,&len);
return rb_assoc_new(sock2, rb_str_new(buf, len));
}

Просмотреть файл

@ -20,8 +20,6 @@
#include <sys/fcntl.h>
#endif
#define STRIO_EOF FMODE_SYNC
struct StringIO {
VALUE string;
long pos;
@ -490,7 +488,6 @@ strio_rewind(self)
struct StringIO *ptr = StringIO(self);
ptr->pos = 0;
ptr->lineno = 0;
ptr->flags &= ~STRIO_EOF;
return INT2FIX(0);
}
@ -522,7 +519,6 @@ strio_seek(argc, argv, self)
error_inval(0);
}
ptr->pos = offset;
ptr->flags &= ~STRIO_EOF;
return INT2FIX(0);
}
@ -557,7 +553,6 @@ strio_getc(self)
struct StringIO *ptr = readable(StringIO(self));
int c;
if (ptr->pos >= RSTRING(ptr->string)->len) {
ptr->flags |= STRIO_EOF;
return Qnil;
}
c = RSTRING(ptr->string)->ptr[ptr->pos++];
@ -588,7 +583,6 @@ strio_ungetc(self, ch)
OBJ_INFECT(ptr->string, self);
}
--ptr->pos;
ptr->flags &= ~STRIO_EOF;
}
return Qnil;
}
@ -661,7 +655,6 @@ strio_getline(argc, argv, ptr)
}
if (ptr->pos >= (n = RSTRING(ptr->string)->len)) {
ptr->flags |= STRIO_EOF;
return Qnil;
}
s = RSTRING(ptr->string)->ptr;
@ -674,7 +667,6 @@ strio_getline(argc, argv, ptr)
p = s;
while (*p == '\n') {
if (++p == e) {
ptr->flags |= STRIO_EOF;
return Qnil;
}
}
@ -858,11 +850,6 @@ strio_read(argc, argv, self)
rb_raise(rb_eArgError, "negative length %ld given", len);
}
if (len > 0 && ptr->pos >= RSTRING(ptr->string)->len) {
ptr->flags |= STRIO_EOF;
if (!NIL_P(str)) rb_str_resize(str, 0);
return Qnil;
}
else if (ptr->flags & STRIO_EOF) {
if (!NIL_P(str)) rb_str_resize(str, 0);
return Qnil;
}
@ -873,7 +860,6 @@ strio_read(argc, argv, self)
olen = -1;
len = RSTRING(ptr->string)->len;
if (len <= ptr->pos) {
ptr->flags |= STRIO_EOF;
if (NIL_P(str)) {
str = rb_str_new(0, 0);
}
@ -899,13 +885,12 @@ strio_read(argc, argv, self)
MEMCPY(RSTRING(str)->ptr, RSTRING(ptr->string)->ptr + ptr->pos, char, len);
}
if (NIL_P(str)) {
if (!(ptr->flags & STRIO_EOF)) str = rb_str_new(0, 0);
str = rb_str_new(0, 0);
len = 0;
}
else {
ptr->pos += len = RSTRING(str)->len;
}
if (olen < 0 || olen > len) ptr->flags |= STRIO_EOF;
return str;
}

27
file.c
Просмотреть файл

@ -639,7 +639,7 @@ rb_stat(file, st)
OpenFile *fptr;
GetOpenFile(tmp, fptr);
return fstat(fileno(fptr->f), st);
return fstat(fptr->fd, st);
}
FilePathValue(file);
return stat(StringValueCStr(file), st);
@ -693,7 +693,7 @@ rb_io_stat(obj)
struct stat st;
GetOpenFile(obj, fptr);
if (fstat(fileno(fptr->f), &st) == -1) {
if (fstat(fptr->fd, &st) == -1) {
rb_sys_fail(fptr->path);
}
return stat_new(&st);
@ -1531,7 +1531,7 @@ rb_file_atime(obj)
struct stat st;
GetOpenFile(obj, fptr);
if (fstat(fileno(fptr->f), &st) == -1) {
if (fstat(fptr->fd, &st) == -1) {
rb_sys_fail(fptr->path);
}
return rb_time_new(st.st_atime, 0);
@ -1576,7 +1576,7 @@ rb_file_mtime(obj)
struct stat st;
GetOpenFile(obj, fptr);
if (fstat(fileno(fptr->f), &st) == -1) {
if (fstat(fptr->fd, &st) == -1) {
rb_sys_fail(fptr->path);
}
return rb_time_new(st.st_mtime, 0);
@ -1624,7 +1624,7 @@ rb_file_ctime(obj)
struct stat st;
GetOpenFile(obj, fptr);
if (fstat(fileno(fptr->f), &st) == -1) {
if (fstat(fptr->fd, &st) == -1) {
rb_sys_fail(fptr->path);
}
return rb_time_new(st.st_ctime, 0);
@ -1695,7 +1695,7 @@ rb_file_chmod(obj, vmode)
GetOpenFile(obj, fptr);
#ifdef HAVE_FCHMOD
if (fchmod(fileno(fptr->f), mode) == -1)
if (fchmod(fptr->fd, mode) == -1)
rb_sys_fail(fptr->path);
#else
if (!fptr->path) return Qnil;
@ -1840,7 +1840,7 @@ rb_file_chown(obj, owner, group)
if (chown(fptr->path, o, g) == -1)
rb_sys_fail(fptr->path);
#else
if (fchown(fileno(fptr->f), o, g) == -1)
if (fchown(fptr->fd, o, g) == -1)
rb_sys_fail(fptr->path);
#endif
@ -2973,7 +2973,6 @@ rb_file_truncate(obj, len)
VALUE obj, len;
{
OpenFile *fptr;
FILE *f;
off_t pos;
rb_secure(2);
@ -2982,15 +2981,13 @@ rb_file_truncate(obj, len)
if (!(fptr->mode & FMODE_WRITABLE)) {
rb_raise(rb_eIOError, "not opened for writing");
}
f = GetWriteFile(fptr);
fflush(f);
fseeko(f, (off_t)0, SEEK_CUR);
rb_io_flush(obj);
#ifdef HAVE_TRUNCATE
if (ftruncate(fileno(f), pos) < 0)
if (ftruncate(fptr->fd, pos) < 0)
rb_sys_fail(fptr->path);
#else
# ifdef HAVE_CHSIZE
if (chsize(fileno(f), pos) < 0)
if (chsize(fptr->fd, pos) < 0)
rb_sys_fail(fptr->path);
# else
rb_notimplement();
@ -3084,10 +3081,10 @@ rb_file_flock(obj, operation)
GetOpenFile(obj, fptr);
if (fptr->mode & FMODE_WRITABLE) {
fflush(GetWriteFile(fptr));
rb_io_flush(obj);
}
retry:
if (flock(fileno(fptr->f), op) < 0) {
if (flock(fptr->fd, op) < 0) {
switch (errno) {
case EAGAIN:
case EACCES:

Просмотреть файл

@ -278,6 +278,7 @@ VALUE rb_io_gets _((VALUE));
VALUE rb_io_getc _((VALUE));
VALUE rb_io_ungetc _((VALUE, VALUE));
VALUE rb_io_close _((VALUE));
VALUE rb_io_flush _((VALUE));
VALUE rb_io_eof _((VALUE));
VALUE rb_io_binmode _((VALUE));
VALUE rb_io_addstr _((VALUE, VALUE));

931
io.c

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1349,8 +1349,8 @@ rb_fork(status, chfunc, charg)
#endif
#ifndef __VMS
fflush(stdout);
fflush(stderr);
rb_io_flush(rb_stdout);
rb_io_flush(rb_stderr);
#endif
#ifdef FD_CLOEXEC

Просмотреть файл

@ -21,14 +21,22 @@
#endif
typedef struct OpenFile {
int fd;
FILE *f; /* stdio ptr for read/write */
FILE *f2; /* additional ptr for rw pipes */
int mode; /* mode flags */
int pid; /* child's pid (for pipes) */
int lineno; /* number of lines read */
char *path; /* pathname for file */
void (*finalize) _((struct OpenFile*,int)); /* finalize proc */
long refcnt;
char *wbuf;
int wbuf_off;
int wbuf_len;
int wbuf_capa;
char *rbuf;
int rbuf_off;
int rbuf_len;
int rbuf_capa;
} OpenFile;
#define FMODE_READABLE 1
@ -38,8 +46,8 @@ typedef struct OpenFile {
#define FMODE_CREATE 128
#define FMODE_BINMODE 4
#define FMODE_SYNC 8
#define FMODE_WBUF 16
#define FMODE_RBUF 32
#define FMODE_LINEBUF 16
#define FMODE_UNSEEKABLE 32
#define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
@ -51,23 +59,29 @@ typedef struct OpenFile {
}\
fp = 0;\
fp = RFILE(obj)->fptr = ALLOC(OpenFile);\
fp->f = fp->f2 = NULL;\
fp->fd = -1;\
fp->f = NULL;\
fp->mode = 0;\
fp->pid = 0;\
fp->lineno = 0;\
fp->path = NULL;\
fp->finalize = 0;\
fp->refcnt = 1;\
fp->wbuf = NULL;\
fp->wbuf_off = 0;\
fp->wbuf_len = 0;\
fp->wbuf_capa = 0;\
fp->rbuf = NULL;\
fp->rbuf_off = 0;\
fp->rbuf_len = 0;\
fp->rbuf_capa = 0;\
} while (0)
#define GetReadFile(fptr) ((fptr)->f)
#define GetWriteFile(fptr) (((fptr)->f2) ? (fptr)->f2 : (fptr)->f)
#define GetWriteFile(fptr) ((fptr)->f)
FILE *rb_fopen _((const char*, const char*));
FILE *rb_fdopen _((int, const char*));
int rb_getc _((FILE*));
long rb_io_fread _((char *, long, FILE *));
long rb_io_fwrite _((const char *, long, FILE *));
int rb_io_mode_flags _((const char*));
int rb_io_modenum_flags _((int));
void rb_io_check_writable _((OpenFile*));
@ -82,6 +96,32 @@ int rb_io_wait_writable _((int));
VALUE rb_io_taint_check _((VALUE));
NORETURN(void rb_eof_error _((void)));
void rb_read_check _((FILE*));
int rb_read_pending _((FILE*));
void rb_io_read_check _((OpenFile*));
int rb_io_read_pending _((OpenFile*));
int rb_getc _((FILE*))
#ifdef __GNUC__
__attribute__ ((deprecated))
#endif
;
long rb_io_fread _((char *, long, FILE *))
#ifdef __GNUC__
__attribute__ ((deprecated))
#endif
;
long rb_io_fwrite _((const char *, long, FILE *))
#ifdef __GNUC__
__attribute__ ((deprecated))
#endif
;
void rb_read_check _((FILE*))
#ifdef __GNUC__
__attribute__ ((deprecated))
#endif
;
int rb_read_pending _((FILE*))
#ifdef __GNUC__
__attribute__ ((deprecated))
#endif
;
#endif

Просмотреть файл

@ -6,8 +6,8 @@ module TestEOF
assert_equal("", f.read(0))
assert_equal("", f.read(0))
assert_equal("", f.read)
assert_nil(f.read(0))
assert_nil(f.read(0))
assert_equal("", f.read(0))
assert_equal("", f.read(0))
}
open_file("") {|f|
assert_nil(f.read(1))
@ -43,8 +43,8 @@ module TestEOF
assert_equal("" , f.read(0))
assert_equal("" , f.read(0))
assert_equal("", f.read)
assert_nil(f.read(0))
assert_nil(f.read(0))
assert_equal("", f.read(0))
assert_equal("", f.read(0))
}
open_file("a") {|f|
assert_equal("a", f.read(1))
@ -69,7 +69,7 @@ module TestEOF
}
open_file("a") {|f|
assert_equal("a", f.read)
assert_nil(f.read(0))
assert_equal("", f.read(0))
}
open_file("a") {|f|
s = "x"
@ -96,7 +96,7 @@ module TestEOF
assert_equal(10, f.pos)
assert_equal("", f.read(0))
assert_equal("", f.read)
assert_nil(f.read(0))
assert_equal("", f.read(0))
assert_equal("", f.read)
}
end