diff options
author | William Wilgus <wilgus.william@gmail.com> | 2024-04-03 23:10:07 -0400 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2024-04-04 14:40:17 -0500 |
commit | 76a9a524c08ffe6b76321b556b4872cf1b75d76d (patch) | |
tree | 4a18ed4a86cf4f2930098aa3c9bd81d6ccfe7c74 /apps | |
parent | 3714288f7aa7182c3e60993b967343cdea968476 (diff) | |
download | rockbox-76a9a524c08ffe6b76321b556b4872cf1b75d76d.tar.gz rockbox-76a9a524c08ffe6b76321b556b4872cf1b75d76d.zip |
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
Diffstat (limited to 'apps')
-rw-r--r-- | apps/gui/skin_engine/skin_tokens.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c index f6c166b140..12277aa0ea 100644 --- a/apps/gui/skin_engine/skin_tokens.c +++ b/apps/gui/skin_engine/skin_tokens.c | |||
@@ -87,6 +87,7 @@ static const char* get_codectype(const struct mp3entry* id3) | |||
87 | * level - what to extract. 0 is file name, 1 is parent of file, 2 is | 87 | * level - what to extract. 0 is file name, 1 is parent of file, 2 is |
88 | * parent of parent, etc. | 88 | * parent of parent, etc. |
89 | * | 89 | * |
90 | * path does not need to be absolute, ignores multiple slashes | ||
90 | * Returns buf if the desired level was found, NULL otherwise. | 91 | * Returns buf if the desired level was found, NULL otherwise. |
91 | */ | 92 | */ |
92 | char* get_dir(char* buf, int buf_size, const char* path, int level) | 93 | char* get_dir(char* buf, int buf_size, const char* path, int level) |
@@ -94,7 +95,7 @@ char* get_dir(char* buf, int buf_size, const char* path, int level) | |||
94 | const char* sep; | 95 | const char* sep; |
95 | const char* last_sep; | 96 | const char* last_sep; |
96 | int len; | 97 | int len; |
97 | 98 | buf[0] = '\0'; | |
98 | sep = path + strlen(path); | 99 | sep = path + strlen(path); |
99 | last_sep = sep; | 100 | last_sep = sep; |
100 | 101 | ||
@@ -105,15 +106,19 @@ char* get_dir(char* buf, int buf_size, const char* path, int level) | |||
105 | if (!level) | 106 | if (!level) |
106 | break; | 107 | break; |
107 | 108 | ||
108 | level--; | ||
109 | last_sep = sep - 1; | 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 | return NULL; | 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 | strmemccpy(buf, sep + 1, len + 1); | 122 | strmemccpy(buf, sep + 1, len + 1); |
118 | return buf; | 123 | return buf; |
119 | } | 124 | } |