summaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/config.c b/src/config.c
index 652556e..09da702 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1,5 +1,6 @@
#include "p11-tests.h"
+#include "p11-tests-lib.h"
#include <ctype.h>
#include <stdio.h>
@@ -25,8 +26,8 @@ trim(char* data)
return data;
}
-void
-p11t_config_parse(const char* filename)
+int
+p11t_config_parse (const char* filename)
{
char* name = NULL;
char* value = NULL;
@@ -37,21 +38,29 @@ p11t_config_parse(const char* filename)
char* t;
f = fopen(filename, "r");
- if(f == NULL)
- p11t_msg_fatal("couldn't open config file: %s", filename);
+ if (f == NULL) {
+ p11t_msg_print ("couldn't open config file: %s", filename);
+ return -1;
+ }
/* Figure out size */
- if(fseek(f, 0, SEEK_END) == -1 || (len = ftell(f)) == -1 || fseek(f, 0, SEEK_SET) == -1)
- p11t_msg_fatal("couldn't seek config file: %s", filename);
+ if (fseek (f, 0, SEEK_END) == -1 || (len = ftell (f)) == -1 || fseek (f, 0, SEEK_SET) == -1) {
+ p11t_msg_print ("couldn't seek config file: %s", filename);
+ return -1;
+ }
assert(!config_data);
config_data = malloc(len + 2);
- if(!config_data)
- p11t_msg_fatal("out of memory");
+ if (!config_data) {
+ p11t_msg_print ("out of memory");
+ return -1;
+ }
/* And read in one block */
- if(fread(config_data, 1, len, f) != len)
- p11t_msg_fatal("couldn't read config file: %s", filename);
+ if (fread(config_data, 1, len, f) != len) {
+ p11t_msg_print ("couldn't read config file: %s", filename);
+ return -1;
+ }
fclose(f);
@@ -81,7 +90,7 @@ p11t_config_parse(const char* filename)
t = p + strcspn(p, ":=");
if(!*t)
{
- fprintf(stderr, "p11-test: invalid config line: %s", p);
+ fprintf (stderr, "p11-test: invalid config line: %s", p);
exit(1);
}
@@ -98,6 +107,8 @@ p11t_config_parse(const char* filename)
p11t_session_config(name, value);
}
}
+
+ return 0;
}
void