xref: /netbsd/usr.sbin/bootp/common/tzone.c (revision bf9ec67e)
1 /*	$NetBSD: tzone.c,v 1.4 1998/03/14 04:39:55 lukem Exp $	*/
2 
3 #include <sys/cdefs.h>
4 #ifndef lint
5 __RCSID("$NetBSD: tzone.c,v 1.4 1998/03/14 04:39:55 lukem Exp $");
6 #endif
7 
8 /*
9  * tzone.c - get the timezone
10  *
11  * This is shared by bootpd and bootpef
12  */
13 
14 #include <sys/types.h>
15 
16 #ifdef	SVR4
17 /* XXX - Is this really SunOS specific? -gwr */
18 /* This is in <time.h> but only visible if (__STDC__ == 1). */
19 extern long timezone;
20 #else /* SVR4 */
21 /* BSD or SunOS */
22 # include <sys/time.h>
23 # include <syslog.h>
24 #endif /* SVR4 */
25 
26 #include "bptypes.h"
27 #include "report.h"
28 #include "tzone.h"
29 
30 /* This is what other modules use. */
31 int32 secondswest;
32 
33 /*
34  * Get our timezone offset so we can give it to clients if the
35  * configuration file doesn't specify one.
36  */
37 void
38 tzone_init()
39 {
40 #ifdef	SVR4
41 	/* XXX - Is this really SunOS specific? -gwr */
42 	secondswest = timezone;
43 #else /* SVR4 */
44 	struct timezone tzp;		/* Time zone offset for clients */
45 	struct timeval tp;			/* Time (extra baggage) */
46 	if (gettimeofday(&tp, &tzp) < 0) {
47 		secondswest = 0;		/* Assume GMT for lack of anything better */
48 		report(LOG_ERR, "gettimeofday: %s", get_errmsg());
49 	} else {
50 		secondswest = 60L * tzp.tz_minuteswest;	/* Convert to seconds */
51 	}
52 #endif /* SVR4 */
53 }
54