From 363a869b000ee1c9337bc0086108f6a5960da326 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Sun, 15 Nov 2009 20:26:16 +0000 Subject: Allow use of p11-tests as a library. --- src/config.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'src/config.c') 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 #include @@ -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 -- cgit v1.2.3