* lib/openat.c (openat_permissive): Close fd regardless
of whether it’s STDERR_FILENO. This saves a bit of code space
and there’s no point to making this unlikely path faster.
Also change a couple of != 0 to < 0 for clarity
when -1 is the only option.
2024-11-20 Paul Eggert <eggert@cs.ucla.edu>
+ openat: omit unnecessary fd test
+ * lib/openat.c (openat_permissive): Close fd regardless
+ of whether it’s STDERR_FILENO. This saves a bit of code space
+ and there’s no point to making this unlikely path faster.
+ Also change a couple of != 0 to < 0 for clarity
+ when -1 is the only option.
+
openat: use C99 decls after stmts
* lib/openat.c (rpl_openat, openat_permissive):
Refactor to put decls closer to where they’re used.
int err = fchdir (fd);
int saved_errno = errno;
- if (! err)
+ if (0 <= err)
{
err = open (file, flags, mode);
saved_errno = errno;
- if (!save_failed && restore_cwd (&saved_cwd) != 0)
+ if (!save_failed && restore_cwd (&saved_cwd) < 0)
{
if (! cwd_errno)
{
/* Don't write a message to just-created fd 2. */
saved_errno = errno;
- if (err == STDERR_FILENO)
- close (err);
+ close (err);
openat_restore_fail (saved_errno);
}
*cwd_errno = errno;