diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2014-01-29 14:03:05 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2014-02-02 22:58:19 +0000 |
commit | 9f9ab1dc667186c533454c87f70295fcb67b4e8a (patch) | |
tree | 98ee23a763792dae0f98f96a71b3a5c8c8320c17 /demos | |
parent | d162584b1154153d997fed18a9df2e60771fe06c (diff) | |
download | openssl-9f9ab1dc667186c533454c87f70295fcb67b4e8a.tar.gz |
Demo of use of errors in applications.
Diffstat (limited to 'demos')
-rw-r--r-- | demos/err/Makefile | 17 | ||||
-rw-r--r-- | demos/err/README | 12 | ||||
-rw-r--r-- | demos/err/main.c | 19 | ||||
-rw-r--r-- | demos/err/test_err.ec | 3 | ||||
-rw-r--r-- | demos/err/test_err.h | 24 |
5 files changed, 75 insertions, 0 deletions
diff --git a/demos/err/Makefile b/demos/err/Makefile new file mode 100644 index 0000000000..81503c8ed8 --- /dev/null +++ b/demos/err/Makefile @@ -0,0 +1,17 @@ +# Minimal makefile to generate error codes and link a test app +SRC= main.c +OBJ= main.o +HEADER=test_err.h +ERROBJ= test_err.o +CC=gcc +CFLAGS=-I../../include +LDFLAGS=-L../.. -lcrypto + +PERL=perl + +testapp: $(OBJ) $(ERROBJ) $(HEADER) + $(CC) -o testapp $(OBJ) $(ERROBJ) $(LDFLAGS) + +errors: + $(PERL) ../../util/mkerr.pl -conf test_err.ec \ + -nostatic -write $(SRC) diff --git a/demos/err/README b/demos/err/README new file mode 100644 index 0000000000..79c392ffae --- /dev/null +++ b/demos/err/README @@ -0,0 +1,12 @@ + +This directory contains a simple example of how to use the ERR functions of +OpenSSL to add error codes to an external application. + +To test it first do "make errors". This will build error codes and add them +to the header files. It will also create some functions to load error codes. +Notice how "test_err.h" is updated after this call and the C source file +"test_err.c" is created. These names are in the test_err.ec file passed to the +mkerr.pl script. + +Then do "make" which will build the test application. + diff --git a/demos/err/main.c b/demos/err/main.c new file mode 100644 index 0000000000..7f09fbfc7e --- /dev/null +++ b/demos/err/main.c @@ -0,0 +1,19 @@ +#include <openssl/err.h> + +#include "test_err.h" + +/* Simple error test routine */ + +void a_test_function(void) + { + TESTerr(TEST_F_A_TEST_FUNCTION, TEST_R_TEST_REASON_CODE); + TESTerr(TEST_F_A_TEST_FUNCTION, TEST_R_ANOTHER_TEST_REASON_CODE); + ERR_add_error_data(1, "some additional error data"); + } + +int main(int argc, char **argv) + { + ERR_load_TEST_strings(); + a_test_function(); + ERR_print_errors_fp(stderr); + } diff --git a/demos/err/test_err.ec b/demos/err/test_err.ec new file mode 100644 index 0000000000..46e95bb0de --- /dev/null +++ b/demos/err/test_err.ec @@ -0,0 +1,3 @@ +# Details: name of library, header file to use and +# file to output error codes to. +L TEST test_err.h test_err.c diff --git a/demos/err/test_err.h b/demos/err/test_err.h new file mode 100644 index 0000000000..96add52800 --- /dev/null +++ b/demos/err/test_err.h @@ -0,0 +1,24 @@ +/* Demo of use of error library */ + +#ifndef TEST_ERR_H +#define TEST_ERR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Test library name */ + +#define TEST_LIB_NAME "demo test library routines" + +/* Normal header details go here */ + +/* Prototypes are picked up by the error script to generate strings for + * function names. + */ + +void a_test_function(void); + +/* Everything after this point is auto generated when you do + * "make errors" + */ |