Back to index

glibc  2.9
Defines | Functions
tst-numeric.c File Reference
#include <stdio.h>
#include <locale.h>
#include <string.h>
#include <stdlib.h>

Go to the source code of this file.

Defines

#define EXIT_SUCCESS   0
#define EXIT_FAILURE   1
#define EXIT_SETLOCALE   2
#define EXIT_SNPRINTF   3

Functions

int main (int argc, char *argv[])

Define Documentation

#define EXIT_FAILURE   1

Definition at line 38 of file tst-numeric.c.

#define EXIT_SETLOCALE   2

Definition at line 39 of file tst-numeric.c.

#define EXIT_SNPRINTF   3

Definition at line 40 of file tst-numeric.c.

#define EXIT_SUCCESS   0

Definition at line 37 of file tst-numeric.c.


Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 43 of file tst-numeric.c.

{
  char *s = malloc (201);
  double val;

  /* Make sure to read the value before setting of the locale, as
     strtod() is locale-dependent. */
  val = strtod (argv[3], NULL);

  if (setlocale (LC_ALL, argv[1]) == NULL)
    {
      fprintf (stderr, "setlocale(LC_ALL, \"%s\"): %m\n", argv[1]);
      exit (EXIT_SETLOCALE);
    }

  if (snprintf (s, 200, argv[2], val) == -1)
    {
      perror ("snprintf");
      exit (EXIT_SNPRINTF);
    }

  if (strcmp (s, argv[4]) != 0)
    {
      printf ("\
locale: \"%s\", format: \"%s\", expected: \"%s\", got: \"%s\" => %s\n",
             argv[1], argv[2], argv[4], s,
             strcmp (s, argv[4]) != 0 ? "false" : "correct");
      exit (EXIT_FAILURE);
    }

  return EXIT_SUCCESS;
}

Here is the call graph for this function: