Fix file wordexp in some paths #59

This commit is contained in:
simon987 2020-06-05 19:41:02 -04:00
parent 018b49fa4c
commit 8c1c1697e0
2 changed files with 24 additions and 11 deletions

View File

@ -26,10 +26,11 @@ dyn_buffer_t url_escape(char *str) {
}
char *abspath(const char *path) {
wordexp_t w;
wordexp(path, &w, 0);
char *abs = realpath(w.we_wordv[0], NULL);
char *expanded = expandpath(path);
char *abs = realpath(expanded, NULL);
free(expanded);
if (abs == NULL) {
return NULL;
}
@ -38,16 +39,28 @@ char *abspath(const char *path) {
strcat(abs, "/");
}
wordfree(&w);
return abs;
}
char *expandpath(const char *path) {
char tmp[PATH_MAX * 2] = {0,};
wordexp_t w;
wordexp(path, &w, 0);
char *expanded = malloc(strlen(w.we_wordv[0]) + 2);
strcpy(expanded, w.we_wordv[0]);
if (w.we_wordv == NULL) {
return NULL;
}
for (int i = 0; i < w.we_wordc; i++) {
strcat(tmp, w.we_wordv[i]);
if (i != w.we_wordc - 1) {
strcat(tmp, " ");
}
}
char *expanded = malloc(strlen(tmp) + 2);
strcpy(expanded, tmp);
strcat(expanded, "/");
wordfree(&w);

File diff suppressed because one or more lines are too long