This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
bfd: patch for missing strtoull
- From: Aldy Hernandez <aldyh at redhat dot com>
- To: binutils at sources dot redhat dot com
- Cc: nickc at redhat dot com
- Date: Fri, 4 Jan 2002 10:39:59 -0800
- Subject: bfd: patch for missing strtoull
hi guys!
MacOS X does not have strtoull so bfd doesn't build. *sigh*
here is a patch to add configury magic to check for strtoull, and if not
available, use our own version of strtoull (stolen from newlib).
is this the right approach?
ok to install?
Cheers.
Aldy
2002-01-04 Aldy Hernandez <aldyh@redhat.com>
* libbfd.c (strtoull): New.
Include ctype.h.
* sysdep.h: Add extern for strtoull.
* bfd/configure.in: Check for strtoull.
* bfd/configure: Regenerate.
* bfd/config.in: Regenerate.
* bfd/acconfig.h: New.
Index: configure.in
===================================================================
RCS file: /cvs/uberbaum/bfd/configure.in,v
retrieving revision 1.77
diff -c -p -r1.77 configure.in
*** configure.in 2002/01/04 14:49:03 1.77
--- configure.in 2002/01/04 18:30:25
*************** AC_HEADER_TIME
*** 141,146 ****
--- 141,148 ----
AC_HEADER_DIRENT
AC_CHECK_FUNCS(fcntl getpagesize setitimer sysconf fdopen getuid getgid)
+ AC_CHECK_FUNC(strtoull, [AC_DEFINE(HAVE_STRTOULL)], )
+
BFD_BINARY_FOPEN
BFD_NEED_DECLARATION(strstr)
Index: sysdep.h
===================================================================
RCS file: /cvs/uberbaum/bfd/sysdep.h,v
retrieving revision 1.6
diff -c -p -r1.6 sysdep.h
*** sysdep.h 2001/08/19 23:42:47 1.6
--- sysdep.h 2002/01/04 18:30:26
*************** extern void free ();
*** 125,130 ****
--- 125,134 ----
extern char *getenv ();
#endif
+ #ifndef HAVE_STRTOULL
+ extern unsigned long long strtoull ();
+ #endif
+
/* Define offsetof for those systems which lack it */
#ifndef offsetof
Index: libbfd.c
===================================================================
RCS file: /cvs/uberbaum/bfd/libbfd.c,v
retrieving revision 1.20
diff -c -p -r1.20 libbfd.c
*** libbfd.c 2001/09/21 14:25:09 1.20
--- libbfd.c 2002/01/04 18:30:28
*************** Foundation, Inc., 59 Temple Place - Suit
*** 24,29 ****
--- 24,31 ----
#include "sysdep.h"
#include "libbfd.h"
+ #include <ctype.h>
+
#ifndef HAVE_GETPAGESIZE
#define getpagesize() 2048
#endif
*************** warn_deprecated (what, file, line, func)
*** 1468,1470 ****
--- 1470,1541 ----
mask |= ~(size_t) func;
}
}
+
+ #ifndef HAVE_STRTOULL
+ /*
+ * Our own version of strtoull for imbecile systems.
+ *
+ * Convert a string to an unsigned long long integer.
+ *
+ * Ignores `locale' stuff. Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+ unsigned long long
+ strtoull (nptr, endptr, base)
+ const char *nptr;
+ char **endptr;
+ int base;
+ {
+ register const char *s = nptr;
+ register unsigned long long acc;
+ register int c;
+ register unsigned long long cutoff;
+ register 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 long)ULONG_LONG_MAX / (unsigned long long)base;
+ cutlim = (unsigned long long)ULONG_LONG_MAX % (unsigned long long)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_LONG_MAX;
+ } else if (neg)
+ acc = -acc;
+ if (endptr != 0)
+ *endptr = (char *) (any ? s - 1 : nptr);
+ return (acc);
+ }
+ #endif