Blame gnulib-tests/test-xstrtol.c

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