1118611Snjl/*
2118611Snjl * tzone.c - get the timezone
3118611Snjl *
4118611Snjl * This is shared by bootpd and bootpef
5118611Snjl */
6118611Snjl
7118611Snjl#ifdef	SVR4
8217365Sjkim/* XXX - Is this really SunOS specific? -gwr */
9229989Sjkim/* This is in <time.h> but only visible if (__STDC__ == 1). */
10118611Snjlextern long timezone;
11118611Snjl#else /* SVR4 */
12217365Sjkim/* BSD or SunOS */
13217365Sjkim# include <time.h>
14217365Sjkim# include <syslog.h>
15217365Sjkim#endif /* SVR4 */
16217365Sjkim
17217365Sjkim#include "bptypes.h"
18217365Sjkim#include "report.h"
19217365Sjkim#include "tzone.h"
20217365Sjkim
21217365Sjkim/* This is what other modules use. */
22217365Sjkimint32 secondswest;
23217365Sjkim
24217365Sjkim/*
25217365Sjkim * Get our timezone offset so we can give it to clients if the
26118611Snjl * configuration file doesn't specify one.
27217365Sjkim */
28217365Sjkimvoid
29217365Sjkimtzone_init()
30118611Snjl{
31217365Sjkim#ifdef	SVR4
32217365Sjkim	/* XXX - Is this really SunOS specific? -gwr */
33217365Sjkim	secondswest = timezone;
34217365Sjkim#else /* SVR4 */
35217365Sjkim	struct tm *tm;
36217365Sjkim	time_t now;
37217365Sjkim
38217365Sjkim	(void)time(&now);
39217365Sjkim	if ((tm = localtime(&now)) == NULL) {
40217365Sjkim		secondswest = 0;		/* Assume GMT for lack of anything better */
41217365Sjkim		report(LOG_ERR, "localtime() failed");
42217365Sjkim	} else {
43217365Sjkim		secondswest = -tm->tm_gmtoff;
44118611Snjl	}
45118611Snjl#endif /* SVR4 */
46118611Snjl}
47118611Snjl