diff options
author | Jim Meyering <jim@meyering.net> | 2001-01-03 09:15:22 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2001-01-03 09:15:22 +0000 |
commit | 536a6dd3ce58413d8d616310a36f864e0cf2b3b1 (patch) | |
tree | a410322edbe680b0b200571bf1517caa8f5f38ea /src | |
parent | 701cc3fe2cd33b16b56d28010b5d6a5c2bd8fab8 (diff) | |
download | coreutils-536a6dd3ce58413d8d616310a36f864e0cf2b3b1.tar.xz |
(long_time_expected_width): New function.
(print_long_format): Use it, so that we don't assume a
particular width for time stamps in an internationalized
environment.
Diffstat (limited to 'src')
-rw-r--r-- | src/ls.c | 32 |
1 files changed, 31 insertions, 1 deletions
@@ -2342,6 +2342,36 @@ print_current_files (void) break; } } + +/* Return the expected number of columns in a long-format time stamp, + or zero if it cannot be calculated. */ + +static int +long_time_expected_width (void) +{ + static int width = -1; + + if (width < 0) + { + time_t epoch = 0; + struct tm const *tm = localtime (&epoch); + char const *fmt = long_time_format[0]; + char initbuf[100]; + char *buf = initbuf; + size_t bufsize = sizeof initbuf; + size_t len; + + *buf = '\1'; + while (! (len = strftime (buf, bufsize, fmt, tm)) && *buf) + buf = alloca (bufsize *= 2); + + width = mbsnwidth (buf, len, 0); + if (width < 0) + width = 0; + } + + return width; +} static void print_long_format (const struct fileinfo *f) @@ -2482,7 +2512,7 @@ print_long_format (const struct fileinfo *f) /* The time cannot be represented as a local time; print it as a huge integer number of seconds. */ char hbuf[LONGEST_HUMAN_READABLE + 1]; - int width = full_time ? 24 : 12; + int width = long_time_expected_width (); if (when < 0) { |