config_libconfig: eliminate relative paths from XDG_CONFIG_DIRS

According to the XDG Base Directory Specification, relative paths in
XDG_CONFIG_DIRS are invalid, so eliminate them if found.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2020-03-01 13:19:50 +00:00
parent 6b9eddae49
commit 529edce2b9
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
1 changed files with 11 additions and 2 deletions

View File

@ -66,7 +66,7 @@ const char * const * xdgConfigDirectories(void) {
} }
} }
// Store the string and the result pointers together so it can be // Store the string and the result pointers together so they can be
// freed together // freed together
char **dir_list = cvalloc(sizeof(char *) * (count + 2) + strlen(xdgd) + 1); char **dir_list = cvalloc(sizeof(char *) * (count + 2) + strlen(xdgd) + 1);
auto dirs = strcpy((char *)dir_list + sizeof(char *) * (count + 2), xdgd); auto dirs = strcpy((char *)dir_list + sizeof(char *) * (count + 2), xdgd);
@ -79,7 +79,16 @@ const char * const * xdgConfigDirectories(void) {
path++; path++;
} }
dir_list[count] = path; dir_list[count] = path;
dir_list[count + 1] = NULL;
size_t fill = 0;
for (size_t i = 0; i <= count; i++) {
if (dir_list[i][0] == '/') {
dir_list[fill] = dir_list[i];
fill++;
}
}
dir_list[fill] = NULL;
return (const char * const *)dir_list; return (const char * const *)dir_list;
} }