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