From: Karel Zak Date: Thu, 11 Feb 2010 15:29:05 +0000 (+0100) Subject: cal: fix first day of the week calculation on BE systems X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3e3134eb7a252706f1efe53f6f8b5e4309a79e2;p=util-linux cal: fix first day of the week calculation on BE systems This reverts commit dcb54fafb128ab41772ae217afc6a7612e2cc446, "cal: remove gcc-ism from nl_langinfo() call". The code: int wfd = (int)(intptr_t) nl_langinfo(_NL_TIME_WEEK_1STDAY); does not work on big-endian machines. The original solution based on union is better. Note that the "type punning" is not gcc-ism any more, it's allowed by C99 (6.5.2.3). Reported-by: Joseph Jezak Signed-off-by: Karel Zak --- diff --git a/misc-utils/cal.c b/misc-utils/cal.c index 5444ceaf..5eb14b55 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -312,7 +312,11 @@ main(int argc, char **argv) { POSIX: 19971201 + 7 -1 = 0 */ { - int wfd = (int)(intptr_t) nl_langinfo(_NL_TIME_WEEK_1STDAY); + int wfd; + union { unsigned int word; char *string; } val; + val.string = nl_langinfo(_NL_TIME_WEEK_1STDAY); + + wfd = val.word; wfd = day_in_week(wfd % 100, (wfd / 100) % 100, wfd / (100 * 100)); weekstart = (wfd + *nl_langinfo(_NL_TIME_FIRST_WEEKDAY) - 1) % 7; }