projects
/
tedtools.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9350eab
)
Add 64-bit variant for xtostr and strtox
author
teodor
<teodor>
Thu, 16 Oct 2008 11:32:16 +0000
(11:32 +0000)
committer
teodor
<teodor>
Thu, 16 Oct 2008 11:32:16 +0000
(11:32 +0000)
tools.c
patch
|
blob
|
history
tools.h
patch
|
blob
|
history
diff --git
a/tools.c
b/tools.c
index
a6c0206
..
07c0e46
100644
(file)
--- a/
tools.c
+++ b/
tools.c
@@
-71,7
+71,23
@@
strtox(char *src, char **end) {
return res;
}
return res;
}
-static char buf[10];
+u_int64_t
+strtox64(char *src, char **end) {
+ u_int32_t res=0, i=0;
+
+ while(src && *src && isXdigit(*src) && i<16) {
+ res = res << 4;
+ res |= str2hex[ *(unsigned char*)src ];
+ src++;
+ i++;
+ }
+
+ if ( end )
+ *end=src;
+ return res;
+}
+
+static char buf[32];
static char hex2str[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
char*
static char hex2str[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
char*
@@
-89,6
+105,21
@@
xtostr(u_int32_t x) {
return buf;
}
return buf;
}
+char*
+x64tostr(u_int64_t x) {
+ char *ptr=buf;
+ int i,wast=0;
+ for(i=60;i>=0;i-=4) {
+ *ptr = hex2str[ (x>>i) & 0x0f ];
+ if ( wast || *ptr!='0' || i==0 ) {
+ ptr++;
+ wast=1;
+ }
+ }
+ *ptr='\0';
+ return buf;
+}
+
double
timediff(struct timeval *begin, struct timeval *end) {
return ((double)( end->tv_sec - begin->tv_sec )) + ( (double)( end->tv_usec-begin->tv_usec ) ) / 1.0e+6;
double
timediff(struct timeval *begin, struct timeval *end) {
return ((double)( end->tv_sec - begin->tv_sec )) + ( (double)( end->tv_usec-begin->tv_usec ) ) / 1.0e+6;
diff --git
a/tools.h
b/tools.h
index
473e21b
..
f4ee5b7
100644
(file)
--- a/
tools.h
+++ b/
tools.h
@@
-34,8
+34,10
@@
#include <sys/time.h>
u_int32_t strtox(char *src, char **end);
#include <sys/time.h>
u_int32_t strtox(char *src, char **end);
+u_int64_t strtox64(char *src, char **end);
#define atox(x) strtox((x),NULL)
char* xtostr(u_int32_t x);
#define atox(x) strtox((x),NULL)
char* xtostr(u_int32_t x);
+char* x64tostr(u_int64_t x);
double timediff(struct timeval *begin, struct timeval *end);
double elapsedtime(struct timeval *begin);
double timediff(struct timeval *begin, struct timeval *end);
double elapsedtime(struct timeval *begin);