Commit 5417446e 5417446e257acc8fab46cef5d25605a810690ba4 by Sam Roberts

News funtions: mu_hex2ul(), mu_hexstr2ul().

1 parent 7557c0b1
......@@ -37,6 +37,9 @@
extern "C" {
#endif
extern unsigned long mu_hex2ul __P ((char hex));
extern size_t mu_hexstr2ul __P ((unsigned long* ul, const char* hex, size_t len));
struct mu_timezone
{
int utc_offset;
......
......@@ -30,6 +30,41 @@
#include <unistd.h>
#include <mailutils/mutil.h>
/* convert a sequence of hex characters into an integer */
unsigned long mu_hex2ul(char hex)
{
if (hex >= '0' && hex <= '9')
return hex - '0';
if (hex >= 'a' && hex <= 'z')
return hex - 'a';
if (hex >= 'A' && hex <= 'Z')
return hex - 'A';
return -1;
}
size_t mu_hexstr2ul(unsigned long* ul, const char* hex, size_t len)
{
size_t r;
*ul = 0;
for (r = 0; r < len; r++)
{
unsigned long v = mu_hex2ul(hex[r]);
if(v == -1)
return r;
*ul = *ul * 16 + v;
}
return r;
}
/* Convert struct tm into time_t, taking into account timezone offset.
mktime() always treats tm as if it was localtime, so convert it
......