From owner-freebsd-hackers@freebsd.org Mon Jan 1 03:05:52 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 17DEAEB484C for ; Mon, 1 Jan 2018 03:05:52 +0000 (UTC) (envelope-from freebsd-rwg@pdx.rh.CN85.dnsmgr.net) Received: from pdx.rh.CN85.dnsmgr.net (br1.CN84in.dnsmgr.net [69.59.192.140]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EB9646F180 for ; Mon, 1 Jan 2018 03:05:51 +0000 (UTC) (envelope-from freebsd-rwg@pdx.rh.CN85.dnsmgr.net) Received: from pdx.rh.CN85.dnsmgr.net (localhost [127.0.0.1]) by pdx.rh.CN85.dnsmgr.net (8.13.3/8.13.3) with ESMTP id w0135mG4084159; Sun, 31 Dec 2017 19:05:48 -0800 (PST) (envelope-from freebsd-rwg@pdx.rh.CN85.dnsmgr.net) Received: (from freebsd-rwg@localhost) by pdx.rh.CN85.dnsmgr.net (8.13.3/8.13.3/Submit) id w0135luG084158; Sun, 31 Dec 2017 19:05:47 -0800 (PST) (envelope-from freebsd-rwg) From: "Rodney W. Grimes" Message-Id: <201801010305.w0135luG084158@pdx.rh.CN85.dnsmgr.net> Subject: Re: Is it considered to be ok to not check the return code of close(2) in base? In-Reply-To: <79FFA3EB-5994-4B7B-BE35-F1AB9D4AE3CD@dsl-only.net> To: Mark Millard Date: Sun, 31 Dec 2017 19:05:47 -0800 (PST) CC: phk@phk.freebsd.dk, FreeBSD Hackers X-Mailer: ELM [version 2.4ME+ PL121h (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Mailman-Approved-At: Mon, 01 Jan 2018 03:43:58 +0000 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Jan 2018 03:05:52 -0000 > Poul-Henning Kamp phk at phk.freebsd.dk wrote on > Sat Dec 30 20:35:35 UTC 2017 : > > > But if you just close a file, and you're 100% sure that will work, > > you should write it as: > > > > assert(close(fd) == 0); > > > > To tell the rest of us about your assumption and your confidence in it. > > Quoting the FreeBSD assert man page: > > QUOTE > The assert() macro may be removed at compile time by defining NDEBUG as a > macro (e.g., by using the cc(1) option -DNDEBUG). > ENDQUOTE > > This makes required-actions inside asserts dangerous, > at least without guarantees that NDEBUG will be > undefined. Trying to guarantee that NDEBUG will be > undefined would generally be a bad idea. > > So, > > assert(close(fd) == 0); > > is a bad coding practice in my view. Less bad than either of (void)close(fd)); close(fd); -- Rod Grimes rgrimes@freebsd.org