diff --git a/os/vfs/include/vfsparser.h b/os/vfs/include/vfsparser.h index 0ed2b8235..023748bb0 100644 --- a/os/vfs/include/vfsparser.h +++ b/os/vfs/include/vfsparser.h @@ -58,7 +58,7 @@ extern "C" { msg_t vfs_parse_match_separator(const char **pathp); msg_t vfs_parse_match_end(const char **pathp); msg_t vfs_parse_get_fname(const char **pathp, char *fname); - msg_t vfs_parse_copy_with_separator(char *dst, const char *src); + size_t vfs_parse_copy_with_separator(char *dst, const char *src); #ifdef __cplusplus } #endif diff --git a/os/vfs/src/vfsparser.c b/os/vfs/src/vfsparser.c index 3d93517d2..c83c58253 100644 --- a/os/vfs/src/vfsparser.c +++ b/os/vfs/src/vfsparser.c @@ -136,7 +136,18 @@ msg_t vfs_parse_get_fname(const char **pathp, char *fname) { } } -msg_t vfs_parse_copy_with_separator(char *dst, const char *src) { +/** + * @brief Copies a path into a destination buffer. + * @details Up to @p VFS_CFG_PATHLEN_MAX characters are copied. A path + * separator is added to the end of the path if not present. + * + * @param[out] dst The destination buffer. + * @param[in] src The source path. + * @return The copied path size not including the final + * zero. + * @retval 0 If the path size exceeded @p VFS_CFG_PATHLEN_MAX. + */ +size_t vfs_parse_copy_with_separator(char *dst, const char *src) { size_t n = 0U; char lc = '\0'; @@ -144,7 +155,7 @@ msg_t vfs_parse_copy_with_separator(char *dst, const char *src) { while ((*dst = *src) != '\0') { if (n > VFS_CFG_PATHLEN_MAX) { - return VFS_RET_ENAMETOOLONG; + return 0U; } lc = *src++; @@ -156,7 +167,7 @@ msg_t vfs_parse_copy_with_separator(char *dst, const char *src) { if (lc != '/') { if (n > VFS_CFG_PATHLEN_MAX) { - return VFS_RET_ENAMETOOLONG; + return 0U; } *dst++ = '/'; @@ -164,7 +175,7 @@ msg_t vfs_parse_copy_with_separator(char *dst, const char *src) { n++; } - return (msg_t)n; + return n; } /** @} */