Commit 5417446e 5417446e257acc8fab46cef5d25605a810690ba4 by Sam Roberts

News funtions: mu_hex2ul(), mu_hexstr2ul().

1 parent 7557c0b1
...@@ -37,6 +37,9 @@ ...@@ -37,6 +37,9 @@
37 extern "C" { 37 extern "C" {
38 #endif 38 #endif
39 39
40 extern unsigned long mu_hex2ul __P ((char hex));
41 extern size_t mu_hexstr2ul __P ((unsigned long* ul, const char* hex, size_t len));
42
40 struct mu_timezone 43 struct mu_timezone
41 { 44 {
42 int utc_offset; 45 int utc_offset;
......
...@@ -30,6 +30,41 @@ ...@@ -30,6 +30,41 @@
30 #include <unistd.h> 30 #include <unistd.h>
31 31
32 #include <mailutils/mutil.h> 32 #include <mailutils/mutil.h>
33
34 /* convert a sequence of hex characters into an integer */
35
36 unsigned long mu_hex2ul(char hex)
37 {
38 if (hex >= '0' && hex <= '9')
39 return hex - '0';
40
41 if (hex >= 'a' && hex <= 'z')
42 return hex - 'a';
43
44 if (hex >= 'A' && hex <= 'Z')
45 return hex - 'A';
46
47 return -1;
48 }
49
50 size_t mu_hexstr2ul(unsigned long* ul, const char* hex, size_t len)
51 {
52 size_t r;
53
54 *ul = 0;
55
56 for (r = 0; r < len; r++)
57 {
58 unsigned long v = mu_hex2ul(hex[r]);
59
60 if(v == -1)
61 return r;
62
63 *ul = *ul * 16 + v;
64 }
65 return r;
66 }
67
33 /* Convert struct tm into time_t, taking into account timezone offset. 68 /* Convert struct tm into time_t, taking into account timezone offset.
34 69
35 mktime() always treats tm as if it was localtime, so convert it 70 mktime() always treats tm as if it was localtime, so convert it
......