git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15227 27425a3e-05d8-49a3-a47f-9c15f0e5edd8

This commit is contained in:
Giovanni Di Sirio 2021-12-09 16:02:46 +00:00
parent e3c3e9916a
commit 6100c01bdc
2 changed files with 16 additions and 5 deletions

View File

@ -58,7 +58,7 @@ extern "C" {
msg_t vfs_parse_match_separator(const char **pathp); msg_t vfs_parse_match_separator(const char **pathp);
msg_t vfs_parse_match_end(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_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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -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; size_t n = 0U;
char lc = '\0'; char lc = '\0';
@ -144,7 +155,7 @@ msg_t vfs_parse_copy_with_separator(char *dst, const char *src) {
while ((*dst = *src) != '\0') { while ((*dst = *src) != '\0') {
if (n > VFS_CFG_PATHLEN_MAX) { if (n > VFS_CFG_PATHLEN_MAX) {
return VFS_RET_ENAMETOOLONG; return 0U;
} }
lc = *src++; lc = *src++;
@ -156,7 +167,7 @@ msg_t vfs_parse_copy_with_separator(char *dst, const char *src) {
if (lc != '/') { if (lc != '/') {
if (n > VFS_CFG_PATHLEN_MAX) { if (n > VFS_CFG_PATHLEN_MAX) {
return VFS_RET_ENAMETOOLONG; return 0U;
} }
*dst++ = '/'; *dst++ = '/';
@ -164,7 +175,7 @@ msg_t vfs_parse_copy_with_separator(char *dst, const char *src) {
n++; n++;
} }
return (msg_t)n; return n;
} }
/** @} */ /** @} */