]> git.draconx.ca Git - cdecl99.git/blobdiff - src/scan.l
Provide strtoumax fallback in the scanner.
[cdecl99.git] / src / scan.l
index cc152b9984609a17182c513d7b97118fe7ff34a6..1688873eea7a98744f68041bd16a858cfd82b332 100644 (file)
@@ -1,7 +1,7 @@
 %top{
 /*
  *  Scanner for C declarations.
- *  Copyright © 2011 Nick Bowler
+ *  Copyright © 2011, 2021, 2023 Nick Bowler
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
 #include "cdecl-internal.h"
 #include "cdecl.h"
 
+#if HAVE_STRTOUMAX
+/* Best case, implementation provides strtoumax. */
+#  define STRTOUMAX strtoumax
+#elif HAVE_STRTOULL
+/* Fall back to strtoull, with possibly reduced range. */
+#define STRTOUMAX strtoull
+#elif HAVE___STRTOULL
+/* HP-UX 11 has __strtoull in <inttypes.h> */
+#define STRTOUMAX __strtoull
+#else
+/* Fall back to strtoul, with possibly reduced range. */
+#define STRTOUMAX strtoul
+#endif
+
 #define lex_error(...) do { \
        cdecl__err(CDECL_ENOPARSE, __VA_ARGS__); \
        return T_LEX_ERROR; \
@@ -102,7 +116,7 @@ INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+
        char *end;
 
        errno = 0;
-       yylval->uintval = strtoumax(yytext, &end, 0);
+       yylval->uintval = STRTOUMAX(yytext, &end, 0);
        if (errno == ERANGE)
                lex_error(_("integer constant out of range"));
        if (*end)