summaryrefslogtreecommitdiffstats
path: root/testutil/section-value.c
diff options
context:
space:
mode:
Diffstat (limited to 'testutil/section-value.c')
-rw-r--r--testutil/section-value.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/testutil/section-value.c b/testutil/section-value.c
new file mode 100644
index 0000000..b4c0304
--- /dev/null
+++ b/testutil/section-value.c
@@ -0,0 +1,52 @@
+/* See LICENSE file for copyright and license details. */
+#include "../libsyscalls.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" /* clang is just being silly */
+#endif
+
+
+int
+main(int argc, char **argv)
+{
+ enum libsyscalls_datatype_section section;
+ unsigned long long int value;
+ size_t bits;
+ char *end;
+ enum libsyscalls_error err;
+
+ if (argc != 4) {
+ usage:
+ fprintf(stderr, "usage error\n");
+ return 1;
+ }
+
+ section = (enum libsyscalls_datatype_section)atoi(argv[1]);
+ errno = 0;
+ value = strtoull(argv[2], &end, 16);
+ if (errno || *end)
+ goto usage;
+ bits = (size_t)atol(argv[3]);
+
+ err = libsyscalls_section_value(value, bits, section, &value);
+ if (err == LIBSYSCALLS_E_INVAL) {
+ printf("inval\n");
+ goto out;
+ } else if (err) {
+ libsyscalls_perror(NULL, err);
+ return 1;
+ }
+
+ printf("%llX\n", value);
+
+out:
+ if (fflush(stdout) || fclose(stdout)) {
+ perror(NULL);
+ return 1;
+ }
+ return 0;
+}