1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright (c) 1995 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate */ 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gate #ident "%Z%%M% %I% %E% SMI" 27*0Sstevel@tonic-gate 28*0Sstevel@tonic-gate #include <stdio.h> 29*0Sstevel@tonic-gate #include <stdlib.h> 30*0Sstevel@tonic-gate #include <time.h> 31*0Sstevel@tonic-gate #include <tzfile.h> 32*0Sstevel@tonic-gate #include <sys/time.h> 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate static int get_tzp_info(void); 35*0Sstevel@tonic-gate extern long _timezone, _altzone; /* from the base libc */ 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate /* 39*0Sstevel@tonic-gate * The second parameter to gettimeofday() did not work correctly on 40*0Sstevel@tonic-gate * 4.x, and it was documented that localtime() should be used instead. 41*0Sstevel@tonic-gate * This is an attempt to provide correctly what 4.x meant to do. There 42*0Sstevel@tonic-gate * are shortcomings, however. See notes for DST_RUM and DST_AUSTALT. 43*0Sstevel@tonic-gate */ 44*0Sstevel@tonic-gate 45*0Sstevel@tonic-gate int 46*0Sstevel@tonic-gate gettimeofday(tp, tzp) 47*0Sstevel@tonic-gate struct timeval *tp; 48*0Sstevel@tonic-gate struct timezone *tzp; 49*0Sstevel@tonic-gate { 50*0Sstevel@tonic-gate int ret = 0; 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gate if (tp != NULL) 53*0Sstevel@tonic-gate if ((ret = _gettimeofday(tp)) == -1) 54*0Sstevel@tonic-gate maperror(); 55*0Sstevel@tonic-gate 56*0Sstevel@tonic-gate /* 57*0Sstevel@tonic-gate * We should call localtime() with the current time and 58*0Sstevel@tonic-gate * set tz_minuteswest to _altzone/SECSPERMIN if tm_isdst 59*0Sstevel@tonic-gate * is set. But we want to be bug-for-bug compatible with 60*0Sstevel@tonic-gate * 4.x, which would never adjust for DST. Futher comments 61*0Sstevel@tonic-gate * are in get_tzp_info(). 62*0Sstevel@tonic-gate */ 63*0Sstevel@tonic-gate if (tzp != NULL) { 64*0Sstevel@tonic-gate _tzset(); 65*0Sstevel@tonic-gate tzp->tz_dsttime = get_tzp_info(); 66*0Sstevel@tonic-gate tzp->tz_minuteswest = _timezone/SECSPERMIN; 67*0Sstevel@tonic-gate } 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gate return(ret); 70*0Sstevel@tonic-gate } 71*0Sstevel@tonic-gate 72*0Sstevel@tonic-gate static int 73*0Sstevel@tonic-gate get_tzp_info() 74*0Sstevel@tonic-gate { 75*0Sstevel@tonic-gate char *zonename = getenv("TZ"); 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate if ((zonename == NULL) || (*zonename == '\0')) 78*0Sstevel@tonic-gate return (DST_NONE); 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate if ((strncmp(zonename, "US/", 3) == 0) || 81*0Sstevel@tonic-gate (strcmp(zonename, "PST8PDT") == 0) || 82*0Sstevel@tonic-gate (strcmp(zonename, "MST7MDT") == 0) || 83*0Sstevel@tonic-gate (strcmp(zonename, "CST6CDT") == 0) || 84*0Sstevel@tonic-gate (strcmp(zonename, "EST5EDT") == 0) || 85*0Sstevel@tonic-gate (strncmp(zonename, "America/", 8) == 0)) 86*0Sstevel@tonic-gate return (DST_USA); 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate if (strncmp(zonename, "Australia/", 10) == 0) 89*0Sstevel@tonic-gate return (DST_AUST); 90*0Sstevel@tonic-gate 91*0Sstevel@tonic-gate if (strcmp(zonename, "WET") == 0) 92*0Sstevel@tonic-gate return (DST_WET); 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate if (strcmp(zonename, "MET") == 0) 95*0Sstevel@tonic-gate return (DST_MET); 96*0Sstevel@tonic-gate 97*0Sstevel@tonic-gate if (strcmp(zonename, "EET") == 0) 98*0Sstevel@tonic-gate return (DST_EET); 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate if (strncmp(zonename, "Canada/", 7) == 0) 101*0Sstevel@tonic-gate return (DST_CAN); 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate if ((strcmp(zonename, "GB") == 0) || 104*0Sstevel@tonic-gate (strcmp(zonename, "GB-Eire") == 0)) 105*0Sstevel@tonic-gate return (DST_GB); 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate /* 108*0Sstevel@tonic-gate * what's the corresponding DST_RUM: Rumanian DST? 109*0Sstevel@tonic-gate * There was not Rumanian timezone on 4.x. 110*0Sstevel@tonic-gate */ 111*0Sstevel@tonic-gate 112*0Sstevel@tonic-gate if (strcmp(zonename, "Turkey") == 0) 113*0Sstevel@tonic-gate return (DST_TUR); 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate /* 116*0Sstevel@tonic-gate * How do we differentiate between DST_AUST and DST_AUSTALT? 117*0Sstevel@tonic-gate * It seems that all of our current Australia timezones do 118*0Sstevel@tonic-gate * not have the 1986 shift, so we never will return DST_AUSTALT. 119*0Sstevel@tonic-gate */ 120*0Sstevel@tonic-gate 121*0Sstevel@tonic-gate return (DST_NONE); 122*0Sstevel@tonic-gate } 123