From: Paul Eggert Date: Thu, 17 Dec 2020 09:13:40 +0000 (-0800) Subject: canonicalize: omit second readlink when not needed X-Git-Tag: v1.0~3357 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=3a75362f0375f66ebe204c87313899ed81010731;p=gnulib.git canonicalize: omit second readlink when not needed * lib/canonicalize.c (canonicalize_filename_mode_stk): Omit second readlink when (can_exist != CAN_MISSING && startlen != 0 && !logical). Simplify. --- diff --git a/ChangeLog b/ChangeLog index 58c7c16d7a..fccedabe31 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2020-12-17 Paul Eggert + canonicalize: omit second readlink when not needed + * lib/canonicalize.c (canonicalize_filename_mode_stk): + Omit second readlink when (can_exist != CAN_MISSING + && startlen != 0 && !logical). Simplify. + canonicalize: remove arbitrary 8192-byte limit Remove canonicalize.c’s arbitrary 8192-byte limit on platforms like GNU Hurd that do not define the PATH_MAX macro, and similarly diff --git a/lib/canonicalize.c b/lib/canonicalize.c index 04fae10a42..bcfd52be26 100644 --- a/lib/canonicalize.c +++ b/lib/canonicalize.c @@ -360,31 +360,15 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode, dest++; } } - else if (can_exist != CAN_MISSING - && (startlen == 0 - ? stat (rname, &st) < 0 - : !logical && readlink (rname, &discard, 1) < 0)) - { - switch (errno) - { - case EINVAL: - case EOVERFLOW: /* Possible with stat. */ - /* RNAME exists and is not a symbolic link. */ - break; - - case ENOENT: - /* RNAME does not exist. */ - if (can_exist == CAN_EXISTING + else if (! (can_exist == CAN_MISSING + || (startlen == 0 + ? stat (rname, &st) == 0 || errno == EOVERFLOW + : ((logical && 0 <= readlink (rname, &discard, 1)) + || errno == EINVAL)) || (can_exist == CAN_ALL_BUT_LAST - && end[strspn (end, SLASHES)])) - goto error; - break; - - default: - /* Some other problem with RNAME. */ - goto error; - } - } + && errno == ENOENT + && !end[strspn (end, SLASHES)]))) + goto error; } } if (dest > rname + prefix_len + 1 && ISSLASH (dest[-1]))