From 8c2f7661b762fb378415e2df4b2634910acd3eb4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 13 Jul 2013 13:19:15 -0600 Subject: More Zmodem bugfixes and new files --- apps/system/zmodem/sz_main.c | 45 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to 'apps/system/zmodem/sz_main.c') diff --git a/apps/system/zmodem/sz_main.c b/apps/system/zmodem/sz_main.c index c6693f0b5..e20af9e97 100644 --- a/apps/system/zmodem/sz_main.c +++ b/apps/system/zmodem/sz_main.c @@ -42,8 +42,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -55,11 +57,13 @@ static void show_usage(FAR const char *progname, int errcode) { - fprintf(stderr, "USAGE: %s [OPTIONS] [ [ ...]]\n", progname); + fprintf(stderr, "USAGE: %s [OPTIONS] [ [ ...]]\n", + progname); fprintf(stderr, "\nWhere:\n"); fprintf(stderr, "\t is the local file name\n"); fprintf(stderr, "\nand OPTIONS include the following:\n"); - fprintf(stderr, "\t-d : Communication device to use. Default /dev/console\n"); + fprintf(stderr, "\t-d : Communication device to use. Default: %s\n", + CONFIG_SYSTEM_ZMODEM_DEVNAME); fprintf(stderr, "\t-r : Remote file name. Default \n"); fprintf(stderr, "\t-x : Transfer type\n"); fprintf(stderr, "\t\t0: Normal file (default)\n"); @@ -91,7 +95,7 @@ int sz_main(int argc, FAR char **argv) enum zm_option_e xfroption = XM_OPTION_REPLACE; ZMSHANDLE handle; FAR const char *rname = NULL; - FAR const char *devname = "/dev/console"; + FAR const char *devname = CONFIG_SYSTEM_ZMODEM_DEVNAME; FAR char *endptr; bool skip = false; long tmp; @@ -197,11 +201,44 @@ int sz_main(int argc, FAR char **argv) */ FAR const char *nextlname = argv[optind]; - FAR const char *nextrname = rname ? rname : nextlname; + FAR const char *nextrname; + FAR char *ralloc; + + /* Get the next remote file name */ + + nextrname = rname; + ralloc = NULL; + + if (!nextrname) + { + /* No remote filename, use the basename of the local filename. + * NOTE: that we have to duplicate the local filename to do this + * because basename() modifies the original string. + */ + + ralloc = strdup(nextlname); + if (!ralloc) + { + fprintf(stderr, "ERROR: Out-of-memory\n"); + goto errout_with_device; + } + + nextrname = basename(ralloc); + } /* Transfer the file */ ret = zms_send(handle, nextlname, nextrname, xfrtype, xfroption, skip); + + /* Free any allocations made for the remote file name */ + + if (ralloc) + { + free(ralloc); + } + + /* Check if the transfer was successful */ + if (ret < 0) { fprintf(stderr, "ERROR: Transfer of %s failed: %d\n", -- cgit v1.2.3