From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id f5db4ebd for ; Sun, 18 Sep 2016 10:48:15 -0500 (EST) Date: Sun, 18 Sep 2016 10:48:15 -0500 (EST) Message-Id: <4505015829647960485.enqueue@fantadrom.bsd.lv> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: schwarze@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: We cannot use fputs(3) in passthrough() because the stdout X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- We cannot use fputs(3) in passthrough() because the stdout stream might be in stdio wide orientation due to prior formatting of an unformatted manual in man -aTutf8 mode. So for now, use fflush(3) followed by unbuffered write(2) instead. Fixes output corruption on glibc discovered on Linux while testing a diff to fix a loosely related bug reported by . I detest the concept of stdio stream orientation. One day, i will rewrite term_ascii.c to always use narrow streams, even in UTF-8 output mode. But that's too much work for today. Modified Files: -------------- mdocml: main.c Revision Data ------------- Index: main.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/main.c,v retrieving revision 1.276 retrieving revision 1.277 diff -Lmain.c -Lmain.c -u -p -r1.276 -r1.277 --- main.c +++ main.c @@ -820,11 +820,17 @@ passthrough(const char *file, int fd, in 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, in } 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, in 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; } } -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv