diff options
author | Jari Vetoniemi <mailroxas@gmail.com> | 2017-04-20 16:49:35 +0300 |
---|---|---|
committer | Jari Vetoniemi <mailroxas@gmail.com> | 2017-05-01 22:58:22 +0300 |
commit | 29086b1d12a2c28cffdbfbf0b3990a7bd75506b9 (patch) | |
tree | 8acd48bc30932812744c0adb102d7a7add494357 /src/utils | |
parent | 76b8c9e03c97b16d9ff97f3b79c0ecbff0f5e7f2 (diff) |
work in progress
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/dec2bin.c | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/src/utils/dec2bin.c b/src/utils/dec2bin.c deleted file mode 100644 index 97e59bb..0000000 --- a/src/utils/dec2bin.c +++ /dev/null @@ -1,40 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <stdint.h> -#include <string.h> -#include <err.h> - -int -main(int argc, char *argv[]) -{ - if (argc < 3) - errx(EXIT_FAILURE, "usage: %s <u8|u16|u32|u64> number\n", argv[0]); - - const struct { - const char *t; - size_t sz; - } map[] = { - { .t = "u8", .sz = sizeof(uint8_t) }, - { .t = "u16", .sz = sizeof(uint16_t) }, - { .t = "u32", .sz = sizeof(uint32_t) }, - { .t = "u64", .sz = sizeof(uint64_t) }, - }; - -#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) - - size_t sz = 0; - for (size_t i = 0; i < ARRAY_SIZE(map); ++i) { - if (strcmp(argv[1], map[i].t)) - continue; - - sz = map[i].sz; - break; - } - - if (!sz) - errx(EXIT_FAILURE, "unknown type: %s", argv[1]); - - const uint64_t v = strtoll(argv[2], NULL, 10); - fwrite(&v, sz, 1, stdout); - return EXIT_SUCCESS; -} |