From 23ba046d0ad85ab6e288a70902c0e0589169ff65 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Fri, 15 Sep 2006 18:48:09 +0000 Subject: [PATCH] * rename-dest-slash.c (has_trailing_slash): Use FILE_SYSTEM_PREFIX_LEN, for non-POSIX systems. (rpl_rename_dest_slash): Perform the cheaper trailing slash test before testing whether SRC is a directory. Suggestions from Bruno Haible. --- lib/ChangeLog | 6 ++++++ lib/rename-dest-slash.c | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 8a11306056..fe690cd735 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,5 +1,11 @@ 2006-09-15 Jim Meyering + * rename-dest-slash.c (has_trailing_slash): Use + FILE_SYSTEM_PREFIX_LEN, for non-POSIX systems. + (rpl_rename_dest_slash): Perform the cheaper trailing slash + test before testing whether SRC is a directory. + Suggestions from Bruno Haible. + Avoid a warning about an unused variable. * regex_internal.c (re_dfa_add_node): Move declaration of "type" into the #ifdef block where it's used. diff --git a/lib/rename-dest-slash.c b/lib/rename-dest-slash.c index 4e79de41a6..2c73f06d23 100644 --- a/lib/rename-dest-slash.c +++ b/lib/rename-dest-slash.c @@ -42,7 +42,7 @@ static inline bool has_trailing_slash (char const *file, size_t len) { /* Don't count "/" as having a trailing slash. */ - if (len <= 1) + if (len <= FILE_SYSTEM_PREFIX_LEN (file) + 1) return false; char last = file[len - 1]; @@ -64,6 +64,11 @@ rpl_rename_dest_slash (char const *src, char const *dst) if (ret_val == 0 || errno != ENOENT) 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; + { /* Fail now, unless SRC is a directory. */ struct stat sb; @@ -71,11 +76,6 @@ rpl_rename_dest_slash (char const *src, char const *dst) 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; - { char *dst_temp; dst_temp = xmemdup (dst, d_len + 1); -- 2.30.2