diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2012-09-02 12:19:25 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2012-09-02 12:19:25 +0200 |
commit | d702ab14c97572e99a4586931c3ba465974c7081 (patch) | |
tree | 68e56bcacfc0df45f11c0b9f470feea9b70d0201 /googleurl | |
parent | 553f808fc4986818e820a76fa267c90a660d41c2 (diff) | |
download | crawler-d702ab14c97572e99a4586931c3ba465974c7081.tar.gz crawler-d702ab14c97572e99a4586931c3ba465974c7081.tar.bz2 |
googleurl works on FreeBSD now, C99 fix around 64-bit and strtoull
Diffstat (limited to 'googleurl')
-rw-r--r-- | googleurl/GNUmakefile | 9 | ||||
-rw-r--r-- | googleurl/strtoull.c | 77 | ||||
-rw-r--r-- | googleurl/strtoull.h | 21 | ||||
-rwxr-xr-x | googleurl/url_canon_internal.h | 3 |
4 files changed, 108 insertions, 2 deletions
diff --git a/googleurl/GNUmakefile b/googleurl/GNUmakefile index 88da0c5..293badf 100644 --- a/googleurl/GNUmakefile +++ b/googleurl/GNUmakefile @@ -33,8 +33,13 @@ CPP_OBJS = \ url_parse_file.o \ url_util.o -STATIC_LIB = \ - libgoogleurl.a +OBJS = \ + strtoull.o + +DYNAMIC_LIB = libgoogleurl.so +DYNAMIC_LIB_MAJOR = 0 +DYNAMIC_LIB_MINOR = 0 +DYNAMIC_LIB_PATCH = 0 -include $(TOPDIR)/makefiles/gmake/sub.mk diff --git a/googleurl/strtoull.c b/googleurl/strtoull.c new file mode 100644 index 0000000..bac3cae --- /dev/null +++ b/googleurl/strtoull.c @@ -0,0 +1,77 @@ +#include "strtoull.h" + +#include <ctype.h> +#include <limits.h> +#include <errno.h> + +#ifdef __GNUC__ +union __constcast { + const char *cstr; + char *str; +}; +#define CHAR_CONST_CAST( X ) (__extension__(union __constcast)( X )).str +#else +#define CHAR_CONST_CAST( X ) X +#endif + +uint64_t __strtoull(const char *nptr, char **endptr, int base) +{ + const char *s = nptr; + unsigned long acc; + int c; + unsigned long cutoff; + int neg = 0, any, cutlim; + + /* + * See strtol for comments as to the logic used. + */ + do { + c = *s++; + } while (isspace(c)); + if (c == '-') + { + neg = 1; + c = *s++; + } + else if (c == '+') + c = *s++; + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) + { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + cutoff = (unsigned long)ULONG_MAX / base; + cutlim = (unsigned long)ULONG_MAX % base; + for (acc = 0, any = 0;; c = *s++) + { + if (isdigit(c)) + c -= '0'; + else if (isalpha(c)) + c -= isupper(c) ? 'A' - 10 : 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) + { + acc = ULONG_MAX; + errno = ERANGE; + } + else if (neg) + acc = -acc; + if (endptr != 0) + *endptr = any ? CHAR_CONST_CAST(s) - 1 : CHAR_CONST_CAST(nptr); + return acc; +} diff --git a/googleurl/strtoull.h b/googleurl/strtoull.h new file mode 100644 index 0000000..5caf83b --- /dev/null +++ b/googleurl/strtoull.h @@ -0,0 +1,21 @@ +#ifndef _STRTOLL_H_ +#define _STRTOLL_H_ + +#include <stdlib.h> + +#ifdef FREEBSD +#include <stdint.h> +#ifdef __cplusplus +extern "C" { +#endif +uint64_t __strtoull(const char *nptr, char **endptr, int base); +#ifdef __cplusplus +} +#endif +#define strtoull __strtoull +#else +// use system one +#endif + +#endif + diff --git a/googleurl/url_canon_internal.h b/googleurl/url_canon_internal.h index ac5774f..4ff69a9 100755 --- a/googleurl/url_canon_internal.h +++ b/googleurl/url_canon_internal.h @@ -36,6 +36,9 @@ #define GOOGLEURL_SRC_URL_CANON_INTERNAL_H__ #include <stdlib.h> +#include <errno.h> + +#include "strtoull.h" #include "base/logging.h" #include "url_canon.h" |