Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

skin_tokens.c get_dir() improve path detection

get_dir grabs a component of a path
it now handles
multiple slashes, no leading slashes

Change-Id: I6c4a377796652808a02b44f6da0a63b201dd8f46

authored by

William Wilgus and committed by
William Wilgus
76a9a524 3714288f

+9 -4
+9 -4
apps/gui/skin_engine/skin_tokens.c
··· 87 87 * level - what to extract. 0 is file name, 1 is parent of file, 2 is 88 88 * parent of parent, etc. 89 89 * 90 + * path does not need to be absolute, ignores multiple slashes 90 91 * Returns buf if the desired level was found, NULL otherwise. 91 92 */ 92 93 char* get_dir(char* buf, int buf_size, const char* path, int level) ··· 94 95 const char* sep; 95 96 const char* last_sep; 96 97 int len; 97 - 98 + buf[0] = '\0'; 98 99 sep = path + strlen(path); 99 100 last_sep = sep; 100 101 ··· 105 106 if (!level) 106 107 break; 107 108 108 - level--; 109 109 last_sep = sep - 1; 110 + if (*last_sep != '/') /* ignore multiple separators */ 111 + level--; 110 112 } 111 113 } 112 114 113 - if (level || (last_sep <= sep)) 115 + if (level || (last_sep <= sep)) /* level was not found */ 114 116 return NULL; 115 117 116 - len = MIN(last_sep - sep, buf_size - 1); 118 + if (sep == path && *sep != '/') /* for paths without leading separator */ 119 + sep = path - 1; 120 + 121 + len = MIN((last_sep - sep), buf_size - 1); 117 122 strmemccpy(buf, sep + 1, len + 1); 118 123 return buf; 119 124 }