From: Nicholas Nethercote Date: Sat, 22 Sep 2007 06:23:07 +0000 (+0000) Subject: Add VG_(atoll). X-Git-Tag: svn/VALGRIND_3_3_0~202 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2455b7eaf893f5fe383f0309ac062f56e4dde945;p=thirdparty%2Fvalgrind.git Add VG_(atoll). git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6899 --- diff --git a/coregrind/m_libcbase.c b/coregrind/m_libcbase.c index 8628feb975..a1f073cb39 100644 --- a/coregrind/m_libcbase.c +++ b/coregrind/m_libcbase.c @@ -63,6 +63,33 @@ Long VG_(atoll) ( Char* str ) return n; } +Long VG_(atoll16) ( Char* str ) +{ + Bool neg = False; + Long n = 0; + if (*str == '-') { str++; neg = True; }; + while (True) { + Char c = *str; + if (c >= '0' && c <= (Char)'9') { + n = 16*n + (Long)(c - '0'); + } + else + if (c >= 'A' && c <= (Char)'F') { + n = 16*n + (Long)((c - 'A') + 10); + } + else + if (c >= 'a' && c <= (Char)'f') { + n = 16*n + (Long)((c - 'a') + 10); + } + else { + break; + } + str++; + } + if (neg) n = -n; + return n; +} + Long VG_(atoll36) ( Char* str ) { Bool neg = False; diff --git a/include/pub_tool_libcbase.h b/include/pub_tool_libcbase.h index d9765fa976..658aedb4f3 100644 --- a/include/pub_tool_libcbase.h +++ b/include/pub_tool_libcbase.h @@ -42,7 +42,9 @@ extern Bool VG_(isdigit) ( Char c ); Converting strings to numbers ------------------------------------------------------------------ */ + // Nb: atoll16 doesn't handle a "0x" prefix. extern Long VG_(atoll) ( Char* str ); // base 10 +extern Long VG_(atoll16) ( Char* str ); // base 16 extern Long VG_(atoll36) ( Char* str ); // base 36 /* ---------------------------------------------------------------------