Fix:Core:Return useful values in case of wordexp error
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Thu, 25 Aug 2011 21:59:05 +0000 (21:59 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Thu, 25 Aug 2011 21:59:05 +0000 (21:59 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@4713 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/file.c

index 2ce2358..14324aa 100644 (file)
@@ -828,6 +828,7 @@ file_destroy(struct file *f)
 
 struct file_wordexp {
        int err;
+       char *pattern;
        wordexp_t we;
 };
 
@@ -836,6 +837,7 @@ file_wordexp_new(const char *pattern)
 {
        struct file_wordexp *ret=g_new0(struct file_wordexp, 1);
 
+       ret->pattern=g_strdup(pattern);
        ret->err=wordexp(pattern, &ret->we, 0);
        if (ret->err)
                dbg(0,"wordexp('%s') returned %d\n", pattern, ret->err);
@@ -845,12 +847,16 @@ file_wordexp_new(const char *pattern)
 int
 file_wordexp_get_count(struct file_wordexp *wexp)
 {
+       if (wexp->error)
+               return 1;
        return wexp->we.we_wordc;
 }
 
 char **
 file_wordexp_get_array(struct file_wordexp *wexp)
 {
+       if (wexp->error)
+               return &wexp->pattern;
        return wexp->we.we_wordv;
 }
 
@@ -859,6 +865,7 @@ file_wordexp_destroy(struct file_wordexp *wexp)
 {
        if (! wexp->err)
                wordfree(&wexp->we);
+       g_free(wexp->pattern);
        g_free(wexp);
 }