summaryrefslogtreecommitdiffstats
path: root/ffi/examples
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-03-22 16:19:39 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-03-22 16:19:39 +0100
commit6a9e2743d149fecd5d7706b273dc69a45fe25ea2 (patch)
treef1d3d40d578467416659d96cee6a2a68b9c31889 /ffi/examples
parent1d35557a8f7866141f84b2764287f384a8e12872 (diff)
openpgp-ffi: Replace glibc's error function.
- To make the tests and examples more portable, provide our own roughly compatible replacement for glibc's error(3).
Diffstat (limited to 'ffi/examples')
-rw-r--r--ffi/examples/configure.c13
-rw-r--r--ffi/examples/keyserver.c11
2 files changed, 21 insertions, 3 deletions
diff --git a/ffi/examples/configure.c b/ffi/examples/configure.c
index 38b15c05..23e243ac 100644
--- a/ffi/examples/configure.c
+++ b/ffi/examples/configure.c
@@ -1,9 +1,18 @@
#define _GNU_SOURCE
#include <assert.h>
-#include <error.h>
+/* Roughly glibc compatible error reporting. */
+#define error(S, E, F, ...) do { \
+ fprintf (stderr, (F), __VA_ARGS__); \
+ int s = (S), e = (E); \
+ if (e) { fprintf (stderr, ": %s", strerror (e)); } \
+ fprintf (stderr, "\n"); \
+ fflush (stderr); \
+ if (s) { exit (s); } \
+ } while (0)
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <sequoia.h>
@@ -34,7 +43,7 @@ main (int argc, char **argv)
pgp_error_free (err);
}
else
- error (1, 0, "This should not be allowed");
+ assert (! "reachable");
sq_keyserver_free (ks);
sq_context_free (ctx);
diff --git a/ffi/examples/keyserver.c b/ffi/examples/keyserver.c
index f7437472..1e6ca135 100644
--- a/ffi/examples/keyserver.c
+++ b/ffi/examples/keyserver.c
@@ -1,8 +1,17 @@
#define _GNU_SOURCE
-#include <error.h>
+/* Roughly glibc compatible error reporting. */
+#define error(S, E, F, ...) do { \
+ fprintf (stderr, (F), __VA_ARGS__); \
+ int s = (S), e = (E); \
+ if (e) { fprintf (stderr, ": %s", strerror (e)); } \
+ fprintf (stderr, "\n"); \
+ fflush (stderr); \
+ if (s) { exit (s); } \
+ } while (0)
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <sequoia.h>