1986-01-13 17:21:20 -05:00
|
|
|
#
|
|
|
|
|
|
|
|
|
|
/*LINTLIBRARY*/
|
|
|
|
|
|
|
|
|
|
#include "timezone.h"
|
|
|
|
|
#include "time.h"
|
|
|
|
|
|
|
|
|
|
#ifdef OBJECTID
|
|
|
|
|
static char sccsid[] = "%W%";
|
|
|
|
|
#endif
|
|
|
|
|
|
1986-01-15 08:27:06 -05:00
|
|
|
extern char * asctime();
|
|
|
|
|
extern struct tm * gmtime();
|
|
|
|
|
extern char * strcpy();
|
|
|
|
|
extern char * strcat();
|
|
|
|
|
extern char * getenv();
|
1986-01-13 17:21:20 -05:00
|
|
|
|
|
|
|
|
static struct tzinfo tzinfo;
|
|
|
|
|
|
|
|
|
|
settz(tzname)
|
|
|
|
|
char * tzname;
|
|
|
|
|
{
|
|
|
|
|
register struct tzinfo * tzp;
|
1986-01-13 20:30:59 -05:00
|
|
|
register struct dsinfo * dsp;
|
1986-01-13 17:21:20 -05:00
|
|
|
register int fid;
|
1986-01-13 20:30:59 -05:00
|
|
|
register int i, j;
|
1986-01-13 17:21:20 -05:00
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
|
|
tzp = &tzinfo;
|
|
|
|
|
fid = -1;
|
1986-01-13 20:30:59 -05:00
|
|
|
if (tzname == 0 && tzname[0] == '\0')
|
|
|
|
|
goto gmt;
|
|
|
|
|
if (tzname[0] == '/')
|
|
|
|
|
buf[0] = '\0';
|
|
|
|
|
else {
|
|
|
|
|
(void) strcpy(buf, TZDIR);
|
|
|
|
|
(void) strcat(buf, "/");
|
|
|
|
|
}
|
1986-01-13 17:21:20 -05:00
|
|
|
if ((strlen(buf) + strlen(tzname) + 1) > sizeof buf)
|
1986-01-13 20:30:59 -05:00
|
|
|
goto gmt;
|
1986-01-13 17:21:20 -05:00
|
|
|
(void) strcat(buf, tzname);
|
|
|
|
|
/*
|
1986-01-13 20:30:59 -05:00
|
|
|
** We might be running set-user-ID, so. . .
|
1986-01-13 17:21:20 -05:00
|
|
|
*/
|
1986-01-13 21:15:41 -05:00
|
|
|
if (access(buf, 4) != 0)
|
1986-01-13 20:30:59 -05:00
|
|
|
goto gmt;
|
1986-01-13 17:21:20 -05:00
|
|
|
if ((fid = open(buf, 0)) == -1)
|
1986-01-13 20:30:59 -05:00
|
|
|
goto gmt;
|
1986-01-13 17:21:20 -05:00
|
|
|
if (read(fid, (char *) tzp, sizeof *tzp) != sizeof *tzp)
|
1986-01-13 20:30:59 -05:00
|
|
|
goto gmt;
|
1986-01-13 17:21:20 -05:00
|
|
|
if (close(fid) != 0)
|
1986-01-13 20:30:59 -05:00
|
|
|
goto gmt;
|
1986-01-13 17:21:20 -05:00
|
|
|
fid = -1;
|
|
|
|
|
/*
|
|
|
|
|
** Check the information.
|
|
|
|
|
*/
|
1986-01-13 20:30:59 -05:00
|
|
|
dsp = tzp->tz_dsinfo;
|
|
|
|
|
if (dsp->ds_abbr[0] == '\0' || dsp->ds_abbr[TZ_ABBR_LEN] != '\0')
|
|
|
|
|
goto gmt;
|
|
|
|
|
for (i = 0; i < tzp->tz_rulecnt; ++i) {
|
|
|
|
|
if (i > 0 && tzp->tz_times[i] <= tzp->tz_times[i - 1])
|
|
|
|
|
goto gmt;
|
|
|
|
|
j = tzp->tz_types[i];
|
|
|
|
|
if (j < 0 || j >= TZ_MAX_TYPES)
|
|
|
|
|
goto gmt;
|
|
|
|
|
dsp = tzp->tz_dsinfo + j;
|
|
|
|
|
if (dsp->ds_abbr[0] == '\0' ||
|
|
|
|
|
dsp->ds_abbr[TZ_ABBR_LEN] != '\0')
|
|
|
|
|
goto gmt;
|
1986-01-13 17:21:20 -05:00
|
|
|
}
|
|
|
|
|
return 0;
|
1986-01-13 20:30:59 -05:00
|
|
|
gmt:
|
1986-01-13 17:21:20 -05:00
|
|
|
(void) close(fid);
|
|
|
|
|
tzp->tz_rulecnt = 0;
|
1986-01-13 20:30:59 -05:00
|
|
|
dsp = tzp->tz_dsinfo;
|
|
|
|
|
dsp->ds_gmtoff = 0;
|
|
|
|
|
(void) strcpy(dsp->ds_abbr, "GMT");
|
1986-01-13 17:21:20 -05:00
|
|
|
return (tzname[0] == 0) ? 0 : -1;
|
|
|
|
|
}
|
|
|
|
|
|
1986-01-13 20:30:59 -05:00
|
|
|
static struct dsinfo * getdsp(t)
|
|
|
|
|
register long t;
|
1986-01-13 17:21:20 -05:00
|
|
|
{
|
|
|
|
|
register struct tzinfo * tzp;
|
1986-01-13 20:30:59 -05:00
|
|
|
register int i;
|
1986-01-13 17:21:20 -05:00
|
|
|
|
|
|
|
|
tzp = &tzinfo;
|
1986-01-13 20:30:59 -05:00
|
|
|
if (tzp->tz_dsinfo[0].ds_abbr[0] == '\0')
|
|
|
|
|
(void) settz(getenv("TZ"));
|
|
|
|
|
if (tzp->tz_rulecnt == 0 || t < tzp->tz_times[0])
|
|
|
|
|
return tzp->tz_dsinfo;
|
|
|
|
|
for (i = 0; i < tzp->tz_rulecnt; ++i)
|
|
|
|
|
if (t < tzp->tz_times[i])
|
1986-01-13 17:21:20 -05:00
|
|
|
break;
|
1986-01-13 20:30:59 -05:00
|
|
|
return tzp->tz_dsinfo + tzp->tz_types[i - 1];
|
1986-01-13 17:21:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
1986-01-15 08:27:06 -05:00
|
|
|
newctime(timep)
|
|
|
|
|
long *timep;
|
1986-01-13 17:21:20 -05:00
|
|
|
{
|
1986-01-13 20:30:59 -05:00
|
|
|
register struct dsinfo * dsp;
|
1986-01-13 17:21:20 -05:00
|
|
|
register char * cp;
|
|
|
|
|
register char * dp;
|
|
|
|
|
long copyt;
|
1986-01-15 08:27:06 -05:00
|
|
|
static char buf[26 + TZ_ABBR_LEN + 1];
|
1986-01-13 17:21:20 -05:00
|
|
|
|
1986-01-15 08:27:06 -05:00
|
|
|
dsp = getdsp(*timep);
|
|
|
|
|
copyt = *timep + dsp->ds_gmtoff;
|
|
|
|
|
(void) strcpy(buf, asctime(gmtime(©t)));
|
|
|
|
|
dp = &buf[24];
|
1986-01-13 17:21:20 -05:00
|
|
|
*dp++ = ' ';
|
1986-01-13 20:30:59 -05:00
|
|
|
cp = dsp->ds_abbr;
|
1986-01-13 17:21:20 -05:00
|
|
|
while ((*dp = *cp++) != '\0')
|
|
|
|
|
++dp;
|
|
|
|
|
*dp++ = '\n';
|
|
|
|
|
*dp++ = '\0';
|
1986-01-15 08:27:06 -05:00
|
|
|
return buf;
|
1986-01-13 17:21:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct tm *
|
1986-01-15 08:27:06 -05:00
|
|
|
newlocaltime(timep)
|
|
|
|
|
long *timep;
|
1986-01-13 17:21:20 -05:00
|
|
|
{
|
1986-01-13 20:30:59 -05:00
|
|
|
register struct dsinfo * dsp;
|
1986-01-13 17:21:20 -05:00
|
|
|
long copyt;
|
|
|
|
|
register struct tm * ct;
|
|
|
|
|
|
1986-01-15 08:27:06 -05:00
|
|
|
dsp = getdsp(*timep);
|
|
|
|
|
copyt = *timep + dsp->ds_gmtoff;
|
1986-01-13 17:21:20 -05:00
|
|
|
ct = gmtime(©t);
|
1986-01-13 20:30:59 -05:00
|
|
|
ct->tm_isdst = dsp->ds_isdst != 0;
|
1986-01-13 17:21:20 -05:00
|
|
|
return ct;
|
|
|
|
|
}
|