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