* rename-dest-slash.c (has_trailing_slash): Use
authorJim Meyering <jim@meyering.net>
Fri, 15 Sep 2006 18:48:09 +0000 (18:48 +0000)
committerJim Meyering <jim@meyering.net>
Fri, 15 Sep 2006 18:48:09 +0000 (18:48 +0000)
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
lib/rename-dest-slash.c

index 8a11306..fe690cd 100644 (file)
@@ -1,5 +1,11 @@
 2006-09-15  Jim Meyering  <jim@meyering.net>
 
+       * 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.
index 4e79de4..2c73f06 100644 (file)
@@ -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);