This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: New test for LC_NUMERIC


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Petter Reinholdtsen wrote:

>  #define EXIT_SUCCESS 0
>  #define EXIT_FAILURE 1
>  #define EXIT_SETLOCALE 2
> -#define EXIT_STRFMON 3
> +#define EXIT_SNPRINTF 3
> 
>  int
>  main (int argc, char *argv[])
>  {
>    char *s = malloc (201);
> -  double monval;
> +  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_MONETARY, argv[1]) == NULL)
> +  if (setlocale (LC_NUMERIC, argv[1]) == NULL)
>      {
>        perror ("setlocale");
>        exit (EXIT_SETLOCALE);
>      }
> -  /* This is locale-dependent! see setlocale(3) for details */
> -  monval = strtod (argv[3], NULL);
> 
> -  if (strfmon (s, 200, argv[2], (double) atof (argv[3])) == -1)
> +  if (snprintf (s, 200, argv[2], val) == -1)
>      {
> -      perror ("strfmon");
> -      exit (EXIT_STRFMON);
> +      perror ("snprintf");
> +      exit (EXIT_SNPRINTF);

You cannot just replace the test.  The monetary and numeric information
is independent and should be tested both.  So, extend the test, don't
replace it.

- -- 
- --------------.                        ,-.            444 Castro Street
Ulrich Drepper \    ,-----------------'   \ Mountain View, CA 94041 USA
Red Hat         `--' drepper at redhat.com `---------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+nc3p2ijCOnn/RHQRAouVAKCO36mAkxvOVwe/1GTNrNSlhAE45gCfRsjp
YcbOFae7v+LSweqlaWjMjpM=
=+lWP
-----END PGP SIGNATURE-----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]