Hi,
Jim Meyering wrote:
> +static inline bool
> +has_trailing_slash (char const *file, size_t len)
> +{
> + /* Don't count "/" as having a trailing slash. */
> + if (len <= 1)
> + return false;
> +
> + char last = file[len - 1];
> + return ISSLASH (last);
Since you use ISSLASH, you apparently care about non-POSIX systems. But
then shouldn't the first test be this?
if (len <= FILE_SYSTEM_PREFIX_LEN (file) + 1)
return false;
> + {
> + /* Fail now, unless SRC is a directory. */
> + struct stat sb;
> + if (lstat (src, &sb) != 0 || ! S_ISDIR (sb.st_mode))
> + return ret_val;
> + }
> +
> + /* Don't call rename again if there are no trailing slashes. */
> + d_len = strlen (dst);
> + if ( ! has_trailing_slash (dst, d_len))
> + return ret_val;
How about reversing the order of these two tests? Doing an strlen
is much cheaper than a system call. If you do the trailing slash first,
you save a system call in many cases.
Bruno