Module Name: src
Committed By: bouyer
Date: Wed Mar 14 18:37:00 UTC 2018
Modified Files:
src/lib/libc/stdio [netbsd-8]: vfwprintf.c
src/tests/lib/libc/locale [netbsd-8]: t_sprintf.c
Log Message:
Pull up following revision(s) (requested by martin in ticket #630):
lib/libc/stdio/vfwprintf.c: revision 1.35
lib/libc/stdio/vfwprintf.c: revision 1.36
tests/lib/libc/locale/t_sprintf.c: revision 1.2
Change t_sprintf to an expected failure, since we don't respect the empty
thousands separator of the C/POSIX locale (PR standards/52282).
Do not use thousands grouping when none is specified by the locale.
Fixes PR standards/52282.
A more correct fix for PR standards/52282.
To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.34.18.1 src/lib/libc/stdio/vfwprintf.c
cvs rdiff -u -r1.1 -r1.1.2.1 src/tests/lib/libc/locale/t_sprintf.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/stdio/vfwprintf.c
diff -u src/lib/libc/stdio/vfwprintf.c:1.34 src/lib/libc/stdio/vfwprintf.c:1.34.18.1
--- src/lib/libc/stdio/vfwprintf.c:1.34 Mon Jan 20 14:11:03 2014
+++ src/lib/libc/stdio/vfwprintf.c Wed Mar 14 18:37:00 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: vfwprintf.c,v 1.34 2014/01/20 14:11:03 yamt Exp $ */
+/* $NetBSD: vfwprintf.c,v 1.34.18.1 2018/03/14 18:37:00 bouyer Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -38,7 +38,7 @@
static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93";
__FBSDID("$FreeBSD: src/lib/libc/stdio/vfwprintf.c,v 1.27 2007/01/09 00:28:08 imp Exp $");
#else
-__RCSID("$NetBSD: vfwprintf.c,v 1.34 2014/01/20 14:11:03 yamt Exp $");
+__RCSID("$NetBSD: vfwprintf.c,v 1.34.18.1 2018/03/14 18:37:00 bouyer Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -923,15 +923,15 @@ reswitch: switch (ch) {
sign = '+';
goto rflag;
case '\'':
- flags |= GROUPING;
thousands_sep = *(localeconv_l(loc)->thousands_sep);
grouping = localeconv_l(loc)->grouping;
- /* If the locale doesn't define the above, use sane
- * defaults - otherwise silly things happen! */
- if (thousands_sep == 0)
- thousands_sep = ',';
- if (!grouping || !*grouping)
- grouping = "\3";
+ /* Use grouping if defined by locale */
+ if (thousands_sep && grouping && *grouping)
+ flags |= GROUPING;
+ else {
+ thousands_sep = '\0';
+ grouping = NULL;
+ }
goto rflag;
case '.':
if ((ch = *fmt++) == '*') {
Index: src/tests/lib/libc/locale/t_sprintf.c
diff -u src/tests/lib/libc/locale/t_sprintf.c:1.1 src/tests/lib/libc/locale/t_sprintf.c:1.1.2.1
--- src/tests/lib/libc/locale/t_sprintf.c:1.1 Tue May 30 23:44:02 2017
+++ src/tests/lib/libc/locale/t_sprintf.c Wed Mar 14 18:37:00 2018
@@ -1,11 +1,11 @@
-/* $NetBSD: t_sprintf.c,v 1.1 2017/05/30 23:44:02 perseant Exp $ */
+/* $NetBSD: t_sprintf.c,v 1.1.2.1 2018/03/14 18:37:00 bouyer Exp $ */
/*-
* Copyright (c) 2017 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
- * by Konrad Schroder
+ * by Konrad Schroder.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,7 +32,7 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2017\
The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_sprintf.c,v 1.1 2017/05/30 23:44:02 perseant Exp $");
+__RCSID("$NetBSD: t_sprintf.c,v 1.1.2.1 2018/03/14 18:37:00 bouyer Exp $");
#include <locale.h>
#include <stdio.h>
@@ -53,14 +53,6 @@ static struct test {
const char *double_input;
} tests[] = {
{
- "C",
- -12345,
- "-12,345",
- "-12345",
- -12345.6789,
- "-12,345.678900",
- "-12345.678900",
- }, {
"en_US.UTF-8",
-12345,
"-12,345",
@@ -77,6 +69,30 @@ static struct test {
"-12\240345,678900",
"-12345,678900",
}, {
+ "it_IT.ISO8859-1",
+ -12345,
+ "-12.345",
+ "-12345",
+ -12345.6789,
+ "-12.345,678900",
+ "-12345,678900",
+ }, {
+ "POSIX",
+ /*
+ * POSIX-1.2008 specifies that the C and POSIX
+ * locales shall be identical (section 7.2) and
+ * that the POSIX locale shall have an empty
+ * thousands separator and "<period>" as its
+ * decimal point (section 7.3.4). *printf
+ * ought to honor these settings.
+ */
+ -12345,
+ "-12345",
+ "-12345",
+ -12345.6789,
+ "-12345.678900",
+ "-12345.678900",
+ }, {
NULL,
0,
NULL,
@@ -95,12 +111,18 @@ h_sprintf(const struct test *t)
ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C");
printf("Trying locale %s...\n", t->locale);
ATF_REQUIRE(setlocale(LC_NUMERIC, t->locale) != NULL);
+ printf("Using locale: %s\n", setlocale(LC_ALL, NULL));
+
+ if (!strcmp("POSIX", t->locale))
+ atf_tc_expect_fail("%s", "PR standards/52282, printf doesn't respect empty thousands separator");
sprintf(buf, "%'f", t->double_value);
ATF_REQUIRE_STREQ(buf, t->double_result);
sprintf(buf, "%'d", t->int_value);
ATF_REQUIRE_STREQ(buf, t->int_result);
+
+ atf_tc_expect_pass();
}
static void