- while ((nr = read(fd, buf, BUFSIZ)) != -1 && nr != 0)
- for (off = 0; off < nr; off += nw)
- if ((nw = write(STDOUT_FILENO, buf + off,
- (size_t)(nr - off))) == -1 || nw == 0) {
+ if ((stream = fdopen(fd, "r")) == NULL) {
+ close(fd);
+ syscall = "fdopen";
+ goto fail;
+ }
+
+ 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);