summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-07 06:34:26 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-07 06:34:26 +0000
commit02c45389c5e611e1521d5da4b4bca51ecf2c8d45 (patch)
tree51d6183bc73077b46fa4c42963b7b74e31d42e0c /io.c
parent9b0e00079e73268d6b40b1664ba001690c07df74 (diff)
* io.c (io_write): remove rb_str_locktmp(). [ruby-dev:25050]
* io.c (io_fwrite): takes VALUE string as an argument. [ruby-dev:25050] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7489 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/io.c b/io.c
index a3164363ec..f2bcf0b38a 100644
--- a/io.c
+++ b/io.c
@@ -385,15 +385,15 @@ rb_io_wait_writable(f)
}
/* writing functions */
-long
-io_fwrite(ptr, len, fptr)
- const char *ptr;
- long len;
+static long
+io_fwrite(str, fptr)
+ VALUE str;
OpenFile *fptr;
{
- long n, r;
+ long len, n, r, offset = 0;
FILE *f = GetWriteFile(fptr);
+ len = RSTRING(str)->len;
if ((n = len) <= 0) return n;
if (fptr->mode & FMODE_SYNC) {
io_fflush(f, fptr);
@@ -401,28 +401,30 @@ io_fwrite(ptr, len, fptr)
rb_io_check_closed(fptr);
}
retry:
- r = write(fileno(f), ptr, n);
+ r = write(fileno(f), RSTRING(str)->ptr+offset, n);
if (r == n) return len;
if (0 <= r) {
- ptr += r;
+ offset += r;
n -= r;
errno = EAGAIN;
}
if (rb_io_wait_writable(fileno(f))) {
rb_io_check_closed(fptr);
- goto retry;
+ if (offset < RSTRING(str)->len)
+ goto retry;
}
return -1L;
}
#if defined(__human68k__) || defined(__vms)
do {
- if (fputc(*ptr++, f) == EOF) {
+ if (fputc(RSTRING(str)->ptr+offset, f) == EOF) {
+ offset++;
if (ferror(f)) return -1L;
break;
}
} while (--n > 0);
#else
- while (errno = 0, ptr += (r = fwrite(ptr, 1, n, f)), (n -= r) > 0) {
+ while (errno = 0, offset += (r = fwrite(RSTRING(str)->ptr+offset, 1, n, f)), (n -= r) > 0) {
if (ferror(f)
#if defined __BORLANDC__
|| errno
@@ -434,7 +436,8 @@ io_fwrite(ptr, len, fptr)
if (rb_io_wait_writable(fileno(f))) {
rb_io_check_closed(fptr);
clearerr(f);
- continue;
+ if (offset < RSTRING(str)->len)
+ continue;
}
return -1L;
}
@@ -455,7 +458,7 @@ rb_io_fwrite(ptr, len, f)
of.f2 = NULL;
of.mode = FMODE_WRITABLE;
of.path = NULL;
- return io_fwrite(ptr, len, &of);
+ return io_fwrite(rb_str_new(ptr, len), &of);
}
/*
@@ -496,9 +499,7 @@ io_write(io, str)
GetOpenFile(io, fptr);
rb_io_check_writable(fptr);
- rb_str_locktmp(str);
- n = io_fwrite(RSTRING(str)->ptr, RSTRING(str)->len, fptr);
- rb_str_unlocktmp(str);
+ n = io_fwrite(str, fptr);
if (n == -1L) rb_sys_fail(fptr->path);
if (!(fptr->mode & FMODE_SYNC)) {
fptr->mode |= FMODE_WBUF;