This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ctime.stp timezone patch


The following patch adjusts the output of ctime() for the
system timezone. It works for me. Can anyone think of a reason why this patch should not be included? Worst case, if
sys_tz isn't set for some reason, the result will be GMT
as before.


- Mike Mason


--- src/tapset/ctime.stp 2006-05-11 08:58:41.000000000 -0700 +++ src.save2/tapset/ctime.stp 2006-10-21 08:29:44.000000000 -0700 @@ -13,8 +13,6 @@ * * Note that the real C library ctime() function puts a newline ('\n') * character at the end of the string that this function does not. - * Also note that since the kernel has no concept of timezones, the - * returned time is always in GMT. * * This code was adapted from the newlib mktm_r() and asctime_r() * functions. In newlib, mktm_r.c states that it was adapted from @@ -24,6 +22,10 @@ * Changes copyright (C) 2006 Red Hat Inc. */

+%{
+#include <linux/time.h>
+%}
+
function ctime:string(epochsecs:long)
%{

@@ -38,6 +40,8 @@
#define EPOCH_YEAR      1970
#define EPOCH_WDAY      4

+extern struct timezone sys_tz;
+
#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)

    static const int mon_lengths[2][MONSPERYEAR] = {
@@ -71,7 +75,10 @@
    int tm_wday;        /* day of the week */

lcltime = THIS->epochsecs;
- +
+ /* adjust for timezone */
+ lcltime -= sys_tz.tz_minuteswest * 60;
+
days = ((long)lcltime) / SECSPERDAY;
rem = ((long)lcltime) % SECSPERDAY;
while (rem < 0)




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]