diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2020-12-17 01:13:40 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2020-12-17 01:39:46 -0800 |
commit | 3a75362f0375f66ebe204c87313899ed81010731 (patch) | |
tree | 1fafc81cb9f5f8924aebd26f4cea820da72b011f /lib/canonicalize.c | |
parent | 7ff4b70437dcd6f7b0cfe903164d1642528b61e1 (diff) | |
download | gnulib-3a75362f0375f66ebe204c87313899ed81010731.tar.gz |
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.
Diffstat (limited to 'lib/canonicalize.c')
-rw-r--r-- | lib/canonicalize.c | 32 |
1 files changed, 8 insertions, 24 deletions
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])) |