From 04d39401bf641371ebd7d33949c6022bf67ee762 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 | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'read.c') diff --git a/read.c b/read.c index d1ffb578..52997bb0 100644 --- a/read.c +++ b/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.146 2015/11/07 14:22:29 schwarze Exp $ */ +/* $Id: read.c,v 1.147 2016/01/08 02:13:39 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2015 Ingo Schwarze @@ -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 v1.2.3