aboutsummaryrefslogtreecommitdiff
path: root/src/ini.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2023-11-20 08:49:43 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2023-11-20 08:49:43 -0500
commit601681d88387dddda70db8601a98cb89edea1d78 (patch)
tree2868f12cd952090d62600def59a1e512522b3495 /src/ini.c
parentb9576b9bddc5887d912643f7822d13df7140c84a (diff)
downloadstasis-601681d88387dddda70db8601a98cb89edea1d78.tar.gz
Implements slightly improved error handling
* Return status from conda_ and delivery_ functions * Caller prints meaningful error, and handles it * Enable warnings during compilation * Squelch format-truncation warning -- those strings are extremely unlikely to overflow (famous last words)
Diffstat (limited to 'src/ini.c')
-rw-r--r--src/ini.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/ini.c b/src/ini.c
index afbca6a..37d07a0 100644
--- a/src/ini.c
+++ b/src/ini.c
@@ -56,7 +56,7 @@ struct INIData *ini_getall(struct INIFILE *ini, char *section_name) {
static size_t i = 0;
section = ini_section_search(&ini, section_name);
- if (section->data[i]) {
+ if (section->data_count) {
result = section->data[i];
i++;
} else {
@@ -138,8 +138,7 @@ int ini_data_record(struct INIFILE **ini, char *section_name, char *key, char *v
struct INIData **tmp = realloc(section->data, (section->data_count + 1) * sizeof(**section->data));
if (!tmp) {
- perror(__FUNCTION__);
- exit(1);
+ return 1;
}
section->data = tmp;
if (!ini_data_get((*ini), section_name, key)) {
@@ -157,7 +156,7 @@ int ini_data_record(struct INIFILE **ini, char *section_name, char *key, char *v
value_tmp = realloc(data->value, value_len_new + 2);
if (!value_tmp) {
perror(__FUNCTION__ );
- exit(1);
+ return -1;
}
data->value = value_tmp;
*/
@@ -170,13 +169,19 @@ int ini_data_record(struct INIFILE **ini, char *section_name, char *key, char *v
void ini_section_record(struct INIFILE **ini, char *key) {
struct INISection **tmp = realloc((*ini)->section, ((*ini)->section_count + 1) * sizeof((*ini)->section));
if (!tmp) {
- perror(__FUNCTION__);
- exit(1);
+ return 1;
}
(*ini)->section = tmp;
(*ini)->section[(*ini)->section_count] = calloc(1, sizeof(*(*ini)->section[0]));
+ if (!(*ini)->section[(*ini)->section_count]) {
+ return -1;
+ }
(*ini)->section[(*ini)->section_count]->key = strdup(key);
+ if (!(*ini)->section[(*ini)->section_count]->key) {
+ return -1;
+ }
(*ini)->section_count++;
+ return 0;
}
void ini_show(struct INIFILE *ini) {
@@ -238,6 +243,9 @@ struct INIFILE *ini_open(const char *filename) {
char current_section[OMC_BUFSIZ] = {0};
char *key_last = NULL;
struct INIFILE *ini = ini_init();
+ if (ini == NULL) {
+ return NULL;
+ }
ini_section_init(&ini);
@@ -249,8 +257,9 @@ struct INIFILE *ini_open(const char *filename) {
// Open the configuration file for reading
fp = fopen(filename, "r");
if (!fp) {
- perror(filename);
- exit(1);
+ ini_free(&ini);
+ ini = NULL;
+ return NULL;
}
// Read file