X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fliboconfig%2Foconfig.c;h=79b53aec8825f858c87d4b83682b9b99450496be;hb=5313ade6a32041b9312e7fe38bb6a212a85f9a0b;hp=f8d18499d6caacb5eba0524a82ccef4767e9b2e0;hpb=6360474f4aa35dd1a587b6148ff88a23e6155132;p=collectd.git diff --git a/src/liboconfig/oconfig.c b/src/liboconfig/oconfig.c index f8d18499..79b53aec 100644 --- a/src/liboconfig/oconfig.c +++ b/src/liboconfig/oconfig.c @@ -24,18 +24,39 @@ #include "oconfig.h" -/* Functions provided by the scanner */ -void yyset_in (FILE *); +extern FILE *yyin; oconfig_item_t *ci_root; +const char *c_file; + +static void yyset_in (FILE *fd) +{ + yyin = fd; +} /* void yyset_in */ oconfig_item_t *oconfig_parse_fh (FILE *fh) { int status; oconfig_item_t *ret; + char file[10]; + yyset_in (fh); + if (NULL == c_file) { + int status; + + status = snprintf (file, sizeof (file), "", fileno (fh)); + + if ((status < 0) || (status >= sizeof (file))) { + c_file = ""; + } + else { + file[sizeof (file) - 1] = '\0'; + c_file = file; + } + } + status = yyparse (); if (status != 0) { @@ -43,6 +64,8 @@ oconfig_item_t *oconfig_parse_fh (FILE *fh) return (NULL); } + c_file = NULL; + ret = ci_root; ci_root = NULL; yyset_in ((FILE *) 0); @@ -55,6 +78,8 @@ oconfig_item_t *oconfig_parse_file (const char *file) FILE *fh; oconfig_item_t *ret; + c_file = file; + fh = fopen (file, "r"); if (fh == NULL) { @@ -65,6 +90,8 @@ oconfig_item_t *oconfig_parse_file (const char *file) ret = oconfig_parse_fh (fh); fclose (fh); + c_file = NULL; + return (ret); } /* oconfig_item_t *oconfig_parse_file */ @@ -72,11 +99,25 @@ void oconfig_free (oconfig_item_t *ci) { int i; + if (ci == NULL) + return; + + if (ci->key != NULL) + free (ci->key); + + for (i = 0; i < ci->values_num; i++) + if ((ci->values[i].type == OCONFIG_TYPE_STRING) + && (NULL != ci->values[i].value.string)) + free (ci->values[i].value.string); + if (ci->values != NULL) free (ci->values); for (i = 0; i < ci->children_num; i++) oconfig_free (ci->children + i); + + if (ci->children != NULL) + free (ci->children); } /*