Is it considered to be ok to not check the return code of close(2) in base?
Conrad Meyer
cem at freebsd.org
Mon Jan 8 18:13:24 UTC 2018
On Mon, Jan 8, 2018 at 10:05 AM, Andrew Duane <aduane at juniper.net> wrote:
> Of course, my OCD will kick in and say this would need to be something like:
>
> #ifdef DEBUG_CLOSE
> #define close(f) do {if (close(f) < 0) assert(errno != EBADF); } while (0)
> #endif
>
> Have to watch those macro replacements like "if (need_to_close) close(f);". And the close succeeding :-)
Of course, this has turned into nerd sniping. But I'll take my turn.
Better to use the GCC "statement expression" extension so that the
return value of "close()" can still be used by callers naive to the
macro.
#define close(f) ({ int __ret; __ret = (close)(f); if (__ret < 0)
assert(errno != EBADF); __ret; })
Best,
Conrad
More information about the freebsd-hackers
mailing list