xref: /freebsd/libexec/bootpd/tzone.c (revision 6be3386466ab79a84b48429ae66244f21526d3df)
1 /*
2  * tzone.c - get the timezone
3  *
4  * This is shared by bootpd and bootpef
5  *
6  * $FreeBSD$
7  */
8 
9 #ifdef	SVR4
10 /* XXX - Is this really SunOS specific? -gwr */
11 /* This is in <time.h> but only visible if (__STDC__ == 1). */
12 extern long timezone;
13 #else /* SVR4 */
14 /* BSD or SunOS */
15 # include <time.h>
16 # include <syslog.h>
17 #endif /* SVR4 */
18 
19 #include "bptypes.h"
20 #include "report.h"
21 #include "tzone.h"
22 
23 /* This is what other modules use. */
24 int32 secondswest;
25 
26 /*
27  * Get our timezone offset so we can give it to clients if the
28  * configuration file doesn't specify one.
29  */
30 void
31 tzone_init()
32 {
33 #ifdef	SVR4
34 	/* XXX - Is this really SunOS specific? -gwr */
35 	secondswest = timezone;
36 #else /* SVR4 */
37 	struct tm *tm;
38 	time_t now;
39 
40 	(void)time(&now);
41 	if ((tm = localtime(&now)) == NULL) {
42 		secondswest = 0;		/* Assume GMT for lack of anything better */
43 		report(LOG_ERR, "localtime() failed");
44 	} else {
45 		secondswest = -tm->tm_gmtoff;
46 	}
47 #endif /* SVR4 */
48 }
49