xref: /freebsd-src/libexec/bootpd/tzone.c (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
144099b7bSPaul Traina /*
244099b7bSPaul Traina  * tzone.c - get the timezone
344099b7bSPaul Traina  *
444099b7bSPaul Traina  * This is shared by bootpd and bootpef
544099b7bSPaul Traina  */
644099b7bSPaul Traina 
744099b7bSPaul Traina #ifdef	SVR4
844099b7bSPaul Traina /* XXX - Is this really SunOS specific? -gwr */
944099b7bSPaul Traina /* This is in <time.h> but only visible if (__STDC__ == 1). */
1044099b7bSPaul Traina extern long timezone;
1144099b7bSPaul Traina #else /* SVR4 */
1244099b7bSPaul Traina /* BSD or SunOS */
13*59cc8812SDirk Froemberg # include <time.h>
1444099b7bSPaul Traina # include <syslog.h>
1544099b7bSPaul Traina #endif /* SVR4 */
1644099b7bSPaul Traina 
1744099b7bSPaul Traina #include "bptypes.h"
1844099b7bSPaul Traina #include "report.h"
1944099b7bSPaul Traina #include "tzone.h"
2044099b7bSPaul Traina 
2144099b7bSPaul Traina /* This is what other modules use. */
2244099b7bSPaul Traina int32 secondswest;
2344099b7bSPaul Traina 
2444099b7bSPaul Traina /*
2544099b7bSPaul Traina  * Get our timezone offset so we can give it to clients if the
2644099b7bSPaul Traina  * configuration file doesn't specify one.
2744099b7bSPaul Traina  */
2844099b7bSPaul Traina void
tzone_init()2944099b7bSPaul Traina tzone_init()
3044099b7bSPaul Traina {
3144099b7bSPaul Traina #ifdef	SVR4
3244099b7bSPaul Traina 	/* XXX - Is this really SunOS specific? -gwr */
3344099b7bSPaul Traina 	secondswest = timezone;
3444099b7bSPaul Traina #else /* SVR4 */
35*59cc8812SDirk Froemberg 	struct tm *tm;
36*59cc8812SDirk Froemberg 	time_t now;
37*59cc8812SDirk Froemberg 
38*59cc8812SDirk Froemberg 	(void)time(&now);
39*59cc8812SDirk Froemberg 	if ((tm = localtime(&now)) == NULL) {
4044099b7bSPaul Traina 		secondswest = 0;		/* Assume GMT for lack of anything better */
41*59cc8812SDirk Froemberg 		report(LOG_ERR, "localtime() failed");
4244099b7bSPaul Traina 	} else {
43*59cc8812SDirk Froemberg 		secondswest = -tm->tm_gmtoff;
4444099b7bSPaul Traina 	}
4544099b7bSPaul Traina #endif /* SVR4 */
4644099b7bSPaul Traina }
47