aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/main.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2016-01-08 02:13:39 +0000
committerIngo Schwarze <schwarze@openbsd.org>2016-01-08 02:13:39 +0000
commit04d39401bf641371ebd7d33949c6022bf67ee762 (patch)
treeb80ccae4c0c658aca51fc9efa7b61c1c8ffc0ee1 /main.c
parent24cca2c9750d89a1dd92e9e8aee7567012175880 (diff)
downloadmandoc-04d39401bf641371ebd7d33949c6022bf67ee762.tar.gz
mandoc-04d39401bf641371ebd7d33949c6022bf67ee762.tar.zst
mandoc-04d39401bf641371ebd7d33949c6022bf67ee762.zip
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.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/main.c b/main.c
index a311eb93..ccebdb4d 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.260 2015/12/15 17:38:45 schwarze Exp $ */
+/* $Id: main.c,v 1.261 2016/01/08 02:13:39 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -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;