summaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-11-11 13:48:51 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-11-11 13:48:51 +0000
commit5ceef7994325675ca20f6ca66e4c010277703294 (patch)
tree82a03de0a876df1a00e1865c9d338861d1ae5b26 /io.c
parent2ec047bab09fbbda7ce523e972f444d85c56ad70 (diff)
downloadruby-5ceef7994325675ca20f6ca66e4c010277703294.tar.gz
ruby-5ceef7994325675ca20f6ca66e4c010277703294.tar.xz
ruby-5ceef7994325675ca20f6ca66e4c010277703294.zip
* io.c (appendline): file may not end with newline. a bug if
READ_DATA_PENDING_PTR is defined. [ruby-talk:84925] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@4937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/io.c b/io.c
index 75c0227a1..7d6637e1f 100644
--- a/io.c
+++ b/io.c
@@ -873,7 +873,7 @@ appendline(fptr, delim, strp)
#ifndef READ_DATA_PENDING_PTR
char buf[8192];
char *bp = buf, *bpe = buf + sizeof buf - 3;
- int cnt;
+ int update = Qfalse;
#endif
do {
@@ -925,11 +925,13 @@ appendline(fptr, delim, strp)
rb_sys_fail(fptr->path);
continue;
}
+#ifdef READ_DATA_PENDING_PTR
return c;
+#endif
}
#ifndef READ_DATA_PENDING_PTR
- if ((*bp++ = c) == delim || bp == bpe) {
- cnt = bp - buf;
+ if (c == EOF || (*bp++ = c) == delim || bp == bpe) {
+ int cnt = bp - buf;
if (cnt > 0) {
if (!NIL_P(str))
@@ -937,8 +939,14 @@ appendline(fptr, delim, strp)
else
*strp = str = rb_str_new(buf, cnt);
}
+ if (c == EOF) {
+ if (update)
+ return (int)RSTRING(str)->ptr[RSTRING(str)->len-1];
+ return c;
+ }
bp = buf;
}
+ update = Qtrue;
#endif
} while (c != delim);