From 2d37319b21349d6f4af771a9f2525e515e7b3581 Mon Sep 17 00:00:00 2001 From: ache Date: Sat, 10 Feb 2001 22:46:47 +0000 Subject: [PATCH] Localize it (LC_NUMERIC) --- usr.bin/time/time.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/usr.bin/time/time.c b/usr.bin/time/time.c index 48a40074c859..2bf61d5bbeba 100644 --- a/usr.bin/time/time.c +++ b/usr.bin/time/time.c @@ -56,6 +56,7 @@ static const char rcsid[] = #include #include #include +#include #include #include #include @@ -64,6 +65,8 @@ static int getstathz __P((void)); static void humantime __P((FILE *, long, long)); static void usage __P((void)); +static char decimal_point; + int main(argc, argv) int argc; @@ -77,6 +80,9 @@ main(argc, argv) char *ofn = NULL; int exitonsig = 0; /* Die with same signal as child */ + (void) setlocale(LC_NUMERIC, ""); + decimal_point = localeconv()->decimal_point[0]; + aflag = hflag = lflag = pflag = 0; while ((ch = getopt(argc, argv, "ahlo:p")) != -1) switch((char)ch) { @@ -142,12 +148,15 @@ main(argc, argv) /* POSIX wants output that must look like "real %f\nuser %f\nsys %f\n" and requires at least two digits after the radix. */ - fprintf(out, "real %ld.%02ld\n", - after.tv_sec, after.tv_usec/10000); - fprintf(out, "user %ld.%02ld\n", - ru.ru_utime.tv_sec, ru.ru_utime.tv_usec/10000); - fprintf(out, "sys %ld.%02ld\n", - ru.ru_stime.tv_sec, ru.ru_stime.tv_usec/10000); + fprintf(out, "real %ld%c%02ld\n", + after.tv_sec, decimal_point, + after.tv_usec/10000); + fprintf(out, "user %ld%c%02ld\n", + ru.ru_utime.tv_sec, decimal_point, + ru.ru_utime.tv_usec/10000); + fprintf(out, "sys %ld%c%02ld\n", + ru.ru_stime.tv_sec, decimal_point, + ru.ru_stime.tv_usec/10000); } else if (hflag) { humantime(out, after.tv_sec, after.tv_usec/10000); fprintf(out, " real\t"); @@ -156,12 +165,15 @@ main(argc, argv) humantime(out, ru.ru_stime.tv_sec, ru.ru_stime.tv_usec/10000); fprintf(out, " sys\n"); } else { - fprintf(out, "%9ld.%02ld real ", - after.tv_sec, after.tv_usec/10000); - fprintf(out, "%9ld.%02ld user ", - ru.ru_utime.tv_sec, ru.ru_utime.tv_usec/10000); - fprintf(out, "%9ld.%02ld sys\n", - ru.ru_stime.tv_sec, ru.ru_stime.tv_usec/10000); + fprintf(out, "%9ld%c%02ld real ", + after.tv_sec, decimal_point, + after.tv_usec/10000); + fprintf(out, "%9ld%c%02ld user ", + ru.ru_utime.tv_sec, decimal_point, + ru.ru_utime.tv_usec/10000); + fprintf(out, "%9ld%c%02ld sys\n", + ru.ru_stime.tv_sec, decimal_point, + ru.ru_stime.tv_usec/10000); } if (lflag) { int hz = getstathz(); @@ -262,5 +274,5 @@ humantime(out, sec, usec) fprintf(out, "%ldh", hrs); if (mins) fprintf(out, "%ldm", mins); - fprintf(out, "%ld.%02lds", sec, usec); + fprintf(out, "%ld%c%02lds", sec, decimal_point, usec); }