Blame gnulib-tests/test-xstrtol.c

Packit 709fb3
/* Test of xstrtol module.
Packit 709fb3
   Copyright (C) 1995-1996, 1998-2001, 2003-2017 Free Software Foundation, Inc.
Packit 709fb3
Packit 709fb3
   This program is free software: you can redistribute it and/or modify
Packit 709fb3
   it under the terms of the GNU General Public License as published by
Packit 709fb3
   the Free Software Foundation; either version 3 of the License, or
Packit 709fb3
   (at your option) any later version.
Packit 709fb3
Packit 709fb3
   This program is distributed in the hope that it will be useful,
Packit 709fb3
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 709fb3
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 709fb3
   GNU General Public License for more details.
Packit 709fb3
Packit 709fb3
   You should have received a copy of the GNU General Public License
Packit 709fb3
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 709fb3
Packit 709fb3
#include <config.h>
Packit 709fb3
Packit 709fb3
#include <inttypes.h>
Packit 709fb3
#include <stdlib.h>
Packit 709fb3
#include <stdio.h>
Packit 709fb3
Packit 709fb3
#include "xstrtol.h"
Packit 709fb3
#include "error.h"
Packit 709fb3
Packit 709fb3
#ifndef __xstrtol
Packit 709fb3
# define __xstrtol xstrtol
Packit 709fb3
# define __strtol_t long int
Packit 709fb3
# define __spec "ld"
Packit 709fb3
#endif
Packit 709fb3
Packit 709fb3
/* Don't show the program name in error messages.  */
Packit 709fb3
static void
Packit 709fb3
print_no_progname (void)
Packit 709fb3
{
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
int
Packit 709fb3
main (int argc, char **argv)
Packit 709fb3
{
Packit 709fb3
  strtol_error s_err;
Packit 709fb3
  int i;
Packit 709fb3
Packit 709fb3
  error_print_progname = print_no_progname;
Packit 709fb3
Packit 709fb3
  for (i = 1; i < argc; i++)
Packit 709fb3
    {
Packit 709fb3
      char *p;
Packit 709fb3
      __strtol_t val;
Packit 709fb3
Packit 709fb3
      s_err = __xstrtol (argv[i], &p, 0, &val, "bckMw0");
Packit 709fb3
      if (s_err == LONGINT_OK)
Packit 709fb3
        {
Packit 709fb3
          printf ("%s->%" __spec " (%s)\n", argv[i], val, p);
Packit 709fb3
        }
Packit 709fb3
      else
Packit 709fb3
        {
Packit 709fb3
          xstrtol_fatal (s_err, -2, 'X', NULL, argv[i]);
Packit 709fb3
        }
Packit 709fb3
    }
Packit 709fb3
  exit (0);
Packit 709fb3
}