From eed2d1323441861f2d41f0ecc0a72fcc9190fa5f Mon Sep 17 00:00:00 2001 From: Thorsten Töpper Date: Sat, 7 Feb 2026 21:43:17 +0100 Subject: file processor: Copied from my small-utils project --- include/hex_conversion.h | 113 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 include/hex_conversion.h (limited to 'include/hex_conversion.h') diff --git a/include/hex_conversion.h b/include/hex_conversion.h new file mode 100644 index 0000000..90ab9e4 --- /dev/null +++ b/include/hex_conversion.h @@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +/* Copyright 2026 Thorsten Töpper + * + * vim:ts=4:sw=4:expandtab + */ +#ifndef HEX_CONVERSION_H +#define HEX_CONVERSION_H + +#include +#include +#include + +#ifdef DEBUGBUILD +#include "trace_macros.h" +#endif + +#define ishex_macro(c) ((c>='0' && c <= '9') || (c>='A' && c <= 'F') || (c>='a' && c <= 'f')) + +int convert_line(char *s); +int ishex(unsigned char c); +int ishex_string(const char *s, size_t l); +unsigned char *convert_to_binary(char *hex, unsigned char *out); +char *convert_from_binary(unsigned char *bin, size_t l, char *out); + +/* short inline functions are fine in header */ +inline int convert_line(char *s) { + size_t i = 0, l = 0; + if (s == NULL) + return -1; + l=strlen(s); + for (i=0; i='0' && c <= '9') || (c>='A' && c <= 'F') || (c>='a' && c <= 'f')) { + return 1; + } + return 0; +}; + +inline int ishex_string(const char *s, size_t l) { + size_t i = 0; + if (s == 0) + return 0; + if (l == 0) + l = strlen(s); + for (; i