From owner-freebsd-hackers@freebsd.org Sun Dec 31 22:11:46 2017 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 68892EA9E9E for ; Sun, 31 Dec 2017 22:11:46 +0000 (UTC) (envelope-from markmi@dsl-only.net) Received: from asp.reflexion.net (outbound-mail-210-137.reflexion.net [208.70.210.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id F2EF965826 for ; Sun, 31 Dec 2017 22:11:45 +0000 (UTC) (envelope-from markmi@dsl-only.net) Received: (qmail 22259 invoked from network); 31 Dec 2017 22:11:38 -0000 Received: from unknown (HELO mail-cs-01.app.dca.reflexion.local) (10.81.19.1) by 0 (rfx-qmail) with SMTP; 31 Dec 2017 22:11:38 -0000 Received: by mail-cs-01.app.dca.reflexion.local (Reflexion email security v8.40.3) with SMTP; Sun, 31 Dec 2017 17:11:38 -0500 (EST) Received: (qmail 2613 invoked from network); 31 Dec 2017 22:11:38 -0000 Received: from unknown (HELO iron2.pdx.net) (69.64.224.71) by 0 (rfx-qmail) with (AES256-SHA encrypted) SMTP; 31 Dec 2017 22:11:38 -0000 Received: from [192.168.1.25] (c-76-115-7-162.hsd1.or.comcast.net [76.115.7.162]) by iron2.pdx.net (Postfix) with ESMTPSA id 66346EC8171; Sun, 31 Dec 2017 14:11:37 -0800 (PST) From: Mark Millard Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: Is it considered to be ok to not check the return code of close(2) in base? Message-Id: <79FFA3EB-5994-4B7B-BE35-F1AB9D4AE3CD@dsl-only.net> Date: Sun, 31 Dec 2017 14:11:36 -0800 To: phk@phk.freebsd.dk, FreeBSD Hackers X-Mailer: Apple Mail (2.3273) 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: Sun, 31 Dec 2017 22:11:46 -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: >=20 > assert(close(fd) =3D=3D 0); >=20 > 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) =3D=3D 0); is a bad coding practice in my view. =3D=3D=3D Mark Millard markmi at dsl-only.net