summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-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)
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 */
92char* get_dir(char* buf, int buf_size, const char* path, int level) 93char* 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}