[dovecot-cvs] dovecot/src/lib Makefile.am, 1.54, 1.55 hex-dec.c,
NONE, 1.1 hex-dec.h, NONE, 1.1
cras at dovecot.org
cras at dovecot.org
Fri Nov 25 17:19:51 EET 2005
Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv4752
Modified Files:
Makefile.am
Added Files:
hex-dec.c hex-dec.h
Log Message:
Added decimal <-> hex string translation functions.
Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/Makefile.am,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- Makefile.am 25 Nov 2005 15:16:46 -0000 1.54
+++ Makefile.am 25 Nov 2005 15:19:49 -0000 1.55
@@ -16,6 +16,7 @@
file-set-size.c \
hash.c \
hex-binary.c \
+ hex-dec.c \
hmac-md5.c \
home-expand.c \
hostpid.c \
@@ -93,6 +94,7 @@
file-set-size.h \
hash.h \
hex-binary.h \
+ hex-dec.h \
hmac-md5.h \
home-expand.h \
hostpid.h \
--- NEW FILE: hex-dec.c ---
/* Copyright (c) 2005 Timo Sirainen */
#include "lib.h"
#include "hex-dec.h"
void dec2hex(unsigned char *hexstr, uintmax_t dec, unsigned int hexstr_size)
{
unsigned int i;
for (i = 0; i < hexstr_size; i++) {
unsigned int value = dec & 0x0f;
if (value < 10)
hexstr[hexstr_size-i-1] = value + '0';
else
hexstr[hexstr_size-i-1] = value - 10 + 'A';
dec >>= 4;
}
}
uintmax_t hex2dec(const unsigned char *data, unsigned int len)
{
unsigned int i;
uintmax_t value = 0;
for (i = 0; i < len; i++) {
value = value*0x10;
if (data[i] >= '0' && data[i] <= '9')
value += data[i]-'0';
else if (data[i] >= 'A' && data[i] <= 'F')
value += data[i]-'A' + 10;
else
return 0;
}
return value;
}
--- NEW FILE: hex-dec.h ---
#ifndef __HEX_DEC_H
#define __HEX_DEC_H
#define DEC2HEX(hexstr, str) \
dec2hex(hexstr, str, sizeof(hexstr))
/* Decimal -> hex string translation. The result isn't NUL-terminated. */
void dec2hex(unsigned char *hexstr, uintmax_t dec, unsigned int hexstr_size);
/* Parses hex string and returns its decimal value, or 0 in case of errors */
uintmax_t hex2dec(const unsigned char *data, unsigned int len);
#endif
More information about the dovecot-cvs
mailing list