---
ed.c | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/ed.c b/ed.c
index 686d2aa..c560d1a 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -169,20 +169,20 @@ makeline(char *s, int *off)
}
lp = zero + lastidx;
- while ((c = *s) && *s != '\n')
- ++s;
- if (c == '\n')
- ++s;
- len = s - begin;
+ if (!s) {
+ lp->seek = -1;
+ len = 0;
+ } else {
+ while ((c = *s++) != '\n')
+ /* nothing */;
+ len = s - begin;
+ if ((lp->seek = lseek(scratch, 0, SEEK_END)) < 0 ||
+ write(scratch, begin, len) < 0) {
+ error("input/output error");
+ }
+ }
if (off)
*off = len;
-
- if (len > 0)
- if ((lp->seek = lseek(scratch, 0, SEEK_END)) < 0 ||
- write(scratch, begin, len) < 0) {
- error("input/output error");
- }
-
++lastidx;
return lp - zero;
}
_AT_@ -210,8 +210,11 @@ gettxt(int line)
char *p;
lp = zero + getindex(line);
- off = lp->seek;
sizetxt = 0;
+ off = lp->seek;
+
+ if (off == (off_t) -1)
+ return text = addchar('\0', text, &memtxt, &sizetxt);
repeat:
if (!csize || off < lasto || off - lasto >= csize) {
_AT_@ -341,7 +344,7 @@ setscratch()
error("scratch filename too long");
if ((scratch = mkstemp(tmpname)) < 0)
error("failed to create scratch file");
- if ((k = makeline("", NULL)))
+ if ((k = makeline(NULL, NULL)))
error("input/output error in scratch file");
relink(k, k, k, k);
clearundo();
--
2.1.4
Received on Wed Jan 06 2016 - 22:04:29 CET
This archive was generated by hypermail 2.3.0 : Wed Jan 06 2016 - 22:12:18 CET