A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd

pathfuncs.c add path_strip_leading_separators()

added to path_append as well

Change-Id: Ieb6ec4f4c475ca5e60c8246c7f044bcc7651f6bf

authored by

William Wilgus and committed by
William Wilgus
fe00906a 777098fc

+24 -8
+2 -5
apps/playlist_catalog.c
··· 70 70 71 71 static size_t get_directory(char* dirbuf, size_t dirbuf_sz) 72 72 { 73 - char *pl_dir = PLAYLIST_CATALOG_DEFAULT_DIR; 73 + const char *pl_dir = PLAYLIST_CATALOG_DEFAULT_DIR; 74 74 75 75 /* directory config is of the format: "dir: /path/to/dir" */ 76 76 if (global_settings.playlist_catalog_dir[0] != '\0') ··· 79 79 } 80 80 81 81 /* remove duplicate leading '/' */ 82 - if (pl_dir[0] == '/' && pl_dir[1] == '/') 83 - { 84 - pl_dir++; 85 - } 82 + path_strip_leading_separators(pl_dir, &pl_dir); 86 83 87 84 return strlcpy(dirbuf, pl_dir, dirbuf_sz); 88 85 }
+21 -3
firmware/common/pathfuncs.c
··· 339 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 + 342 359 /* Removes trailing separators from a path 343 360 * "" *nameptr->NUL, len=0: "" 344 361 * "/" *nameptr->/, len=1: "/" ··· 462 479 size_t path_append_ex(char *buf, const char *basepath, size_t basepath_max, 463 480 const char *component, size_t bufsize) 464 481 { 465 - size_t len; 482 + size_t len = 0; 466 483 bool separate = false; 467 484 const char *base = basepath && basepath[0] ? basepath : buf; 468 485 if (!base) ··· 471 488 if (!buf) 472 489 bufsize = 0; 473 490 474 - if (path_is_absolute(component)) 491 + if (path_is_absolute(component)) /* starts with a '/' path separator */ 475 492 { 476 493 /* 'component' is absolute; replace all */ 477 494 basepath = component; ··· 484 501 485 502 if (base == buf) 486 503 len = strlen(buf); 487 - else 504 + else if (basepath) 488 505 { 506 + path_strip_leading_separators(basepath, &basepath); 489 507 len = strlcpy(buf, basepath, bufsize); 490 508 if (basepath_max < len) 491 509 {
+1
firmware/export/pathfuncs.h
··· 87 87 int path_strip_drive(const char *name, const char **nameptr, bool greedy); 88 88 size_t path_basename(const char *name, const char **nameptr); 89 89 size_t path_dirname(const char *name, const char **nameptr); 90 + size_t path_strip_leading_separators(const char *name, const char **nameptr); 90 91 size_t path_strip_trailing_separators(const char *name, const char **nameptr); 91 92 void path_correct_separators(char *dstpath, const char *path); 92 93 void path_remove_dot_segments(char *dstpath, const char *path);