--- ./GNUnet/src/util/storage.c Wed Jul 10 17:49:37 2002 +++ ./GNUnet.orig/src/util/storage.c Wed Jul 10 17:54:30 2002 @@ -40,7 +40,6 @@ #include #include #include -#include static int atoo(char *s) { int n = 0; @@ -91,34 +90,46 @@ * @returns the full file name, expanded with wordexp, * NULL is returned on error **/ -FileName expandFileName(FileName filename) -{ - wordexp_t result; - char *expanded_filename; - unsigned short i; - unsigned short expanded_filename_count; - - if (wordexp(filename, &result, 0)) { - /* An error occured, dont expand */ - wordfree(&result); - return(filename); - } - - expanded_filename_count = 1 + strlen(result.we_wordv[0]); - expanded_filename = malloc(expanded_filename_count); - strcpy(expanded_filename, result.we_wordv[0]); - - /* Expand the strings specified for the arguments. */ - for (i = 1; i < result.we_wordc; i++) { - expanded_filename_count += strlen(result.we_wordv[i]) + 1; - expanded_filename = realloc(expanded_filename, expanded_filename_count); - strcat(expanded_filename, " "); - strcat(expanded_filename, result.we_wordv[i]); - } - wordfree(&result); - - return(expanded_filename); -} +FileName expandFileName(FileName fil) { + FileName fm; + FileName fn; + + if (fil == NULL) + return NULL; + + if (fil[0] == '~') { + fm = getenv("HOME"); + if (fm == NULL) + fm = "$HOME"; /* keep it symbolic to show error to user! */ + fn = xmalloc(strlen(fm) + strlen(fil) + 1, + "expandFileName: fn"); + fn[0] = 0; + strcat(fn, fm); + strcat(fn, "/"); + strcat(fn, &fil[1]); /* do not copy '~' */ + return fn; + } + if (fil[0] == '/') { + /* absolute path, just copy */ + fn = xmalloc(strlen(fil) + 1, + "expandFileName: fn (2)"); + strcpy(fn, fil); + return fn; + } + fm = getenv("PWD"); + if (fm == NULL) + fm = "$PWD"; + fn = xmalloc(strlen(fm) + 1 + strlen(fil) + 1, + "expandFileName: fn (3)"); + fn[0] = 0; + strcat(fn, fm); + strcat(fn, "/"); + strcat(fn, fil); + + printf("filename is %s, was %s\n", fn, fil); + getchar(); + return fn; +} /** * implementation of "mkdir -p"