/var/lib/pcp/testsuite/src/tztest.c is in pcp-testsuite 3.8.12ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | #include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <pcp/pmapi.h>
#include <pcp/impl.h>
char * __pmTimezone(void);
int main()
{
time_t sept = (30*365.25+244)*24*3600; /* 1 Septemnber 2000 */
time_t march = (30*365.25+60)*24*3600; /* 1 March 2000 */
/* Two sets of timezone strings - one works for the first half
* of the year, another for the second. Make sure that in the case
* where we cannot reduce the timezone string and have to re-write it
* same timezone is choosen */
char *zones[][8] = {
{
"ABC-10",
"ABC-10:01:02XYZ-11:03:04,M12.5.0/3:04:05,M7.1.0/2:06:07",
"ABC-10:00:00XYZ-11:00:00,M12.5.0/3:00:00,M7.5.0/2:00:00",
"ABC-10XYZ-11,M12.5.0/3:00:00,M7.1.0/2:00:00",
"ABC-10XYZ-11,M12.5.0/3:01:02,M7.1.0/2:03:04",
"ABC-10",
":Someplace/Somewhere",
NULL
},
{
"ABC-10",
"XYZ-11:03:04ABC-10:01:02,M12.5.0/3:04:05,M7.1.0/2:06:07",
"ABC-10:00:00XYZ-11:00:00,M12.5.0/3:00:00,M7.5.0/2:00:00",
"ABC-10XYZ-11,M12.5.0/3:00:00,M7.1.0/2:00:00",
"XYZ-11ABC-10,M12.5.0/3:01:02,M7.1.0/2:03:04",
"ABC-10",
":Someplace/Somewhere",
NULL
}};
char * tz = getenv("TZ");
if (tz == NULL) {
puts("Timezone is not set, abort the test");
} else {
int i;
time_t now = time(NULL);
struct tm * today = localtime(&now);
int which = today->tm_mon / 6;
char tb[256];
char * newtz = __pmTimezone();
printf("%s -> %s\n", tz, newtz);
for (i=0; zones[which][i] != NULL; i++) {
char * tz;
struct tm *tmp;
char tstr[64];
int dst;
sprintf(tb, "TZ=%s", zones[which][i]);
putenv(tb);
tzset();
tz = getenv("TZ");
newtz = __pmTimezone();
printf("%s -> %s\n", tz, newtz);
tmp = localtime(&march);
dst = tmp->tm_isdst;
strftime(tstr, 64, "%d %B %Y %H:%M %Z", tmp);
printf("In March daylight saving is %s, and the time is %s\n",
(dst ? "on" : "off"), tstr);
tmp = localtime(&sept);
dst = tmp->tm_isdst;
strftime(tstr, 64, "%d %B %Y %H:%M %Z", tmp);
printf("In September daylight saving is %s, and the time is %s\n\n",
(dst ? "on" : "off"), tstr);
}
}
return 0;
}
|