Subject: bin/18475: make strpct i18n aware
To: None <gnats-bugs@gnats.netbsd.org>
From: Benedikt Meurer <bmeurer@fwdn.de>
List: netbsd-bugs
Date: 09/30/2002 16:28:34
>Number:         18475
>Category:       bin
>Synopsis:       make strpct i18n aware
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 30 07:29:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Benedikt Meurer
>Release:        NetBSD 1.6I
>Organization:
University Siegen
>Environment:
	
	
System: NetBSD endor.kosmos.all 1.6I NetBSD 1.6I (ENDOR) #0: Sun Sep 29 23:23:33 CEST 2002 benny@darkstar.kosmos.all:/usr/src/sys/arch/i386/compile/ENDOR i386
Architecture: i386
Machine: i386
>Description:
strpct hardcodes the decimal point. bad practice.
>How-To-Repeat:
>Fix:
Apply the following patch (this will also fix other programs such as
df, who use strpct.c too).
BTW: shouldn't we move strpct to libc/libutil?

Index: strpct.c
===================================================================
RCS file: /cvsroot/basesrc/bin/csh/strpct.c,v
retrieving revision 1.5
diff -u -r1.5 strpct.c
--- strpct.c	2001/09/14 14:04:01	1.5
+++ strpct.c	2002/09/30 14:18:58
@@ -49,6 +49,7 @@
 #include <sys/types.h>
 
 #include <limits.h>
+#include <locale.h>
 #include <stdio.h>
 
 char *strpct(u_long, u_long, u_int);
@@ -84,8 +85,11 @@
 	else {
 		char	fmt[32];
 
-		/* indirection to produce the right output format */
-		(void)snprintf(fmt, sizeof(fmt), "%%lu.%%0%ulu%%%%", digits);
+		/* indirection to produce the right output format.
+		 * NOTE: Hardcoding the decimal point is bad practice,
+		 * instead we use the i18n aware localeconv() way :-) */
+		(void)snprintf(fmt, sizeof(fmt), "%%lu%s%%0%ulu%%%%",
+			localeconv()->decimal_point, digits);
 
 		factor /= 100L;		/* undo initialization */
 
>Release-Note:
>Audit-Trail:
>Unformatted: