]> granicus.if.org Git - procps-ng/commitdiff
w: make date string abbreviations nls aware
authorSami Kerola <kerolasa@iki.fi>
Sat, 3 Mar 2012 11:03:40 +0000 (12:03 +0100)
committerSami Kerola <kerolasa@iki.fi>
Sun, 4 Mar 2012 10:56:25 +0000 (11:56 +0100)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
w.c

diff --git a/w.c b/w.c
index f52b951d94b7dda8959761cad25e135936fc9731..102c603482d7ae651c596f6ec92e51da8414823c 100644 (file)
--- a/w.c
+++ b/w.c
@@ -149,14 +149,11 @@ static time_t idletime(const char *restrict const tty)
 
 static void print_logintime(time_t logt, FILE * fout)
 {
-        /* FIXME: make use of locale, remember strftime() */
-       char weekday[][4] = {
-               "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
-       };
-       char month[][4] = {
-               "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
-               "Sep", "Oct", "Nov", "Dec"
-       };
+
+       /* Abbreviated of weekday can be longer than 3 characters,
+        * see for instance hu_HU.  Using 16 is few bytes more than
+        * enough.  */
+       char time_str[16];
        time_t curt;
        struct tm *logtm, *curtm;
        int today;
@@ -167,12 +164,15 @@ static void print_logintime(time_t logt, FILE * fout)
        today = curtm->tm_yday;
        logtm = localtime(&logt);
        if (curt - logt > 12 * 60 * 60 && logtm->tm_yday != today) {
-               if (curt - logt > 6 * 24 * 60 * 60)
+               if (curt - logt > 6 * 24 * 60 * 60) {
+                       strftime(time_str, sizeof(time_str), "%b", logtm);
                        fprintf(fout, " %02d%3s%02d", logtm->tm_mday,
-                               month[logtm->tm_mon], logtm->tm_year % 100);
-               else
-                       fprintf(fout, " %3s%02d  ", weekday[logtm->tm_wday],
+                               time_str, logtm->tm_year % 100);
+               } else {
+                       strftime(time_str, sizeof(time_str), "%a", logtm);
+                       fprintf(fout, " %3s%02d  ", time_str,
                                logtm->tm_hour);
+               }
        } else {
                fprintf(fout, " %02d:%02d  ", logtm->tm_hour, logtm->tm_min);
        }