Pádraig Brady <[email protected]> writes:
> + int saved_errno = errno;
> + free (dir);
> + errno = saved_errno;
> + return ok;
> +}
We use the 'free-posix' module from Gnulib, which ensures that free does
not clobber errno. So, I don't think you should need to save it here,
although doing so is harmless.
> +
> +/* Dereference the basename of FNAME, but preserve any symlink spelling in
> + parent directories. Relative link values are resolved against the
> + previous link's parent directory, then cleaned without dereferencing
> + symlinks in parent directories. */
> +static char *
> +realpath_resolve_basename (char const *fname, int can_mode)
> +{
> + can_mode |= CAN_NOLINKS;
> + char *can_fname = canonicalize_filename_mode (fname, can_mode);
> +
> + for (idx_t num_links = 0; can_fname; num_links++)
> + {
> + if (! parent_directory_exists (can_fname, can_mode))
> + {
> + int saved_errno = errno;
> + free (can_fname);
> + errno = saved_errno;
> + return NULL;
> + }
Likewise.
> +
> + char *linkname = areadlink_with_size (can_fname, 63);
> + if (!linkname)
> + {
> + if (errno == EINVAL
> + || (can_mode & CAN_MODE_MASK) != CAN_EXISTING)
> + return can_fname;
> +
> + int saved_errno = errno;
> + free (can_fname);
> + errno = saved_errno;
Likewise.
> + free (linkname);
> + free (can_fname);
> + can_fname = canonicalize_filename_mode (next_name, can_mode);
> + int saved_errno = errno;
> + free (next_name);
> + errno = saved_errno;
Likewise.
Collin