aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/main.c b/main.c
index 02aa1968..30ef3d6f 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.276 2016/09/18 15:22:08 schwarze Exp $ */
+/* $Id: main.c,v 1.277 2016/09/18 15:47:45 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014-2016 Ingo Schwarze <schwarze@openbsd.org>
@@ -820,11 +820,17 @@ passthrough(const char *file, int fd, int synopsis_only)
const char *syscall;
char *line, *cp;
size_t linesz;
+ ssize_t len, written;
int print;
line = NULL;
linesz = 0;
+ if (fflush(stdout) == EOF) {
+ syscall = "fflush";
+ goto fail;
+ }
+
if ((stream = fdopen(fd, "r")) == NULL) {
close(fd);
syscall = "fdopen";
@@ -832,14 +838,16 @@ passthrough(const char *file, int fd, int synopsis_only)
}
print = 0;
- while (getline(&line, &linesz, stream) != -1) {
+ while ((len = getline(&line, &linesz, stream)) != -1) {
cp = line;
if (synopsis_only) {
if (print) {
if ( ! isspace((unsigned char)*cp))
goto done;
- while (isspace((unsigned char)*cp))
+ while (isspace((unsigned char)*cp)) {
cp++;
+ len--;
+ }
} else {
if (strcmp(cp, synb) == 0 ||
strcmp(cp, synr) == 0)
@@ -847,9 +855,11 @@ passthrough(const char *file, int fd, int synopsis_only)
continue;
}
}
- if (fputs(cp, stdout)) {
+ for (; len > 0; len -= written) {
+ if ((written = write(STDOUT_FILENO, cp, len)) != -1)
+ continue;
fclose(stream);
- syscall = "fputs";
+ syscall = "write";
goto fail;
}
}