Shorten pathname in status message
authorJoseph C. Lehner <joseph.c.lehner@gmail.com>
Wed, 17 Feb 2016 11:19:43 +0000 (12:19 +0100)
committerJoseph C. Lehner <joseph.c.lehner@gmail.com>
Wed, 17 Feb 2016 11:19:43 +0000 (12:19 +0100)
nmrp.c
nmrpd.h
tftp.c

diff --git a/nmrp.c b/nmrp.c
index 81d9a9c6a4dd40d3b11cd011f4903efd9b71eb63..521c39e179190e5412d7f3603ef14d61016cd04b 100644 (file)
--- a/nmrp.c
+++ b/nmrp.c
@@ -571,7 +571,7 @@ int nmrp_do(struct nmrpd_args *args)
                                        if (!strcmp(args->file_local, "-")) {
                                                printf("Uploading from stdin ... ");
                                        } else {
-                                               printf("Uploading %s ... ", args->file_local);
+                                               printf("Uploading %s ... ", leafname(args->file_local));
                                        }
                                        fflush(stdout);
                                        status = tftp_put(args);
diff --git a/nmrpd.h b/nmrpd.h
index cf5138df8ebdf6e08ece73ffaf36212be7412261..28d3f0fd825a145cad0ca2a41f41292a306cc615 100644 (file)
--- a/nmrpd.h
+++ b/nmrpd.h
@@ -75,6 +75,7 @@ struct nmrpd_args {
        int force_root;
 };
 
+const char *leafname(const char *path);
 int tftp_put(struct nmrpd_args *args);
 bool tftp_is_valid_filename(const char *filename);
 
diff --git a/tftp.c b/tftp.c
index 19866b4afacb22386d5dad98e1d4751655c0c74d..282f6d2d07342834e0cc3d0603ada46a322e61ec 100644 (file)
--- a/tftp.c
+++ b/tftp.c
@@ -40,24 +40,6 @@ enum tftp_opcode {
        ERR  = 5
 };
 
-static const char *leafname(const char *path)
-{
-       const char *slash, *bslash;
-
-       slash = strrchr(path, '/');
-       bslash = strrchr(path, '\\');
-
-       if (slash && bslash) {
-               path = 1 + (slash > bslash ? slash : bslash);
-       } else if (slash) {
-               path = 1 + slash;
-       } else if (bslash) {
-               path = 1 + bslash;
-       }
-
-       return path;
-}
-
 static bool is_netascii(const char *str)
 {
        uint8_t *p = (uint8_t*)str;
@@ -211,6 +193,24 @@ static ssize_t tftp_sendto(int sock, char *pkt, size_t len,
        return sent;
 }
 
+const char *leafname(const char *path)
+{
+       const char *slash, *bslash;
+
+       slash = strrchr(path, '/');
+       bslash = strrchr(path, '\\');
+
+       if (slash && bslash) {
+               path = 1 + (slash > bslash ? slash : bslash);
+       } else if (slash) {
+               path = 1 + slash;
+       } else if (bslash) {
+               path = 1 + bslash;
+       }
+
+       return path;
+}
+
 #ifdef NMRPFLASH_WINDOWS
 void sock_perror(const char *msg)
 {