… | |
… | |
825 | g_free(f); |
825 | g_free(f); |
826 | } |
826 | } |
827 | |
827 | |
828 | struct file_wordexp { |
828 | struct file_wordexp { |
829 | int err; |
829 | int err; |
830 | char *pattern; |
|
|
831 | wordexp_t we; |
830 | wordexp_t we; |
832 | }; |
831 | }; |
833 | |
832 | |
834 | struct file_wordexp * |
833 | struct file_wordexp * |
835 | file_wordexp_new(const char *pattern) |
834 | file_wordexp_new(const char *pattern) |
836 | { |
835 | { |
837 | struct file_wordexp *ret=g_new0(struct file_wordexp, 1); |
836 | struct file_wordexp *ret=g_new0(struct file_wordexp, 1); |
838 | |
837 | |
839 | ret->pattern=g_strdup(pattern); |
|
|
840 | ret->err=wordexp(pattern, &ret->we, 0); |
838 | ret->err=wordexp(pattern, &ret->we, 0); |
841 | if (ret->err) |
839 | if (ret->err) |
842 | dbg(0,"wordexp('%s') returned %d\n", pattern, ret->err); |
840 | dbg(0,"wordexp('%s') returned %d\n", pattern, ret->err); |
843 | return ret; |
841 | return ret; |
844 | } |
842 | } |
845 | |
843 | |
846 | int |
844 | int |
847 | file_wordexp_get_count(struct file_wordexp *wexp) |
845 | file_wordexp_get_count(struct file_wordexp *wexp) |
848 | { |
846 | { |
849 | if (wexp->err) |
|
|
850 | return 1; |
|
|
851 | return wexp->we.we_wordc; |
847 | return wexp->we.we_wordc; |
852 | } |
848 | } |
853 | |
849 | |
854 | char ** |
850 | char ** |
855 | file_wordexp_get_array(struct file_wordexp *wexp) |
851 | file_wordexp_get_array(struct file_wordexp *wexp) |
856 | { |
852 | { |
857 | if (wexp->err) |
|
|
858 | return &wexp->pattern; |
|
|
859 | return wexp->we.we_wordv; |
853 | return wexp->we.we_wordv; |
860 | } |
854 | } |
861 | |
855 | |
862 | void |
856 | void |
863 | file_wordexp_destroy(struct file_wordexp *wexp) |
857 | file_wordexp_destroy(struct file_wordexp *wexp) |
864 | { |
858 | { |
865 | if (! wexp->err) |
859 | if (! wexp->err) |
866 | wordfree(&wexp->we); |
860 | wordfree(&wexp->we); |
867 | g_free(wexp->pattern); |
|
|
868 | g_free(wexp); |
861 | g_free(wexp); |
869 | } |
862 | } |
870 | |
863 | |
871 | |
864 | |
872 | int |
865 | int |