From: Leo C Date: Fri, 25 May 2018 09:04:53 +0000 (+0200) Subject: cleanup do_cd() do_pwd() X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/commitdiff_plain/779c97854d4231311e59c7587979a9d10deea458 cleanup do_cd() do_pwd() --- diff --git a/avr/cmd_fat.c b/avr/cmd_fat.c index a44de41..5acbb55 100644 --- a/avr/cmd_fat.c +++ b/avr/cmd_fat.c @@ -247,7 +247,7 @@ path_append(PATH_T *p, char *name) /* The "+ 1" accounts for the '/' between old path and name. */ if ((len + p->p_end - p->p_path + 1) > MAX_PATHLEN) { err(PSTR("append: '%s/%s': name too long"), p->p_path, name); - return(0); + return NULL; } /* @@ -259,7 +259,7 @@ path_append(PATH_T *p, char *name) *p->p_end = '\0'; } - (void)strncat(p->p_end, name, len); + strncat(p->p_end, name, len); p->p_end += len; *p->p_end = '\0'; @@ -330,28 +330,18 @@ static void swirl(void) command_ret_t do_pwd(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc UNUSED, char * const argv[] UNUSED) { FRESULT res; - char *buf; cmdname = argv[0]; + command_ret = CMD_RET_SUCCESS; - buf = (char *) malloc(BUFFER_SIZE); - if (buf == NULL) { - printf_P(PSTR("pwd: Out of Memory!\n")); - free(buf); - return CMD_RET_FAILURE; - } + res = f_getcwd(from.p_path, MAX_PATHLEN); /* Get current directory path */ - res = f_getcwd(buf, BUFFER_SIZE); /* Get current directory path */ + if (res == FR_OK) + puts(from.p_path); + else + err(PSTR("Error: %S"), rctostr(res)); - if (!res) { - puts(buf); - } - free(buf); - if (res) { - put_rc(res); - return CMD_RET_FAILURE; - } - return CMD_RET_SUCCESS; + return command_ret; } @@ -362,35 +352,28 @@ command_ret_t do_pwd(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc command_ret_t do_cd(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[]) { char *arg; - FRESULT res = 0; + FRESULT res = FR_OK; cmdname = argv[0]; + command_ret = CMD_RET_SUCCESS; if (argc < 2) { arg = getenv_str(PSTR(ENV_HOME)); if (arg == NULL) { - printf_P(PSTR("%s: \"%S\" is not set\n"), argv[0], PSTR(ENV_HOME)); - return CMD_RET_FAILURE; + err(PSTR("'%S' is not set"), PSTR(ENV_HOME)); + return command_ret; } } else arg = argv[1]; - if (arg[1] == ':') { - char drv[3]; - drv[2] = '\0'; - drv[1] = ':'; - drv[0] = arg[0]; - res = f_chdrive(drv); - } - if (!res) { + if (arg[1] == ':') + res = f_chdrive(arg); + if (res == FR_OK) res = f_chdir(arg); - } + if (res != FR_OK) + err(PSTR("'%s': %S"), arg, rctostr(res)); - if (res) { - put_rc(res); - return CMD_RET_FAILURE; - } - return CMD_RET_SUCCESS; + return command_ret; } #if 0 @@ -1223,7 +1206,7 @@ CMD_TBL_ITEM( "dev" ), CMD_TBL_ITEM( - pwd, 2, CTBL_RPT, do_pwd, + pwd, 1, CTBL_RPT, do_pwd, "Print name of current/working directory", "" ),