desc = stringcopy(description, 0);
if (!desc)
goto errmalloc;
-
+
if (!*cf) {
newcf = malloc(sizeof(struct gconffile) * 2);
if (!newcf)
newcf[0].path = desc;
*cf = newcf;
return file;
-
- errmalloc:
+
+errmalloc:
free(desc);
fclose(file);
debug(DBG_ERR, "malloc failed");
FILE *f = NULL;
glob_t globbuf;
char *path, *curfile = NULL, *dir;
-
+
/* if cfgpath is relative, make it relative to current config */
if (*cfgpath == '/')
path = (char *)cfgpath;
}
memset(&globbuf, 0, sizeof(glob_t));
if (glob(path, 0, NULL, &globbuf)) {
- debug(DBG_INFO, "could not glob %s", path);
+ debug(DBG_WARN, "could not glob %s", path);
goto exit;
}
f = pushgconfpath(cf, globbuf.gl_pathv[i]);
if (!f)
break;
- }
+ }
globfree(&globbuf);
- exit:
+exit:
if (curfile) {
free(curfile);
free(path);
return 1;
}
+void freegconfmstr(char **mstr) {
+ int i;
+
+ if (mstr) {
+ for (i = 0; mstr[i]; i++)
+ free(mstr[i]);
+ free(mstr);
+ }
+}
+
void freegconf(struct gconffile **cf) {
int i;
if (!*cf)
return;
-
+
for (i = 0; (*cf)[i].data || (*cf)[i].path; i++) {
if ((*cf)[i].file) {
fclose((*cf)[i].file);
int getlinefromcf(struct gconffile *cf, char *line, const size_t size) {
size_t i, pos;
-
+
if (!cf)
return 0;
-
+
if (cf->file)
return fgets(line, size, cf->file) ? 1 : 0;
else if (cf->data) {
char line[1024];
char *tokens[3], *s;
int tcount;
-
+
*opt = NULL;
*val = NULL;
*conftype = 0;
-
+
if (!cf || !*cf || (!(*cf)->file && !(*cf)->data))
return 1;
}
break;
}
-
+
switch (tcount) {
case 2:
*opt = stringcopy(tokens[0], 0);
if (**val)
return 1;
-
+
debug(DBG_ERR, "configuration error, option %s needs a non-empty value", *opt);
goto errexit;
- errmalloc:
+errmalloc:
debug(DBG_ERR, "malloc failed");
- errexit:
+errexit:
free(*opt);
*opt = NULL;
free(*val);
void unhex(char *s) {
char *t;
for (t = s; *t; s++) {
- if (*t == '%' && isxdigit(t[1]) && isxdigit(t[2])) {
+ if (*t == '%' && isxdigit((int)t[1]) && isxdigit((int)t[2])) {
*s = 16 * hexdigit2int(t[1]) + hexdigit2int(t[2]);
t += 3;
} else
*s = '\0';
}
+typedef int (*t_fptr)(struct gconffile **, void *, char *, char *, char *);
+
/* returns 1 if ok, 0 on error */
/* caller must free returned values also on error */
int getgenericconfig(struct gconffile **cf, char *block, ...) {
uint8_t *bln = NULL;
long int *lint = NULL;
int type = 0, conftype = 0, n;
- int (*cbk)(struct gconffile **, void *, char *, char *, char *) = NULL;
+ t_fptr cbk = NULL;
void *cbkarg = NULL;
for (;;) {
free(val);
continue;
}
-
+
va_start(ap, block);
while ((word = va_arg(ap, char *))) {
type = va_arg(ap, int);
goto errparam;
break;
case CONF_CBK:
- cbk = va_arg(ap, int (*)(struct gconffile **, void *, char *, char *, char *));
+ cbk = va_arg(ap, t_fptr);
if (!cbk)
goto errparam;
cbkarg = va_arg(ap, void *);
break;
}
va_end(ap);
-
+
if (!word) {
if (block)
debug(DBG_ERR, "configuration error in block %s, unknown option %s", block, opt);
}
if (block)
debug(DBG_DBG, "getgenericconfig: block %s: %s = %s", block, opt, val);
- else
+ else
debug(DBG_DBG, "getgenericconfig: %s = %s", opt, val);
if (type == CONF_BLN || type == CONF_LINT)
free(val);
}
- errparam:
+errparam:
debug(DBG_ERR, "getgenericconfig: internal parameter error");
- errexit:
+errexit:
free(opt);
free(val);
return 0;
}
+
+/* Local Variables: */
+/* c-file-style: "stroustrup" */
+/* End: */