summaryrefslogtreecommitdiff
path: root/usr.bin/time
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>2001-02-10 22:46:47 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>2001-02-10 22:46:47 +0000
commite1fc0c16f0b271ce2caf97b9ff0023ca320d934d (patch)
tree61df50bfbae8d517d00f0f966ddfe4a7e49b8ff3 /usr.bin/time
parent7142386acc3b67fd674859ca90ff78715b0ef3e6 (diff)
downloadsrc-test-e1fc0c16f0b271ce2caf97b9ff0023ca320d934d.tar.gz
src-test-e1fc0c16f0b271ce2caf97b9ff0023ca320d934d.zip
Localize it (LC_NUMERIC)
Notes
Notes: svn path=/head/; revision=72338
Diffstat (limited to 'usr.bin/time')
-rw-r--r--usr.bin/time/time.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/usr.bin/time/time.c b/usr.bin/time/time.c
index 48a40074c859f..2bf61d5bbebad 100644
--- a/usr.bin/time/time.c
+++ b/usr.bin/time/time.c
@@ -56,6 +56,7 @@ static const char rcsid[] =
#include <err.h>
#include <stdio.h>
#include <errno.h>
+#include <locale.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
@@ -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);
}