diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2016-01-08 02:13:39 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2016-01-08 02:13:39 +0000 |
commit | d28fad77486ce53230d4b8b5731e7f06276c2e92 (patch) | |
tree | 978f0ff0a675d9c6abde1033cf8cdd0ce705de4f /main.c | |
parent | fde5c56f70c8c331d28ac290a122dbd46c25a2e5 (diff) | |
download | mandoc-d28fad77486ce53230d4b8b5731e7f06276c2e92.tar.gz |
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).
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -724,9 +724,11 @@ parse(struct curparse *curp, int fd, const char *file) /* Begin by parsing the file itself. */ assert(file); - assert(fd >= -1); + assert(fd > 0); rctmp = mparse_readfd(curp->mp, fd, file); + if (fd != STDIN_FILENO) + close(fd); if (rc < rctmp) rc = rctmp; |