Date: Sun, 31 Dec 2017 19:05:47 -0800 (PST) From: "Rodney W. Grimes" <freebsd-rwg@pdx.rh.CN85.dnsmgr.net> To: Mark Millard <markmi@dsl-only.net> Cc: phk@phk.freebsd.dk, FreeBSD Hackers <freebsd-hackers@freebsd.org> Subject: Re: Is it considered to be ok to not check the return code of close(2) in base? Message-ID: <201801010305.w0135luG084158@pdx.rh.CN85.dnsmgr.net> In-Reply-To: <79FFA3EB-5994-4B7B-BE35-F1AB9D4AE3CD@dsl-only.net>
next in thread | previous in thread | raw e-mail | index | archive | help
> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801010305.w0135luG084158>