1 marek 1.1 //%LICENSE////////////////////////////////////////////////////////////////
2 //
3 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 marek 1.1 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //////////////////////////////////////////////////////////////////////////
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #ifndef TimeZone_zOS_h
33 #define TimeZone_zOS_h
34
35 #include <env.h>
36 #include <time.h>
37
38 PEGASUS_NAMESPACE_BEGIN
39
40 /* Defines */
41 #define MICRO_PER_SEC (1000*1000)
42 #define STCK_SHIFT 12
43 marek 1.1 #define STCK_MASK 0x000FFFFFFFFFFFFFull
44
45 /**
46 Get the GMT offset (including daylight saving time)
47 */
48
49 int getUtcOffset_zOS( void )
50 {
51 int utcOffset = 0;
52 char *pC;
53 Sint64 cvtldto;
54
55 pC = (char*) *((int*)(0x10)); // Address(CVT)
56 pC = (char*) *((int*)(pC+0x148)); // Address(CVTEXT2)
57 pC = pC + 0x38; // Address(CVTLDTO)
58 cvtldto = *((Uint64 *) pC); // CVTLDTO
59 cvtldto >>= STCK_SHIFT; // Now its in microseconds
60 cvtldto = cvtldto / MICRO_PER_SEC; // Now it is in seconds
61 utcOffset = cvtldto;
62 return utcOffset;
63 };
64 marek 1.1
65 /**
66 Initialize the timezone information (TZ)
67
68 When environment variable TZ is not set, the UTC offset is
69 determined from the CVTLDTO control block and the value for
70 TZ is set accordingly.
71 Calls tzset() to initialize timezone information.
72
73 */
74 void initialize_zOS_timezone()
75 {
76 // Check if the TZ environment variable is already set,
77 // indicating which timezone information we should use.
78 const char* tzValue = getenv("TZ");
79 if (!tzValue)
80 {
81 int utcOffset = getUtcOffset_zOS();
82
83 char sign = (utcOffset>0) ? '-' : '+';
84 utcOffset = abs(utcOffset);
85 marek 1.1 int hours = utcOffset / 3600;
86 utcOffset = utcOffset - (hours*3600);
87 int minutes = utcOffset / 60;
88 int seconds = utcOffset - (minutes*60);
89
90 char newTzValue[20]; // e.g "GMT+02:00:00"
91 sprintf(newTzValue,
92 "GMT%c%02d:%02d:%02d",
93 sign, hours, minutes, seconds);
94
95 setenv("TZ", newTzValue, 1);
96 }
97 // To activate the value of TZ for all threads, we need to call
98 // tzset() once in the applications main thread.
99 tzset();
100 }
101
102 PEGASUS_NAMESPACE_END
103
104 #endif
105
106 marek 1.1
|