From d28fad77486ce53230d4b8b5731e7f06276c2e92 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Fri, 8 Jan 2016 02:13:39 +0000 Subject: It was very surprising that a function called mparse_readfd() closed the file descriptor passed to it after completing its work, in particular considering the fact that it required its callers to call open(2) or mparse_open() beforehand. Change mparse_readfd() to not call close(2) and change the callers to call close(2) afterwards, more or less bringing open and close to the same level of the code and making review easier. Note that man.cgi(8) already did that, even though it was wrong in the past. Small restructuring suggested by Christos Zoulas (NetBSD). --- read.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'read.c') diff --git a/read.c b/read.c index 90642134..699b2c65 100644 --- a/read.c +++ b/read.c @@ -542,6 +542,7 @@ rerun: if (mparse_open(curp, &fd, ln.buf + of) == MANDOCLEVEL_OK) { mparse_readfd(curp, fd, ln.buf + of); + close(fd); curp->file = save_file; } else { curp->file = save_file; @@ -773,10 +774,6 @@ mparse_readfd(struct mparse *curp, int fd, const char *file) #endif free(blk.buf); } - - if (fd != STDIN_FILENO && close(fd) == -1) - perror(file); - return curp->file_status; } -- cgit