#include <errno.h>
#include <rte_string_fns.h>
#include <rte_common.h>
+#include <rte_log.h>
#include "rte_cfgfile.h"
struct rte_cfgfile_section *sections;
};
+static int cfgfile_logtype;
+
+#define CFG_LOG(level, fmt, args...) \
+ rte_log(RTE_LOG_ ## level, cfgfile_logtype, "%s(): " fmt "\n", \
+ __func__, ## args)
+
/** when we resize a file structure, how many extra entries
* for new sections do we add in */
#define CFG_ALLOC_SECTION_BATCH 8
unsigned int i;
if (!params) {
- printf("Error - missing cfgfile parameters\n");
+ CFG_LOG(ERR, "missing cfgfile parameters\n");
return -EINVAL;
}
}
if (valid_comment == 0) {
- printf("Error - invalid comment characters %c\n",
+ CFG_LOG(ERR, "invalid comment characters %c\n",
params->comment_character);
return -ENOTSUP;
}
size_t len = strnlen(buffer, sizeof(buffer));
lineno++;
if ((len >= sizeof(buffer) - 1) && (buffer[len-1] != '\n')) {
- printf("Error line %d - no \\n found on string. "
+ CFG_LOG(ERR, " line %d - no \\n found on string. "
"Check if line too long\n", lineno);
goto error1;
}
/* section heading line */
char *end = memchr(buffer, ']', len);
if (end == NULL) {
- printf("Error line %d - no terminating ']'"
- "character found\n", lineno);
+ CFG_LOG(ERR,
+ "line %d - no terminating ']' character found\n",
+ lineno);
goto error1;
}
*end = '\0';
split[0] = buffer;
split[1] = memchr(buffer, '=', len);
if (split[1] == NULL) {
- printf("Error line %d - no '='"
- "character found\n", lineno);
+ CFG_LOG(ERR,
+ "line %d - no '=' character found\n",
+ lineno);
goto error1;
}
*split[1] = '\0';
if (!(flags & CFG_FLAG_EMPTY_VALUES) &&
(*split[1] == '\0')) {
- printf("Error at line %d - cannot use empty "
- "values\n", lineno);
+ CFG_LOG(ERR,
+ "line %d - cannot use empty values\n",
+ lineno);
goto error1;
}
sizeof(curr_section->entries[i].value));
return 0;
}
- printf("Error - entry name doesn't exist\n");
+
+ CFG_LOG(ERR, "entry name doesn't exist\n");
return -EINVAL;
}
{
return rte_cfgfile_get_entry(cfg, sectionname, entryname) != NULL;
}
+
+RTE_INIT(cfgfile_init)
+{
+ cfgfile_logtype = rte_log_register("lib.cfgfile");
+ if (cfgfile_logtype >= 0)
+ rte_log_set_level(cfgfile_logtype, RTE_LOG_INFO);
+}