summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2001-01-03 09:15:22 +0000
committerJim Meyering <jim@meyering.net>2001-01-03 09:15:22 +0000
commit536a6dd3ce58413d8d616310a36f864e0cf2b3b1 (patch)
treea410322edbe680b0b200571bf1517caa8f5f38ea /src
parent701cc3fe2cd33b16b56d28010b5d6a5c2bd8fab8 (diff)
downloadcoreutils-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.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/ls.c b/src/ls.c
index f0b753eb0..67f75fa2b 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -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)
{