summaryrefslogtreecommitdiff
path: root/Src/input.c
diff options
context:
space:
mode:
authorAxel Beckert <abe@deuxchevaux.org>2022-04-11 00:17:48 +0200
committerAxel Beckert <abe@deuxchevaux.org>2022-04-11 00:17:48 +0200
commitb09f4483416c54c1782824633dfabaf2ec0265b6 (patch)
tree304bc82642862525ae680c7fbaa249663b10ad57 /Src/input.c
parent12eb3e5356f2fc3351eed58ef1cef1b8fb83b504 (diff)
parent6e55c920503071e917619b8cb1a188cd35d772db (diff)
downloadzsh-b09f4483416c54c1782824633dfabaf2ec0265b6.tar.gz
zsh-b09f4483416c54c1782824633dfabaf2ec0265b6.zip
New upstream version 5.8.1.2-test
Diffstat (limited to 'Src/input.c')
-rw-r--r--Src/input.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/Src/input.c b/Src/input.c
index 18228b37d..c59232681 100644
--- a/Src/input.c
+++ b/Src/input.c
@@ -223,13 +223,20 @@ shingetchar(void)
return STOUC(*shinbufptr++);
shinbufreset();
- do {
- errno = 0;
- nread = read(SHIN, shinbuffer, SHINBUFSIZE);
- } while (nread < 0 && errno == EINTR);
- if (nread <= 0)
- return -1;
- shinbufendptr = shinbuffer + nread;
+ for (;;) {
+ errno = 0;
+ nread = read(SHIN, shinbufendptr, 1);
+ if (nread > 0) {
+ /* Use line buffering (POSIX requirement) */
+ if (*shinbufendptr++ == '\n')
+ break;
+ if (shinbufendptr == shinbuffer + SHINBUFSIZE)
+ break;
+ } else if (nread == 0 || errno != EINTR)
+ break;
+ }
+ if (shinbufendptr == shinbuffer)
+ return -1;
return STOUC(*shinbufptr++);
}
@@ -595,9 +602,9 @@ stuff(char *fn)
zerr("can't open %s", fn);
return 1;
}
- fseek(in, 0, 2);
+ fseek(in, 0, SEEK_END);
len = ftell(in);
- fseek(in, 0, 0);
+ fseek(in, 0, SEEK_SET);
buf = (char *)zalloc(len + 1);
if (!(fread(buf, len, 1, in))) {
zerr("read error on %s", fn);