/* 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;
}
/*
*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';
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;
}
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
"dev"
),
CMD_TBL_ITEM(
- pwd, 2, CTBL_RPT, do_pwd,
+ pwd, 1, CTBL_RPT, do_pwd,
"Print name of current/working directory",
""
),