diff options
Diffstat (limited to 'firmware/common')
-rw-r--r-- | firmware/common/pathfuncs.c | 23 |
1 files changed, 4 insertions, 19 deletions
diff --git a/firmware/common/pathfuncs.c b/firmware/common/pathfuncs.c index e9218ea2c7..db3abe6940 100644 --- a/firmware/common/pathfuncs.c +++ b/firmware/common/pathfuncs.c | |||
@@ -339,23 +339,6 @@ size_t path_dirname(const char *name, const char **nameptr) | |||
339 | return q - name; | 339 | return q - name; |
340 | } | 340 | } |
341 | 341 | ||
342 | /* Removes leading separators from a path | ||
343 | * "" *nameptr->NUL, count=0: "" | ||
344 | * "/" *nameptr->/, count=1: "/" | ||
345 | * "//" *nameptr->2nd /, count=2: "/" | ||
346 | * "a/" *nameptr->a/, count=0: "a/" | ||
347 | * "//b//" *nameptr->2nd /, count=2: "/b//" | ||
348 | * "/c/" *nameptr->/, count=1: "/c/" | ||
349 | */ | ||
350 | size_t path_strip_leading_separators(const char *name, const char **nameptr) | ||
351 | { | ||
352 | const char *p = name; | ||
353 | *nameptr = p; | ||
354 | while (*(p) == PATH_SEPCH && *(++p) == PATH_SEPCH) | ||
355 | *nameptr = p; | ||
356 | return p - name; | ||
357 | } | ||
358 | |||
359 | /* Removes trailing separators from a path | 342 | /* Removes trailing separators from a path |
360 | * "" *nameptr->NUL, len=0: "" | 343 | * "" *nameptr->NUL, len=0: "" |
361 | * "/" *nameptr->/, len=1: "/" | 344 | * "/" *nameptr->/, len=1: "/" |
@@ -503,9 +486,11 @@ size_t path_append_ex(char *buf, const char *basepath, size_t basepath_max, | |||
503 | len = strlen(buf); | 486 | len = strlen(buf); |
504 | else if (basepath) | 487 | else if (basepath) |
505 | { | 488 | { |
506 | path_strip_leading_separators(basepath, &basepath); | 489 | /* strip extra leading separators */ |
490 | while (*basepath == PATH_SEPCH && *(basepath + 1) == PATH_SEPCH) | ||
491 | basepath++; | ||
507 | len = strlcpy(buf, basepath, bufsize); | 492 | len = strlcpy(buf, basepath, bufsize); |
508 | if (basepath_max < len) | 493 | if (basepath_max < len) /*if needed truncate basepath to basepath_max */ |
509 | { | 494 | { |
510 | len = basepath_max; | 495 | len = basepath_max; |
511 | buf[basepath_max] = '\0'; | 496 | buf[basepath_max] = '\0'; |