diff options
author | William Wilgus <wilgus.william@gmail.com> | 2023-11-06 17:22:36 -0500 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2023-11-09 21:03:25 -0500 |
commit | 7ac4d34dd61547db97712dc608c9eb19c9a42e3c (patch) | |
tree | 1fb4bf7e2be5c7b281958654d8c6ccee31db615a /firmware/common | |
parent | 7f455af9053894241291f094865aee8808a1d3df (diff) | |
download | rockbox-7ac4d34dd61547db97712dc608c9eb19c9a42e3c.tar.gz rockbox-7ac4d34dd61547db97712dc608c9eb19c9a42e3c.zip |
Playlist slight optimizations for playlist_resume
Change-Id: I766ce032a9b6b36d750a9231ff9f5d5a0167e5a5
Diffstat (limited to 'firmware/common')
-rw-r--r-- | firmware/common/pathfuncs.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/firmware/common/pathfuncs.c b/firmware/common/pathfuncs.c index b942fdf022..6b70078eb1 100644 --- a/firmware/common/pathfuncs.c +++ b/firmware/common/pathfuncs.c | |||
@@ -448,6 +448,10 @@ void path_remove_dot_segments (char *dstpath, const char *path) | |||
448 | } | 448 | } |
449 | 449 | ||
450 | /* Appends one path to another, adding separators between components if needed. | 450 | /* Appends one path to another, adding separators between components if needed. |
451 | * basepath_max can be used to truncate the basepath if desired | ||
452 | * NOTE: basepath is truncated after copying to the buffer so there must be enough | ||
453 | * free space for the entirety of the basepath even if the resulting string would fit | ||
454 | * | ||
451 | * Return value and behavior is otherwise as strlcpy so that truncation may be | 455 | * Return value and behavior is otherwise as strlcpy so that truncation may be |
452 | * detected. | 456 | * detected. |
453 | * | 457 | * |
@@ -455,9 +459,11 @@ void path_remove_dot_segments (char *dstpath, const char *path) | |||
455 | * PA_SEP_HARD adds a separator even if the base path is empty | 459 | * PA_SEP_HARD adds a separator even if the base path is empty |
456 | * PA_SEP_SOFT adds a separator only if the base path is not empty | 460 | * PA_SEP_SOFT adds a separator only if the base path is not empty |
457 | */ | 461 | */ |
458 | size_t path_append(char *buf, const char *basepath, | 462 | size_t path_append_ex(char *buf, const char *basepath, size_t basepath_max, |
459 | const char *component, size_t bufsize) | 463 | const char *component, size_t bufsize) |
460 | { | 464 | { |
465 | size_t len; | ||
466 | bool separate = false; | ||
461 | const char *base = basepath && basepath[0] ? basepath : buf; | 467 | const char *base = basepath && basepath[0] ? basepath : buf; |
462 | if (!base) | 468 | if (!base) |
463 | return bufsize; /* won't work to get lengths from buf */ | 469 | return bufsize; /* won't work to get lengths from buf */ |
@@ -474,11 +480,20 @@ size_t path_append(char *buf, const char *basepath, | |||
474 | 480 | ||
475 | /* if basepath is not null or empty, buffer contents are replaced, | 481 | /* if basepath is not null or empty, buffer contents are replaced, |
476 | otherwise buf contains the base path */ | 482 | otherwise buf contains the base path */ |
477 | size_t len = base == buf ? strlen(buf) : strlcpy(buf, basepath, bufsize); | ||
478 | 483 | ||
479 | bool separate = false; | 484 | if (base == buf) |
485 | len = strlen(buf); | ||
486 | else | ||
487 | { | ||
488 | len = strlcpy(buf, basepath, bufsize); | ||
489 | if (basepath_max < len && basepath != component) | ||
490 | { | ||
491 | len = basepath_max; | ||
492 | buf[basepath_max] = '\0'; | ||
493 | } | ||
494 | } | ||
480 | 495 | ||
481 | if (!basepath || !component) | 496 | if (!basepath || !component || basepath_max == 0) |
482 | separate = !len || base[len-1] != PATH_SEPCH; | 497 | separate = !len || base[len-1] != PATH_SEPCH; |
483 | else if (component[0]) | 498 | else if (component[0]) |
484 | separate = len && base[len-1] != PATH_SEPCH; | 499 | separate = len && base[len-1] != PATH_SEPCH; |
@@ -496,6 +511,12 @@ size_t path_append(char *buf, const char *basepath, | |||
496 | return len + strlcpy(buf, component ?: "", bufsize); | 511 | return len + strlcpy(buf, component ?: "", bufsize); |
497 | } | 512 | } |
498 | 513 | ||
514 | |||
515 | size_t path_append(char *buf, const char *basepath, | ||
516 | const char *component, size_t bufsize) | ||
517 | { | ||
518 | return path_append_ex(buf, basepath, -1u, component, bufsize); | ||
519 | } | ||
499 | /* Returns the location and length of the next path component, consuming the | 520 | /* Returns the location and length of the next path component, consuming the |
500 | * input in the process. | 521 | * input in the process. |
501 | * | 522 | * |