diff options
author | Mattias Andrée <maandree@kth.se> | 2023-12-16 12:40:10 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-12-16 12:40:10 +0100 |
commit | 683f205402a99cfc8cea46c83ce9b46a42616d42 (patch) | |
tree | f6ee1619454a6ec8b9e31770bbbc2abf36aae2fd /testutil/make-signed.c | |
parent | Improve portability (diff) | |
download | libsyscalls-683f205402a99cfc8cea46c83ce9b46a42616d42.tar.gz libsyscalls-683f205402a99cfc8cea46c83ce9b46a42616d42.tar.bz2 libsyscalls-683f205402a99cfc8cea46c83ce9b46a42616d42.tar.xz |
All kinds of stuff
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | testutil/make-signed.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/testutil/make-signed.c b/testutil/make-signed.c new file mode 100644 index 0000000..7cd0134 --- /dev/null +++ b/testutil/make-signed.c @@ -0,0 +1,56 @@ +/* See LICENSE file for copyright and license details. */ +#include "../libsyscalls.h" + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" /* clang is just being silly */ +#endif + + +int +main(int argc, char **argv) +{ + int sign, neg = -1; + size_t bits; + const char *xval; + enum libsyscalls_error err; + unsigned long long int value; + char *end; + + if (argc != 4) { + usage: + fprintf(stderr, "usage error\n"); + return 1; + } + + sign = atoi(argv[1]); + bits = (unsigned long long int)atoll(argv[2]); + xval = argv[3]; + neg = *xval == '-'; + xval = &xval[neg]; + errno = 0; + value = strtoull(xval, &end, 16); + if (errno || *end) + goto usage; + + err = libsyscalls_make_signed_integer(value, neg, (enum libsyscalls_datatype_sign_representation)sign, bits, &value); + if (err == LIBSYSCALLS_E_INVAL) { + printf("inval\n"); + goto out; + } else if (err) { + libsyscalls_perror(NULL, err); + return 1; + } + printf("%0*llX\n", (int)strlen(xval), value); + +out: + if (fflush(stdout) || fclose(stdout)) { + perror(NULL); + return 1; + } + return 0; +} |