From: Eric Blake Date: Mon, 21 Sep 2009 23:19:10 +0000 (-0600) Subject: open, openat: minor optimization X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f34e1ad57eebc72dbaa7aef0181c1a7d0afff1bf;p=pspp open, openat: minor optimization * lib/open.c (open): If open succeeded, len is non-zero. * lib/openat.c (rpl_openat): Likewise. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index 33dc8aef1e..4abbe70348 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2009-09-22 Eric Blake + open, openat: minor optimization + * lib/open.c (open): If open succeeded, len is non-zero. + * lib/openat.c (rpl_openat): Likewise. + link-follow: ensure correct result * m4/fcntl_h.m4 (gl_FCNTL_H): Clean up temporary file. * m4/link-follow.m4 (gl_FUNC_LINK_FOLLOWS_SYMLINK): Likewise, and diff --git a/lib/open.c b/lib/open.c index 08ecaff44b..7cc25bd07c 100644 --- a/lib/open.c +++ b/lib/open.c @@ -141,8 +141,9 @@ open (const char *filename, int flags, ...) with ENOTDIR. */ if (fd >= 0) { + /* We know len is positive, since open did not fail with ENOENT. */ size_t len = strlen (filename); - if (len > 0 && filename[len - 1] == '/') + if (filename[len - 1] == '/') { struct stat statbuf; diff --git a/lib/openat.c b/lib/openat.c index 7e46a2672b..079039fee3 100644 --- a/lib/openat.c +++ b/lib/openat.c @@ -103,8 +103,9 @@ rpl_openat (int dfd, char const *filename, int flags, ...) with ENOTDIR. */ if (fd >= 0) { + /* We know len is positive, since open did not fail with ENOENT. */ size_t len = strlen (filename); - if (len > 0 && filename[len - 1] == '/') + if (filename[len - 1] == '/') { struct stat statbuf;