aboutsummaryrefslogtreecommitdiff
path: root/src/hex_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hex_utils.c')
-rw-r--r--src/hex_utils.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/hex_utils.c b/src/hex_utils.c
index 6629f10..e18df58 100644
--- a/src/hex_utils.c
+++ b/src/hex_utils.c
@@ -18,23 +18,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/* Convenience function to convert to/from ascii strings of hex digits.
+/* Convenience function to convert to/from ascii strings of hex digits.
*/
-#include <stdio.h>
-#include <stdint.h>
-
+#include "general.h"
#include "hex_utils.h"
-static char hexdigits[] = "0123456789abcdef";
+static const char hexdigits[] = "0123456789abcdef";
-char * hexify(char *hex, const unsigned char *buf, int size)
+char * hexify(char *hex, const void *buf, size_t size)
{
char *tmp = hex;
+ const uint8_t *b = buf;
- while(size--) {
- *tmp++ = hexdigits[*buf >> 4];
- *tmp++ = hexdigits[*buf++ & 0xF];
+ while (size--) {
+ *tmp++ = hexdigits[*b >> 4];
+ *tmp++ = hexdigits[*b++ & 0xF];
}
*tmp++ = 0;
@@ -44,18 +43,19 @@ char * hexify(char *hex, const unsigned char *buf, int size)
static uint8_t unhex_digit(char hex)
{
uint8_t tmp = hex - '0';
- if(tmp > 9)
+ if(tmp > 9)
tmp -= 'A' - '0' - 10;
- if(tmp > 16)
+ if(tmp > 16)
tmp -= 'a' - 'A';
return tmp;
}
-char * unhexify(unsigned char *buf, const char *hex, int size)
+char * unhexify(void *buf, const char *hex, size_t size)
{
- while(size--) {
- *buf = unhex_digit(*hex++) << 4;
- *buf++ |= unhex_digit(*hex++);
+ uint8_t *b = buf;
+ while (size--) {
+ *b = unhex_digit(*hex++) << 4;
+ *b++ |= unhex_digit(*hex++);
}
return buf;
}