summaryrefslogtreecommitdiffstats
path: root/openpgp-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 /openpgp-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 'openpgp-ffi/examples')
-rw-r--r--openpgp-ffi/examples/armor.c10
-rw-r--r--openpgp-ffi/examples/decrypt-with.c11
-rw-r--r--openpgp-ffi/examples/encrypt-for.c12
-rw-r--r--openpgp-ffi/examples/example.c11
-rw-r--r--openpgp-ffi/examples/immutable-reference-demo.c10
-rw-r--r--openpgp-ffi/examples/parser.c12
-rw-r--r--openpgp-ffi/examples/reader.c11
-rw-r--r--openpgp-ffi/examples/type-safety-demo.c10
-rw-r--r--openpgp-ffi/examples/use-after-free-demo.c10
9 files changed, 88 insertions, 9 deletions
diff --git a/openpgp-ffi/examples/armor.c b/openpgp-ffi/examples/armor.c
index 42395811..49ed533c 100644
--- a/openpgp-ffi/examples/armor.c
+++ b/openpgp-ffi/examples/armor.c
@@ -1,6 +1,14 @@
#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 <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/openpgp-ffi/examples/decrypt-with.c b/openpgp-ffi/examples/decrypt-with.c
index ae5e871d..d30b2d52 100644
--- a/openpgp-ffi/examples/decrypt-with.c
+++ b/openpgp-ffi/examples/decrypt-with.c
@@ -3,10 +3,19 @@
#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/openpgp.h>
diff --git a/openpgp-ffi/examples/encrypt-for.c b/openpgp-ffi/examples/encrypt-for.c
index 4a92d023..de2abd64 100644
--- a/openpgp-ffi/examples/encrypt-for.c
+++ b/openpgp-ffi/examples/encrypt-for.c
@@ -2,9 +2,19 @@
encrypt a file. */
#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/openpgp.h>
diff --git a/openpgp-ffi/examples/example.c b/openpgp-ffi/examples/example.c
index 46a45529..3c561761 100644
--- a/openpgp-ffi/examples/example.c
+++ b/openpgp-ffi/examples/example.c
@@ -1,8 +1,17 @@
#define _GNU_SOURCE
#include <errno.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 <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <sequoia/openpgp.h>
diff --git a/openpgp-ffi/examples/immutable-reference-demo.c b/openpgp-ffi/examples/immutable-reference-demo.c
index a0ada27b..47efbdd6 100644
--- a/openpgp-ffi/examples/immutable-reference-demo.c
+++ b/openpgp-ffi/examples/immutable-reference-demo.c
@@ -1,6 +1,14 @@
#define _GNU_SOURCE
#include <errno.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 <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/openpgp-ffi/examples/parser.c b/openpgp-ffi/examples/parser.c
index 5ded2de2..dc404fec 100644
--- a/openpgp-ffi/examples/parser.c
+++ b/openpgp-ffi/examples/parser.c
@@ -2,10 +2,20 @@
* also serves as a simple benchmark. */
#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 <time.h>
+#include <string.h>
+#include <stdlib.h>
#include <sequoia/openpgp.h>
diff --git a/openpgp-ffi/examples/reader.c b/openpgp-ffi/examples/reader.c
index b0273ebb..13c47f69 100644
--- a/openpgp-ffi/examples/reader.c
+++ b/openpgp-ffi/examples/reader.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/openpgp.h>
diff --git a/openpgp-ffi/examples/type-safety-demo.c b/openpgp-ffi/examples/type-safety-demo.c
index ad4870e2..d2bc523e 100644
--- a/openpgp-ffi/examples/type-safety-demo.c
+++ b/openpgp-ffi/examples/type-safety-demo.c
@@ -1,6 +1,14 @@
#define _GNU_SOURCE
#include <errno.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 <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/openpgp-ffi/examples/use-after-free-demo.c b/openpgp-ffi/examples/use-after-free-demo.c
index e64a3c1f..30863c81 100644
--- a/openpgp-ffi/examples/use-after-free-demo.c
+++ b/openpgp-ffi/examples/use-after-free-demo.c
@@ -1,6 +1,14 @@
#define _GNU_SOURCE
#include <errno.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 <fcntl.h>
#include <stdio.h>
#include <stdlib.h>