Shorten pathname in status message

This commit is contained in:
Joseph C. Lehner 2016-02-17 12:19:43 +01:00
parent dc961b598a
commit 758d301c31
3 changed files with 20 additions and 19 deletions

2
nmrp.c
View file

@ -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);

View file

@ -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);

36
tftp.c
View file

@ -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)
{