Directory-related commands apparently working now, file commands to be reworked.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15253 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
a43c553ce0
commit
7480e1eb3d
|
@ -354,13 +354,13 @@ static void cmd_cd(BaseSequentialStream *chp, int argc, char *argv[]) {
|
|||
while (false);
|
||||
}
|
||||
|
||||
static void cmd_cwd(BaseSequentialStream *chp, int argc, char *argv[]) {
|
||||
static void cmd_pwd(BaseSequentialStream *chp, int argc, char *argv[]) {
|
||||
char *buf = NULL;
|
||||
|
||||
(void)argv;
|
||||
|
||||
if (argc != 0) {
|
||||
chprintf(chp, "Usage: cwd" SHELL_NEWLINE_STR);
|
||||
chprintf(chp, "Usage: pwd" SHELL_NEWLINE_STR);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -419,7 +419,7 @@ const ShellCommand shell_local_commands[] = {
|
|||
{"tree", cmd_tree},
|
||||
{"cat", cmd_cat},
|
||||
{"cd", cmd_cd},
|
||||
{"cwd", cmd_cwd},
|
||||
{"pwd", cmd_pwd},
|
||||
#endif
|
||||
#if SHELL_CMD_TEST_ENABLED == TRUE
|
||||
{"test", cmd_test},
|
||||
|
|
|
@ -195,8 +195,14 @@ static msg_t open_absolute_dir(vfs_overlay_driver_c *drvp,
|
|||
msg_t err;
|
||||
|
||||
do {
|
||||
/* Initial separator is expected, skipping.*/
|
||||
const char *scanpath = path + 1;
|
||||
const char *scanpath;
|
||||
|
||||
/* Making sure there is a final separator.*/
|
||||
err = vfs_path_add_separator(path, VFS_CFG_PATHLEN_MAX + 1);
|
||||
VFS_BREAK_ON_ERROR(err);
|
||||
|
||||
/* Initial separator is expected, skipping it.*/
|
||||
scanpath = path + 1;
|
||||
|
||||
/* If it is the root.*/
|
||||
if (*scanpath == '\0') {
|
||||
|
|
|
@ -57,6 +57,7 @@ extern "C" {
|
|||
#endif
|
||||
msg_t vfs_path_append(char *dst, const char *src, size_t size);
|
||||
msg_t vfs_path_prepend(char *dst, const char *src, size_t size);
|
||||
msg_t vfs_path_add_separator(char *dst, size_t size);
|
||||
msg_t vfs_path_normalize(char *dst, const char *src, size_t size);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -129,6 +129,37 @@ msg_t vfs_path_prepend(char *dst, const char *src, size_t size) {
|
|||
return (msg_t)sn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adds a separator to the end of a path if it is missing.
|
||||
*
|
||||
* @param[in] dst The destination path.
|
||||
* @param[in[ size Destination buffer size.
|
||||
* @return The operation status.
|
||||
* @retval VFS_RET_ERANGE If the path size exceeded the buffer size.
|
||||
*/
|
||||
msg_t vfs_path_add_separator(char *dst, size_t size) {
|
||||
size_t dn;
|
||||
|
||||
dn = strnlen(dst, size - 1U);
|
||||
|
||||
if (dn == 0U) {
|
||||
dst[0] = '/';
|
||||
dst[1] = '\0';
|
||||
}
|
||||
else {
|
||||
if (!vfs_parse_is_separator(dst[dn - 1])) {
|
||||
if (dn >= size - 1) {
|
||||
return VFS_RET_ERANGE;
|
||||
}
|
||||
|
||||
dst[dn] = '/';
|
||||
dst[dn + 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return dn + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Normalizes an absolute path.
|
||||
* @note The destination buffer can be the same of the source buffer.
|
||||
|
|
Loading…
Reference in New Issue