X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=blobdiff_plain;f=list.c;h=0b3dd947049cd2ea9c8c30e47e231afd6bc68283;hp=8d73f11405ebad863a4c1fa5228b83c7f6620ccf;hb=bc7b118f0a40709c985b54c96d826e9057c9f0dd;hpb=f7df28b4d0155c780fa46a09d2dbcf7825faebae diff --git a/list.c b/list.c index 8d73f11..0b3dd94 100644 --- a/list.c +++ b/list.c @@ -24,10 +24,10 @@ static inline void uci_list_init(struct uci_list *ptr) /* inserts a new list entry between two consecutive entries */ static inline void __uci_list_add(struct uci_list *prev, struct uci_list *next, struct uci_list *ptr) { - prev->next = ptr; next->prev = ptr; ptr->prev = prev; ptr->next = next; + prev->next = ptr; } /* inserts a new list entry at the tail of the list */ @@ -71,6 +71,7 @@ static struct uci_option *uci_add_option(struct uci_section *section, const char option->value = uci_strdup(ctx, value); uci_list_add(§ion->options, &option->list); UCI_TRAP_RESTORE(ctx); + return option; error: uci_drop_option(option); @@ -178,7 +179,18 @@ found: return 0; } -char **uci_list_configs(struct uci_context *ctx) +static inline char *get_filename(char *path) +{ + char *p; + + p = strrchr(path, '/'); + p++; + if (!*p) + return NULL; + return p; +} + +char **uci_list_configs() { char **configs; glob_t globbuf; @@ -189,8 +201,15 @@ char **uci_list_configs(struct uci_context *ctx) return NULL; size = sizeof(char *) * (globbuf.gl_pathc + 1); - for(i = 0; i < globbuf.gl_pathc; i++) - size += strlen(globbuf.gl_pathv[i]) + 1; + for(i = 0; i < globbuf.gl_pathc; i++) { + char *p; + + p = get_filename(globbuf.gl_pathv[i]); + if (!p) + continue; + + size += strlen(p) + 1; + } configs = malloc(size); if (!configs) @@ -199,8 +218,14 @@ char **uci_list_configs(struct uci_context *ctx) memset(configs, 0, size); buf = (char *) &configs[globbuf.gl_pathc + 1]; for(i = 0; i < globbuf.gl_pathc; i++) { + char *p; + + p = get_filename(globbuf.gl_pathv[i]); + if (!p) + continue; + configs[i] = buf; - strcpy(buf, globbuf.gl_pathv[i]); + strcpy(buf, p); buf += strlen(buf) + 1; } return configs;