diff options
| author | cashmere <cashmere@autistici.org> | 2026-09-04 09:05:24 +0200 |
|---|---|---|
| committer | cashmere <cashmere@autistici.org> | 2026-09-04 09:05:24 +0200 |
| commit | 4f49b16079b27d7ce633619e4cddfdf2bffbc952 (patch) | |
| tree | c296c1e7f3c3e2f6859c6d3a1b1b208779b89679 /compat/zlib/contrib/puff/bin-writer.c | |
| download | relic-master.tar.gz | |
Diffstat (limited to 'compat/zlib/contrib/puff/bin-writer.c')
| -rw-r--r-- | compat/zlib/contrib/puff/bin-writer.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/compat/zlib/contrib/puff/bin-writer.c b/compat/zlib/contrib/puff/bin-writer.c new file mode 100644 index 0000000..cfd8306 --- /dev/null +++ b/compat/zlib/contrib/puff/bin-writer.c @@ -0,0 +1,26 @@ +#include "stdio.h" +#include "stdlib.h" + +/** + * Reads hexadecimal values from stdin and writes binary bytes to stdout. + * Accepts hex values separated by spaces, newlines, commas, etc. + * Handles both uppercase and lowercase hex digits. + */ +int main(void) { + char hexStr[3]; // Two hex digits + null terminator + int ch; + + // Read characters until EOF + while((ch = getchar()) != EOF) { + hexStr[0] = (char)ch; + hexStr[1] = (char)getchar(); + hexStr[2] = '\0'; // Null-terminate string + char *endptr; + unsigned char byte = (unsigned char)strtol(hexStr, &endptr, 16); + fwrite(&byte, 1, 1, stdout); + if((ch = getchar()) == EOF) // Read seaparating space + break; + } + + return 0; +} |
