* io.c (rb_io_fwrite): separated from io_write().
* marshal.c (w_byten): use rb_io_fwrite() to support non-blocking IO, and added error check. * rubyio.h: prototypes; rb_io_fwrite git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3191 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
96d28f71d9
commit
5b615c70eb
@ -1,3 +1,12 @@
|
|||||||
|
Fri Dec 20 18:29:04 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
|
* io.c (rb_io_fwrite): separated from io_write().
|
||||||
|
|
||||||
|
* marshal.c (w_byten): use rb_io_fwrite() to support non-blocking
|
||||||
|
IO, and added error check.
|
||||||
|
|
||||||
|
* rubyio.h: prototypes; rb_io_fwrite
|
||||||
|
|
||||||
Fri Dec 20 17:40:59 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Fri Dec 20 17:40:59 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* object.c (Init_Object): should not remove Class#allocate.
|
* object.c (Init_Object): should not remove Class#allocate.
|
||||||
|
56
io.c
56
io.c
@ -363,14 +363,43 @@ rb_io_wait_writable(f)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* writing functions */
|
/* writing functions */
|
||||||
|
long
|
||||||
|
rb_io_fwrite(ptr, len, f)
|
||||||
|
const char *ptr;
|
||||||
|
long len;
|
||||||
|
FILE *f;
|
||||||
|
{
|
||||||
|
long n, r;
|
||||||
|
|
||||||
|
if ((n = len) <= 0) return n;
|
||||||
|
#ifdef __human68k__
|
||||||
|
do {
|
||||||
|
if (fputc(*ptr++, f) == EOF) {
|
||||||
|
if (ferror(f)) return -1L;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (--n > 0);
|
||||||
|
#else
|
||||||
|
while (ptr += (r = fwrite(ptr, 1, n, f)), (n -= r) > 0) {
|
||||||
|
if (ferror(f)) {
|
||||||
|
if (rb_io_wait_writable(fileno(f))) {
|
||||||
|
clearerr(f);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return -1L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return len - n;
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
io_write(io, str)
|
io_write(io, str)
|
||||||
VALUE io, str;
|
VALUE io, str;
|
||||||
{
|
{
|
||||||
OpenFile *fptr;
|
OpenFile *fptr;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
long n, r;
|
long n;
|
||||||
register char *ptr;
|
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
if (TYPE(str) != T_STRING)
|
if (TYPE(str) != T_STRING)
|
||||||
@ -386,27 +415,8 @@ io_write(io, str)
|
|||||||
rb_io_check_writable(fptr);
|
rb_io_check_writable(fptr);
|
||||||
f = GetWriteFile(fptr);
|
f = GetWriteFile(fptr);
|
||||||
|
|
||||||
ptr = RSTRING(str)->ptr;
|
n = rb_io_fwrite(RSTRING(str)->ptr, RSTRING(str)->len, f);
|
||||||
n = RSTRING(str)->len;
|
if (n == -1L) rb_sys_fail(fptr->path);
|
||||||
#ifdef __human68k__
|
|
||||||
do {
|
|
||||||
if (fputc(*ptr++, f) == EOF) {
|
|
||||||
if (ferror(f)) rb_sys_fail(fptr->path);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (--n > 0);
|
|
||||||
#else
|
|
||||||
while (ptr += (r = fwrite(ptr, 1, n, f)), (n -= r) > 0) {
|
|
||||||
if (ferror(f)) {
|
|
||||||
if (rb_io_wait_writable(fileno(f))) {
|
|
||||||
clearerr(f);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
rb_sys_fail(fptr->path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
n = ptr - RSTRING(str)->ptr;
|
|
||||||
if (fptr->mode & FMODE_SYNC) {
|
if (fptr->mode & FMODE_SYNC) {
|
||||||
io_fflush(f, fptr);
|
io_fflush(f, fptr);
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,8 @@ w_byten(s, n, arg)
|
|||||||
struct dump_arg *arg;
|
struct dump_arg *arg;
|
||||||
{
|
{
|
||||||
if (arg->fp) {
|
if (arg->fp) {
|
||||||
fwrite(s, 1, n, arg->fp);
|
if (rb_io_fwrite(s, n, arg->fp) < 0)
|
||||||
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VALUE buf = arg->str;
|
VALUE buf = arg->str;
|
||||||
|
1
rubyio.h
1
rubyio.h
@ -59,6 +59,7 @@ FILE *rb_fopen _((const char*, const char*));
|
|||||||
FILE *rb_fdopen _((int, const char*));
|
FILE *rb_fdopen _((int, const char*));
|
||||||
int rb_getc _((FILE*));
|
int rb_getc _((FILE*));
|
||||||
long rb_io_fread _((char *, long, 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_mode_flags _((const char*));
|
||||||
void rb_io_check_writable _((OpenFile*));
|
void rb_io_check_writable _((OpenFile*));
|
||||||
void rb_io_check_readable _((OpenFile*));
|
void rb_io_check_readable _((OpenFile*));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user