195b7b453SJohn Marino /* A more useful interface to strtol. 295b7b453SJohn Marino 3*09d4459fSDaniel Fojt Copyright (C) 1995-1996, 1998-1999, 2001-2004, 2006-2020 Free Software 495b7b453SJohn Marino Foundation, Inc. 595b7b453SJohn Marino 695b7b453SJohn Marino This program is free software: you can redistribute it and/or modify 795b7b453SJohn Marino it under the terms of the GNU General Public License as published by 895b7b453SJohn Marino the Free Software Foundation; either version 3 of the License, or 995b7b453SJohn Marino (at your option) any later version. 1095b7b453SJohn Marino 1195b7b453SJohn Marino This program is distributed in the hope that it will be useful, 1295b7b453SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 1395b7b453SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1495b7b453SJohn Marino GNU General Public License for more details. 1595b7b453SJohn Marino 1695b7b453SJohn Marino You should have received a copy of the GNU General Public License 17*09d4459fSDaniel Fojt along with this program. If not, see <https://www.gnu.org/licenses/>. */ 1895b7b453SJohn Marino 1995b7b453SJohn Marino #ifndef XSTRTOL_H_ 2095b7b453SJohn Marino # define XSTRTOL_H_ 1 2195b7b453SJohn Marino 2295b7b453SJohn Marino # include <inttypes.h> 2395b7b453SJohn Marino 2495b7b453SJohn Marino # ifndef _STRTOL_ERROR 2595b7b453SJohn Marino enum strtol_error 2695b7b453SJohn Marino { 2795b7b453SJohn Marino LONGINT_OK = 0, 2895b7b453SJohn Marino 2995b7b453SJohn Marino /* These two values can be ORed together, to indicate that both 3095b7b453SJohn Marino errors occurred. */ 3195b7b453SJohn Marino LONGINT_OVERFLOW = 1, 3295b7b453SJohn Marino LONGINT_INVALID_SUFFIX_CHAR = 2, 3395b7b453SJohn Marino 3495b7b453SJohn Marino LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW = (LONGINT_INVALID_SUFFIX_CHAR 3595b7b453SJohn Marino | LONGINT_OVERFLOW), 3695b7b453SJohn Marino LONGINT_INVALID = 4 3795b7b453SJohn Marino }; 3895b7b453SJohn Marino typedef enum strtol_error strtol_error; 3995b7b453SJohn Marino # endif 4095b7b453SJohn Marino 4195b7b453SJohn Marino # define _DECLARE_XSTRTOL(name, type) \ 4295b7b453SJohn Marino strtol_error name (const char *, char **, int, type *, const char *); 4395b7b453SJohn Marino _DECLARE_XSTRTOL (xstrtol, long int) 4495b7b453SJohn Marino _DECLARE_XSTRTOL (xstrtoul, unsigned long int) 4595b7b453SJohn Marino _DECLARE_XSTRTOL (xstrtoll, long long int) 4695b7b453SJohn Marino _DECLARE_XSTRTOL (xstrtoull, unsigned long long int) 47*09d4459fSDaniel Fojt _DECLARE_XSTRTOL (xstrtoimax, intmax_t) 48*09d4459fSDaniel Fojt _DECLARE_XSTRTOL (xstrtoumax, uintmax_t) 4995b7b453SJohn Marino 5095b7b453SJohn Marino #endif /* not XSTRTOL_H_ */ 51