]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Centralise stripslashes() and make it OS-sensitive.
authorSimon Tatham <anakin@pobox.com>
Thu, 24 Sep 2015 16:47:10 +0000 (17:47 +0100)
committerSimon Tatham <anakin@pobox.com>
Thu, 24 Sep 2015 16:47:10 +0000 (17:47 +0100)
I noticed that Unix PSCP was unwantedly renaming downloaded files
which had a backslash in their names, because pscp.c's stripslashes()
treated \ as a path component separator, since it hadn't been modified
since PSCP ran on Windows only.

It also turns out that pscp.c, psftp.c and winsftp.c all had a
stripslashes(), and they didn't all have quite the same prototype. So
now there's one in winsftp.c and one in uxsftp.c, with appropriate
OS-dependent behaviour, and the ones in pscp.c and psftp.c are gone.

pscp.c
psftp.c
psftp.h
unix/uxsftp.c
windows/winsftp.c

diff --git a/pscp.c b/pscp.c
index 1d4967e760bbecdd2ae72b1674901d7073738383..0b37def18797b250383c890f14ff54237f27238a 100644 (file)
--- a/pscp.c
+++ b/pscp.c
@@ -605,35 +605,6 @@ static char *colon(char *str)
        return (NULL);
 }
 
-/*
- * Return a pointer to the portion of str that comes after the last
- * slash (or backslash or colon, if `local' is TRUE).
- *
- * This function has the annoying strstr() property of taking a const
- * char * and returning a char *. You should treat it as if it was a
- * pair of overloaded functions, one mapping mutable->mutable and the
- * other const->const :-(
- */
-static char *stripslashes(const char *str, int local)
-{
-    char *p;
-
-    if (local) {
-        p = strchr(str, ':');
-        if (p) str = p+1;
-    }
-
-    p = strrchr(str, '/');
-    if (p) str = p+1;
-
-    if (local) {
-       p = strrchr(str, '\\');
-       if (p) str = p+1;
-    }
-
-    return (char *)str;
-}
-
 /*
  * Determine whether a string is entirely composed of dots.
  */
diff --git a/psftp.c b/psftp.c
index 793626197d3837e6927f8076aaf7f70faa2b6646..93a96a4e152a63cc682042474a9a1c0c8d2573fc 100644 (file)
--- a/psftp.c
+++ b/psftp.c
@@ -169,35 +169,6 @@ char *canonify(const char *name)
     }
 }
 
-/*
- * Return a pointer to the portion of str that comes after the last
- * slash (or backslash or colon, if `local' is TRUE).
- *
- * This function has the annoying strstr() property of taking a const
- * char * and returning a char *. You should treat it as if it was a
- * pair of overloaded functions, one mapping mutable->mutable and the
- * other const->const :-(
- */
-static char *stripslashes(const char *str, int local)
-{
-    char *p;
-
-    if (local) {
-        p = strchr(str, ':');
-        if (p) str = p+1;
-    }
-
-    p = strrchr(str, '/');
-    if (p) str = p+1;
-
-    if (local) {
-       p = strrchr(str, '\\');
-       if (p) str = p+1;
-    }
-
-    return (char *)str;
-}
-
 /*
  * qsort comparison routine for fxp_name structures. Sorts by real
  * file name.
diff --git a/psftp.h b/psftp.h
index b3022d56068339d81f93a798b0f188a441165f7c..57a821ab19da7522c773a19792423662a4f132b6 100644 (file)
--- a/psftp.h
+++ b/psftp.h
@@ -177,4 +177,21 @@ int create_directory(const char *name);
  */
 char *dir_file_cat(const char *dir, const char *file);
 
+/*
+ * Return a pointer to the portion of str that comes after the last
+ * path component separator.
+ *
+ * If 'local' is false, path component separators are taken to just be
+ * '/', on the assumption that we're discussing the path syntax on the
+ * server. But if 'local' is true, the separators are whatever the
+ * local OS will treat that way - so that includes '\' and ':' on
+ * Windows.
+ *
+ * This function has the annoying strstr() property of taking a const
+ * char * and returning a char *. You should treat it as if it was a
+ * pair of overloaded functions, one mapping mutable->mutable and the
+ * other const->const :-(
+ */
+char *stripslashes(const char *str, int local);
+
 #endif /* PUTTY_PSFTP_H */
index 7039b69b5c2d1ace1663b0c00a529a03ee5a449e..3ac1d2c346470242955b96ff61825284e78126f0 100644 (file)
@@ -413,6 +413,20 @@ void finish_wildcard_matching(WildcardMatcher *dir) {
     sfree(dir);
 }
 
+char *stripslashes(const char *str, int local)
+{
+    char *p;
+
+    /*
+     * On Unix, we do the same thing regardless of the 'local'
+     * parameter.
+     */
+    p = strrchr(str, '/');
+    if (p) str = p+1;
+
+    return (char *)str;
+}
+
 int vet_filename(const char *name)
 {
     if (strchr(name, '/'))
index fa052eebffc5c5b41b201c1065c5317eafbe2c9c..0776cba94bdc19f544814d26dd7e985611fcae42 100644 (file)
@@ -340,14 +340,14 @@ struct WildcardMatcher {
     char *srcpath;
 };
 
-/*
- * Return a pointer to the portion of str that comes after the last
- * slash (or backslash or colon, if `local' is TRUE).
- */
-static char *stripslashes(char *str, int local)
+char *stripslashes(const char *str, int local)
 {
     char *p;
 
+    /*
+     * On Windows, \ / : are all path component separators.
+     */
+
     if (local) {
         p = strchr(str, ':');
         if (p) str = p+1;
@@ -361,7 +361,7 @@ static char *stripslashes(char *str, int local)
        if (p) str = p+1;
     }
 
-    return str;
+    return (char *)str;
 }
 
 WildcardMatcher *begin_wildcard_matching(const char *name)