* 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. --- ChangeLog | 7 +++++++ lib/openat.c | 7 +++---- 2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog index 11d0a0f679..567370aa3e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2024-11-20 Paul Eggert <egg...@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. diff --git a/lib/openat.c b/lib/openat.c index 9c8180c013..0e8e819408 100644 --- a/lib/openat.c +++ b/lib/openat.c @@ -271,18 +271,17 @@ openat_permissive (int fd, char const *file, int flags, mode_t mode, 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; -- 2.47.0