added pl_x64()

This commit is contained in:
Alfred E. Heggestad 2011-03-15 16:26:00 +00:00
parent d5671216c4
commit 424119c0d6
2 changed files with 39 additions and 0 deletions

View file

@ -31,6 +31,7 @@ void pl_set_mbuf(struct pl *pl, const struct mbuf *mb);
uint32_t pl_u32(const struct pl *pl);
uint32_t pl_x32(const struct pl *pl);
uint64_t pl_u64(const struct pl *pl);
uint64_t pl_x64(const struct pl *pl);
bool pl_isset(const struct pl *pl);
int pl_strcpy(const struct pl *pl, char *str, size_t size);
int pl_strdup(char **dst, const struct pl *src);

View file

@ -148,6 +148,44 @@ uint64_t pl_u64(const struct pl *pl)
}
/**
* Convert a hex pointer-length object to a numeric 64-bit value
*
* @param pl Pointer-length object
*
* @return 64-bit value
*/
uint64_t pl_x64(const struct pl *pl)
{
uint64_t v=0, mul=1;
const char *p;
if (!pl || !pl->p)
return 0;
p = &pl->p[pl->l];
while (p > pl->p) {
const char ch = *--p;
uint8_t c;
if ('0' <= ch && ch <= '9')
c = ch - '0';
else if ('A' <= ch && ch <= 'F')
c = ch - 'A' + 10;
else if ('a' <= ch && ch <= 'f')
c = ch - 'a' + 10;
else
return 0;
v += mul * c;
mul *= 16;
}
return v;
}
/**
* Check if pointer-length object is set
*