diff options
author | Stef Walter <stef@memberwebs.com> | 2009-11-15 20:26:16 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2009-11-15 20:30:45 +0000 |
commit | 363a869b000ee1c9337bc0086108f6a5960da326 (patch) | |
tree | 04b9d0575a5bab921699d76a8d1c9b2640d779a8 /src/config.c | |
parent | 6c610fd305c965e7ab83d3ffc0ab0e94733f01e6 (diff) |
Allow use of p11-tests as a library.
Diffstat (limited to 'src/config.c')
-rw-r--r-- | src/config.c | 33 |
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 |