X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fliboconfig%2Foconfig.c;h=79b53aec8825f858c87d4b83682b9b99450496be;hb=5b5f7f4e3dd28d9e41469c331f3f9f6a09e3147b;hp=2bb80cc99a864b6112dd065048221310b8ca3211;hpb=44e4d530c8db2e078cd73ab254d1be41a5f2812c;p=collectd.git diff --git a/src/liboconfig/oconfig.c b/src/liboconfig/oconfig.c index 2bb80cc9..79b53aec 100644 --- a/src/liboconfig/oconfig.c +++ b/src/liboconfig/oconfig.c @@ -27,6 +27,7 @@ extern FILE *yyin; oconfig_item_t *ci_root; +const char *c_file; static void yyset_in (FILE *fd) { @@ -38,8 +39,24 @@ 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) { @@ -47,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); @@ -59,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) { @@ -69,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 */ @@ -76,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); } /*