diff options
Diffstat (limited to '')
-rw-r--r-- | common/exechelp-posix.c | 4 | ||||
-rw-r--r-- | common/stringhelp.c | 20 | ||||
-rw-r--r-- | common/stringhelp.h | 2 |
3 files changed, 23 insertions, 3 deletions
diff --git a/common/exechelp-posix.c b/common/exechelp-posix.c index b1b56f30c..943f20aa5 100644 --- a/common/exechelp-posix.c +++ b/common/exechelp-posix.c @@ -36,9 +36,7 @@ #include <stdio.h> #include <stdlib.h> -#ifdef HAVE_STDINT_H -# include <stdint.h> -#endif +#include <stdint.h> #include <string.h> #include <errno.h> #include <assert.h> diff --git a/common/stringhelp.c b/common/stringhelp.c index 990fc3577..b5d9f4cf6 100644 --- a/common/stringhelp.c +++ b/common/stringhelp.c @@ -58,6 +58,7 @@ #define tohex_lower(n) ((n) < 10 ? ((n) + '0') : (((n) - 10) + 'a')) + /* Sometimes we want to avoid mixing slashes and backslashes on W32 and prefer backslashes. There is usual no problem with mixing them, however a very few W32 API calls can't grok plain slashes. @@ -660,6 +661,25 @@ compare_filenames (const char *a, const char *b) } +/* Convert a base-10 number in STRING into a 64 bit unsigned int + * value. Leading white spaces are skipped but no error checking is + * done. Thus it is similar to atoi(). */ +uint64_t +string_to_u64 (const char *string) +{ + uint64_t val = 0; + + while (spacep (string)) + string++; + for (; digitp (string); string++) + { + val *= 10; + val += *string - '0'; + } + return val; +} + + /* Convert 2 hex characters at S to a byte value. Return this value or -1 if there is an error. */ int diff --git a/common/stringhelp.h b/common/stringhelp.h index adf2f2060..79d228415 100644 --- a/common/stringhelp.h +++ b/common/stringhelp.h @@ -33,6 +33,7 @@ #ifndef GNUPG_COMMON_STRINGHELP_H #define GNUPG_COMMON_STRINGHELP_H +#include <stdint.h> #include "types.h" /*-- stringhelp.c --*/ @@ -59,6 +60,7 @@ char *make_absfilename_try (const char *first_part, ...) GPGRT_ATTR_SENTINEL(0); int compare_filenames( const char *a, const char *b ); +uint64_t string_to_u64 (const char *string); int hextobyte (const char *s); size_t utf8_charcount (const char *s, int len); |