Page MenuHomeFreeBSD

D4239.id10394.diff
No OneTemporary

D4239.id10394.diff

Index: bin/ls/print.c
===================================================================
--- bin/ls/print.c
+++ bin/ls/print.c
@@ -47,6 +47,7 @@
#include <fts.h>
#include <langinfo.h>
#include <libutil.h>
+#include <limits.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
@@ -105,6 +106,12 @@
} colors[C_NUMCOLORS];
#endif
+#define MAX_ABMON_WIDTH 5
+/* static list of month */
+static char abbreviated_months[12][ MAX_ABMON_WIDTH * 2 * MB_LEN_MAX ];
+static wchar_t wabbreviated_months[12][MAX_ABMON_WIDTH + 1];
+static size_t max_width_month = 0;
+
void
printscol(const DISPLAY *dp)
{
@@ -138,6 +145,28 @@
return rc;
}
+static void
+populate_abbreviated_month(void)
+{
+ int i;
+ size_t len, j;
+
+ for (i = 0; i < 12; i++) {
+ len = mbstowcs(wabbreviated_months[i], nl_langinfo(ABMON_1 + i),
+ MAX_ABMON_WIDTH);
+ for (j = len; j < MAX_ABMON_WIDTH; j++)
+ wabbreviated_months[i][j] = L' ';
+ if (max_width_month < len)
+ max_width_month = len;
+ }
+
+ for (i = 0; i < 12; i++) {
+ wabbreviated_months[i][max_width_month] = L'\0';
+ wcstombs(abbreviated_months[i], wabbreviated_months[i],
+ sizeof(abbreviated_months[i]));
+ }
+}
+
/*
* print name in current style
*/
@@ -425,6 +454,22 @@
xo_emit("{:device/%#*jx} ", (u_int)width, (uintmax_t)dev);
}
+static size_t
+ls_strftime(char *str, size_t len, const char *fmt, const struct tm *tm)
+{
+ char *posb, nfmt[BUFSIZ];
+ const char *format = fmt;
+ size_t ret;
+
+ if (max_width_month > 0 && (posb = strstr(fmt, "%b")) != NULL) {
+ snprintf(nfmt, sizeof(nfmt), "%.*s%s%s", (int)(posb - fmt),
+ fmt, abbreviated_months[tm->tm_mon], posb + 2);
+ format = nfmt;
+ }
+ ret = strftime(str, len, format, tm);
+ return (ret);
+}
+
static void
printtime(const char *field, time_t ftime)
{
@@ -439,6 +484,9 @@
if (now == 0)
now = time(NULL);
+ if (max_width_month == 0)
+ populate_abbreviated_month();
+
#define SIXMONTHS ((365 / 2) * 86400)
if (f_timeformat) /* user specified format */
format = f_timeformat;
@@ -451,7 +499,7 @@
else
/* mmm dd yyyy || dd mmm yyyy */
format = d_first ? "%e %b %Y" : "%b %e %Y";
- strftime(longstring, sizeof(longstring), format, localtime(&ftime));
+ ls_strftime(longstring, sizeof(longstring), format, localtime(&ftime));
snprintf(fmt, sizeof(fmt), "{d:%s/%%hs} ", field);
xo_attr("value", "%ld", (long) ftime);

File Metadata

Mime Type
text/plain
Expires
Fri, Sep 4, 2:43 PM (17 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38246583
Default Alt Text
D4239.id10394.diff (2 KB)

Event Timeline