=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/main.c,v retrieving revision 1.163 retrieving revision 1.164 diff -c -r1.163 -r1.164 *** src/usr.bin/mandoc/main.c 2015/11/06 17:23:50 1.163 --- src/usr.bin/mandoc/main.c 2015/11/07 17:58:52 1.164 *************** *** 1,4 **** ! /* $OpenBSD: main.c,v 1.163 2015/11/06 17:23:50 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze --- 1,4 ---- ! /* $OpenBSD: main.c,v 1.164 2015/11/07 17:58:52 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze *************** *** 729,740 **** FILE *stream; const char *syscall; ! char *line; ! size_t len, off; ! ssize_t nw; int print; ! fflush(stdout); if ((stream = fdopen(fd, "r")) == NULL) { close(fd); --- 729,740 ---- FILE *stream; const char *syscall; ! char *line, *cp; ! size_t linesz; int print; ! line = NULL; ! linesz = 0; if ((stream = fdopen(fd, "r")) == NULL) { close(fd); *************** *** 743,787 **** } print = 0; ! while ((line = fgetln(stream, &len)) != NULL) { if (synopsis_only) { if (print) { ! if ( ! isspace((unsigned char)*line)) goto done; ! while (len && ! isspace((unsigned char)*line)) { ! line++; ! len--; ! } } else { ! if ((len == sizeof(synb) && ! ! strncmp(line, synb, len - 1)) || ! (len == sizeof(synr) && ! ! strncmp(line, synr, len - 1))) print = 1; continue; } } ! for (off = 0; off < len; off += nw) ! if ((nw = write(STDOUT_FILENO, line + off, ! len - off)) == -1 || nw == 0) { ! fclose(stream); ! syscall = "write"; ! goto fail; ! } } if (ferror(stream)) { fclose(stream); ! syscall = "fgetln"; goto fail; } done: fclose(stream); return; fail: warn("%s: SYSERR: %s", file, syscall); if (rc < MANDOCLEVEL_SYSERR) rc = MANDOCLEVEL_SYSERR; --- 743,783 ---- } print = 0; ! while (getline(&line, &linesz, stream) != -1) { ! cp = line; if (synopsis_only) { if (print) { ! if ( ! isspace((unsigned char)*cp)) goto done; ! while (isspace((unsigned char)*cp)) ! cp++; } else { ! if (strcmp(cp, synb) == 0 || ! strcmp(cp, synr) == 0) print = 1; continue; } } ! if (fputs(cp, stdout)) { ! fclose(stream); ! syscall = "fputs"; ! goto fail; ! } } if (ferror(stream)) { fclose(stream); ! syscall = "getline"; goto fail; } done: + free(line); fclose(stream); return; fail: + free(line); warn("%s: SYSERR: %s", file, syscall); if (rc < MANDOCLEVEL_SYSERR) rc = MANDOCLEVEL_SYSERR;