summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2024-04-03 23:10:07 -0400
committerWilliam Wilgus <me.theuser@yahoo.com>2024-04-04 14:40:17 -0500
commit76a9a524c08ffe6b76321b556b4872cf1b75d76d (patch)
tree4a18ed4a86cf4f2930098aa3c9bd81d6ccfe7c74
parent3714288f7aa7182c3e60993b967343cdea968476 (diff)
downloadrockbox-76a9a524c0.tar.gz
rockbox-76a9a524c0.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
-rw-r--r--apps/gui/skin_engine/skin_tokens.c13
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)
* level - what to extract. 0 is file name, 1 is parent of file, 2 is
* parent of parent, etc.
*
+ * path does not need to be absolute, ignores multiple slashes
* Returns buf if the desired level was found, NULL otherwise.
*/
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)
const char* sep;
const char* last_sep;
int len;
-
+ buf[0] = '\0';
sep = path + strlen(path);
last_sep = sep;
@@ -105,15 +106,19 @@ char* get_dir(char* buf, int buf_size, const char* path, int level)
if (!level)
break;
- level--;
last_sep = sep - 1;
+ if (*last_sep != '/') /* ignore multiple separators */
+ level--;
}
}
- if (level || (last_sep <= sep))
+ if (level || (last_sep <= sep)) /* level was not found */
return NULL;
- len = MIN(last_sep - sep, buf_size - 1);
+ if (sep == path && *sep != '/') /* for paths without leading separator */
+ sep = path - 1;
+
+ len = MIN((last_sep - sep), buf_size - 1);
strmemccpy(buf, sep + 1, len + 1);
return buf;
}