summaryrefslogtreecommitdiffstats
path: root/misc-utils/cal.c
diff options
context:
space:
mode:
authorKarel Zak2010-02-11 16:29:05 +0100
committerKarel Zak2010-02-11 16:29:05 +0100
commitaebb9522b78ded9cc00475b2dfc98813a0cbf202 (patch)
tree94b89e67e56eb9981abe392d8cf3a1a3b9997225 /misc-utils/cal.c
parentcfdisk: set '[Quit]' as default menu item on first run instead of '[Bootable]'. (diff)
downloadkernel-qcow2-util-linux-aebb9522b78ded9cc00475b2dfc98813a0cbf202.tar.gz
kernel-qcow2-util-linux-aebb9522b78ded9cc00475b2dfc98813a0cbf202.tar.xz
kernel-qcow2-util-linux-aebb9522b78ded9cc00475b2dfc98813a0cbf202.zip
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 <josejx@gentoo.org> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/cal.c')
-rw-r--r--misc-utils/cal.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 5444ceafc..5eb14b557 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;
}