From 758d301c31db5dff656a41e4f14369500d0c582e Mon Sep 17 00:00:00 2001 From: "Joseph C. Lehner" Date: Wed, 17 Feb 2016 12:19:43 +0100 Subject: [PATCH] Shorten pathname in status message --- nmrp.c | 2 +- nmrpd.h | 1 + tftp.c | 36 ++++++++++++++++++------------------ 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/nmrp.c b/nmrp.c index 81d9a9c..521c39e 100644 --- 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 cf5138d..28d3f0f 100644 --- 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 19866b4..282f6d2 100644 --- 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) { -- 2.25.1