Import upstream version 1.29
[debian/tar] / gnu / xstrtol.c
index 558e04d8b46000952a606977bf0dd72e322362db..bd3ffeb27f82ddcb7e98e6b54dbedae61589bf35 100644 (file)
@@ -1,8 +1,6 @@
-/* -*- buffer-read-only: t -*- vi: set ro: */
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
 /* A more useful interface to strtol.
 
-   Copyright (C) 1995-1996, 1998-2001, 2003-2007, 2009-2010 Free Software
+   Copyright (C) 1995-1996, 1998-2001, 2003-2007, 2009-2015 Free Software
    Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    need stderr defined if assertion checking is enabled.  */
 #include <stdio.h>
 
-#include <assert.h>
 #include <ctype.h>
 #include <errno.h>
 #include <limits.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include "assure.h"
 #include "intprops.h"
 
+/* xstrtoll.c and xstrtoull.c, which include this file, require that
+   ULLONG_MAX, LLONG_MAX, LLONG_MIN are defined, but <limits.h> does not
+   define them on all platforms.  */
+#ifndef ULLONG_MAX
+# define ULLONG_MAX TYPE_MAXIMUM (unsigned long long)
+#endif
+#ifndef LLONG_MAX
+# define LLONG_MAX TYPE_MAXIMUM (long long int)
+#endif
+#ifndef LLONG_MIN
+# define LLONG_MIN TYPE_MINIMUM (long long int)
+#endif
+
 static strtol_error
 bkm_scale (__strtol_t *x, int scale_factor)
 {
@@ -82,10 +93,12 @@ __xstrtol (const char *s, char **ptr, int strtol_base,
   __strtol_t tmp;
   strtol_error err = LONGINT_OK;
 
-  assert (0 <= strtol_base && strtol_base <= 36);
+  assure (0 <= strtol_base && strtol_base <= 36);
 
   p = (ptr ? ptr : &t_ptr);
 
+  errno = 0;
+
   if (! TYPE_SIGNED (__strtol_t))
     {
       const char *q = s;
@@ -96,7 +109,6 @@ __xstrtol (const char *s, char **ptr, int strtol_base,
         return LONGINT_INVALID;
     }
 
-  errno = 0;
   tmp = __strtol (s, p, strtol_base);
 
   if (*p == s)
@@ -115,9 +127,9 @@ __xstrtol (const char *s, char **ptr, int strtol_base,
       err = LONGINT_OVERFLOW;
     }
 
-  /* Let valid_suffixes == NULL mean `allow any suffix'.  */
+  /* Let valid_suffixes == NULL mean "allow any suffix".  */
   /* FIXME: update all callers except the ones that allow suffixes
-     after the number, changing last parameter NULL to `""'.  */
+     after the number, changing last parameter NULL to "".  */
   if (!valid_suffixes)
     {
       *val = tmp;
@@ -138,7 +150,7 @@ __xstrtol (const char *s, char **ptr, int strtol_base,
 
       if (strchr (valid_suffixes, '0'))
         {
-          /* The ``valid suffix'' '0' is a special flag meaning that
+          /* The "valid suffix" '0' is a special flag meaning that
              an optional second suffix is allowed, which can change
              the base.  A suffix "B" (e.g. "100MB") stands for a power
              of 1000, whereas a suffix "iB" (e.g. "100MiB") stands for
@@ -171,7 +183,7 @@ __xstrtol (const char *s, char **ptr, int strtol_base,
           break;
 
         case 'c':
-          overflow = 0;
+          overflow = LONGINT_OK;
           break;
 
         case 'E': /* exa or exbi */