about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2001-01-24 22:13:39 +0000
committerUlrich Drepper <drepper@redhat.com>2001-01-24 22:13:39 +0000
commitdc5fd90772df0a138e25e0af7d3c51ad02a3e940 (patch)
tree4806ee0799bba9278a579c6c54add879d7551bf6
parentac259c27be2057cd323eb2113d213065a4517121 (diff)
downloadglibc-dc5fd90772df0a138e25e0af7d3c51ad02a3e940.tar.gz
glibc-dc5fd90772df0a138e25e0af7d3c51ad02a3e940.tar.xz
glibc-dc5fd90772df0a138e25e0af7d3c51ad02a3e940.zip
Update.
2001-01-24  Ulrich Drepper  <drepper@redhat.com>

	* stdlib/strtod.c (str_to_mpn): Correct parsing of thousands
	separators.
	Reported by Lagardere Jean-Francois <LAGARDEREJ@thmulti.com>.

	* stdlib/tst-strtod.c (locale_test): New function.
	(main): Call locale_test.

	* include/sys/sysctl.h: New file.
-rw-r--r--ChangeLog11
-rw-r--r--stdlib/tst-strtod.c65
2 files changed, 74 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 6a2a742c70..452153ba0e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2001-01-24  Ulrich Drepper  <drepper@redhat.com>
+
+	* stdlib/strtod.c (str_to_mpn): Correct parsing of thousands
+	separators.
+	Reported by Lagardere Jean-Francois <LAGARDEREJ@thmulti.com>.
+
+	* stdlib/tst-strtod.c (locale_test): New function.
+	(main): Call locale_test.
+
 2001-01-24  Mark Kettenis  <kettenis@gnu.org>
 
 	* hurd/hurdsig.c (_hurdsig_getenv): Remove spurious innermost
@@ -10,7 +19,7 @@
 	prototype.
 	* sysdeps/unix/sysv/linux/dl-osinfo.h: Likewise.
 
-	* include/sys/sysctl.h: New.
+	* include/sys/sysctl.h: New file.
 
 2001-01-23  Andreas Jaeger  <aj@suse.de>
 
diff --git a/stdlib/tst-strtod.c b/stdlib/tst-strtod.c
index 01c454261f..1c4612fed6 100644
--- a/stdlib/tst-strtod.c
+++ b/stdlib/tst-strtod.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,96,97,98,99,2000 Free Software Foundation, Inc.
+/* Copyright (C) 1991,96,97,98,99,2000,2001 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -17,6 +17,8 @@
    Boston, MA 02111-1307, USA.  */
 
 #include <ctype.h>
+#include <locale.h>
+#include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -67,6 +69,7 @@ static const struct ltest tests[] =
 
 static void expand (char *dst, int c);
 static int long_dbl (void);
+static int locale_test (void);
 
 int
 main (int argc, char ** argv)
@@ -117,6 +120,8 @@ main (int argc, char ** argv)
 
   status |= long_dbl ();
 
+  status |= locale_test ();
+
   return status ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
@@ -157,3 +162,61 @@ long_dbl (void)
 
   return 0;
 }
+
+/* Perform a few tests in a locale with thousands separators.  */
+static int
+locale_test (void)
+{
+  static const struct
+  {
+    const char *loc;
+    const char *str;
+    double exp;
+    ptrdiff_t nread;
+  } tests[] =
+    {
+      { "de_DE.UTF-8", "1,5", 1.5, 3 },
+      { "de_DE.UTF-8", "1.5", 1.0, 1 },
+      { "de_DE.UTF-8", "1.500", 1500.0, 5 },
+      { "de_DE.UTF-8", "36.893.488.147.419.103.232", 0x1.0p65, 26 }
+    };
+#define ntests (sizeof (tests) / sizeof (tests[0]))
+  size_t n;
+  int result = 0;
+
+  puts ("\nLocale tests");
+
+  for (n = 0; n < ntests; ++n)
+    {
+      double d;
+      char *endp;
+
+      if (setlocale (LC_ALL, tests[n].loc) == NULL)
+	{
+	  printf ("cannot set locale %s\n", tests[n].loc);
+	  result = 1;
+	  continue;
+	}
+
+      /* We call __strtod_interal here instead of strtod to tests the
+	 handling of grouping.  */
+      d = __strtod_internal (tests[n].str, &endp, 1);
+      if (d != tests[n].exp)
+	{
+	  printf ("strtod(\"%s\") returns %g and not %g\n",
+		  tests[n].str, d, tests[n].exp);
+	  result = 1;
+	}
+      else if (endp - tests[n].str != tests[n].nread)
+	{
+	  printf ("strtod(\"%s\") read %td bytes and not %td\n",
+		  tests[n].str, endp - tests[n].str, tests[n].nread);
+	  result = 1;
+	}
+    }
+
+  if (result == 0)
+    puts ("all OK");
+
+  return result;
+}