replace: Replace BSD strtoll by wrapping strtoll instead of strtoq
authorFelix Janda <felix.janda@posteo.de>
Sun, 21 Jun 2015 10:03:56 +0000 (12:03 +0200)
committerVolker Lendecke <vl@samba.org>
Mon, 22 Jun 2015 10:49:10 +0000 (12:49 +0200)
When it is detected that strtoll returns EINVAL not only in the case
that the base is not supported, HAVE_BSD_STRTOLL is declared and
strtoll is replaced. The current replacement code wraps strtoq in
order to replace strtoll and errors out when strtoq is missing.

In order to remove this possible error path, we can use strtoll instead
of strtoq since the code is only used when it is known that strtoll exists.

The fixes a compilation problem on linux systems using musl libc, which
has a BSD-like strtoll but no strtoq.

Signed-off-by: Felix Janda <felix.janda@posteo.de>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: "Stefan (metze) Metzmacher" <metze@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Mon Jun 22 12:49:10 CEST 2015 on sn-devel-104

lib/replace/replace.c

index 9fae44aa5cf4aa22a0fcbca4edc75cc9190adb7c..dccf5142838fdb3857d3af20734ca386e0e1d3ec 100644 (file)
@@ -518,11 +518,10 @@ long long int rep_strtoll(const char *str, char **endptr, int base)
 }
 #else
 #ifdef HAVE_BSD_STRTOLL
-#ifdef HAVE_STRTOQ
 long long int rep_strtoll(const char *str, char **endptr, int base)
 {
-       long long int nb = strtoq(str, endptr, base);
-       /* In linux EINVAL is only returned if base is not ok */
+       long long int nb = strtoll(str, endptr, base);
+       /* With glibc EINVAL is only returned if base is not ok */
        if (errno == EINVAL) {
                if (base == 0 || (base >1 && base <37)) {
                        /* Base was ok so it's because we were not
@@ -534,9 +533,6 @@ long long int rep_strtoll(const char *str, char **endptr, int base)
        }
        return nb;
 }
-#else
-#error "You need the strtoq function"
-#endif /* HAVE_STRTOQ */
 #endif /* HAVE_BSD_STRTOLL */
 #endif /* HAVE_STRTOLL */