1986-01-13 17:21:20 -05:00
|
|
|
#
|
|
|
|
|
|
|
|
|
|
/*LINTLIBRARY*/
|
|
|
|
|
|
1986-02-15 15:23:29 -05:00
|
|
|
#include "tzfile.h"
|
1986-01-13 17:21:20 -05:00
|
|
|
#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;
|
|
|
|
|
|
1986-01-16 08:50:51 -05:00
|
|
|
char * tz_abbr; /* set by localtime; available to all */
|
|
|
|
|
|
1986-03-01 17:07:13 -05:00
|
|
|
static
|
|
|
|
|
tzload(tzname)
|
1986-01-16 08:50:51 -05:00
|
|
|
register char * tzname;
|
1986-01-13 17:21:20 -05:00
|
|
|
{
|
|
|
|
|
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-03-01 17:20:50 -05:00
|
|
|
register int i, j, ok;
|
1986-01-13 17:21:20 -05:00
|
|
|
char buf[256];
|
|
|
|
|
|
1986-02-28 21:29:14 -05:00
|
|
|
if (tzname == 0)
|
|
|
|
|
tzname = TZDEFAULT;
|
1986-01-13 17:21:20 -05:00
|
|
|
tzp = &tzinfo;
|
1986-01-16 08:50:51 -05:00
|
|
|
if (tzname[0] != '/') {
|
1986-01-13 20:30:59 -05:00
|
|
|
(void) strcpy(buf, TZDIR);
|
|
|
|
|
(void) strcat(buf, "/");
|
1986-01-16 08:50:51 -05:00
|
|
|
if ((strlen(buf) + strlen(tzname) + 1) > sizeof buf)
|
1986-03-01 17:07:13 -05:00
|
|
|
goto oops;
|
1986-01-16 08:50:51 -05:00
|
|
|
(void) strcat(buf, tzname);
|
|
|
|
|
tzname = buf;
|
1986-01-13 20:30:59 -05:00
|
|
|
}
|
1986-01-16 08:50:51 -05:00
|
|
|
if ((fid = open(tzname, 0)) == -1)
|
1986-03-01 17:07:13 -05:00
|
|
|
goto oops;
|
1986-01-16 08:50:51 -05:00
|
|
|
ok = read(fid, (char *) tzp, sizeof *tzp) == sizeof *tzp;
|
|
|
|
|
if (close(fid) != 0 || !ok)
|
1986-03-01 17:07:13 -05:00
|
|
|
goto oops;
|
1986-01-13 17:21:20 -05:00
|
|
|
/*
|
1986-03-01 17:20:50 -05:00
|
|
|
** Check for errors that could cause core dumps.
|
|
|
|
|
** Note: all tz_dsinfo elements are checked even if they aren't used.
|
|
|
|
|
** Note that a zero-length time zone abbreviation is *not* considered
|
|
|
|
|
** to be an error.
|
1986-01-13 17:21:20 -05:00
|
|
|
*/
|
1986-03-01 17:29:41 -05:00
|
|
|
if (tzp->tz_timecnt < 0 || tzp->tz_timecnt > TZ_MAX_TIMES)
|
|
|
|
|
goto oops;
|
1986-03-01 17:20:50 -05:00
|
|
|
for (i = 0; i < tzp->tz_timecnt; ++i)
|
|
|
|
|
if (tzp->tz_types[i] > TZ_MAX_TYPES)
|
1986-03-01 17:07:13 -05:00
|
|
|
goto oops;
|
1986-03-01 17:20:50 -05:00
|
|
|
for (i = 0; i < TZ_MAX_TYPES; ++i) {
|
1986-03-01 17:07:13 -05:00
|
|
|
dsp = tzp->tz_dsinfo + i;
|
1986-03-01 17:20:50 -05:00
|
|
|
j = 0;
|
|
|
|
|
while (dsp->ds_abbr[j] != '\0')
|
|
|
|
|
if (++j > TZ_ABBR_LEN)
|
|
|
|
|
goto oops;
|
1986-01-13 17:21:20 -05:00
|
|
|
}
|
|
|
|
|
return 0;
|
1986-03-01 17:07:13 -05:00
|
|
|
oops:
|
|
|
|
|
/*
|
|
|
|
|
** Clobber tzinfo (in case we're running set-user-id and have been
|
|
|
|
|
** used to read a protected file).
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
struct tzinfo nonsense;
|
|
|
|
|
|
|
|
|
|
*tzp = nonsense;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
1986-01-13 17:21:20 -05:00
|
|
|
}
|
|
|
|
|
|
1986-01-16 08:50:51 -05:00
|
|
|
/*
|
1986-03-01 17:07:13 -05:00
|
|
|
** settz("") Use built-in GMT.
|
|
|
|
|
** settz(0) Use TZDEFAULT.
|
|
|
|
|
** settz(otherwise) Use otherwise.
|
1986-01-16 08:50:51 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
settz(tzname)
|
|
|
|
|
char * tzname;
|
|
|
|
|
{
|
|
|
|
|
register int answer;
|
|
|
|
|
|
1986-02-28 21:29:14 -05:00
|
|
|
if (tzname != 0 && *tzname == '\0')
|
1986-01-16 08:50:51 -05:00
|
|
|
answer = 0; /* Use built-in GMT */
|
|
|
|
|
else {
|
|
|
|
|
if (tzload(tzname) == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
/*
|
1986-02-28 21:29:14 -05:00
|
|
|
** If we want to try for local time on errors. . .
|
|
|
|
|
if (tzload((char *) 0) == 0)
|
1986-01-16 08:50:51 -05:00
|
|
|
return -1;
|
1986-02-28 21:29:14 -05:00
|
|
|
*/
|
1986-01-16 08:50:51 -05:00
|
|
|
answer = -1;
|
|
|
|
|
}
|
1986-02-15 17:44:54 -05:00
|
|
|
tzinfo.tz_timecnt = 0;
|
1986-01-16 08:50:51 -05:00
|
|
|
tzinfo.tz_dsinfo[0].ds_gmtoff = 0;
|
|
|
|
|
(void) strcpy(tzinfo.tz_dsinfo[0].ds_abbr, "GMT");
|
|
|
|
|
return answer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct tm *
|
|
|
|
|
newlocaltime(timep)
|
|
|
|
|
long *timep;
|
1986-01-13 17:21:20 -05:00
|
|
|
{
|
|
|
|
|
register struct tzinfo * tzp;
|
1986-01-16 08:50:51 -05:00
|
|
|
register struct dsinfo * dsp;
|
|
|
|
|
register struct tm * ct;
|
1986-01-13 20:30:59 -05:00
|
|
|
register int i;
|
1986-01-16 08:50:51 -05:00
|
|
|
long t;
|
1986-01-13 17:21:20 -05:00
|
|
|
|
|
|
|
|
tzp = &tzinfo;
|
1986-01-16 08:50:51 -05:00
|
|
|
t = *timep;
|
1986-01-13 20:30:59 -05:00
|
|
|
if (tzp->tz_dsinfo[0].ds_abbr[0] == '\0')
|
|
|
|
|
(void) settz(getenv("TZ"));
|
1986-02-15 17:44:54 -05:00
|
|
|
if (tzp->tz_timecnt == 0 || t < tzp->tz_times[0])
|
1986-01-16 08:50:51 -05:00
|
|
|
dsp = tzp->tz_dsinfo;
|
|
|
|
|
else {
|
1986-02-15 17:44:54 -05:00
|
|
|
for (i = 0; i < tzp->tz_timecnt; ++i)
|
1986-01-16 08:50:51 -05:00
|
|
|
if (t < tzp->tz_times[i])
|
|
|
|
|
break;
|
|
|
|
|
dsp = tzp->tz_dsinfo + tzp->tz_types[i - 1];
|
|
|
|
|
}
|
|
|
|
|
t += dsp->ds_gmtoff;
|
|
|
|
|
ct = gmtime(&t);
|
1986-02-19 09:59:57 -05:00
|
|
|
ct->tm_isdst = dsp->ds_isdst;
|
1986-01-16 08:50:51 -05:00
|
|
|
tz_abbr = dsp->ds_abbr;
|
|
|
|
|
return ct;
|
1986-01-13 17:21:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
1986-01-15 08:27:06 -05:00
|
|
|
newctime(timep)
|
1986-03-01 17:07:13 -05:00
|
|
|
long * timep;
|
1986-01-13 17:21:20 -05:00
|
|
|
{
|
1986-03-01 17:07:13 -05:00
|
|
|
register char * cp;
|
|
|
|
|
register char * dp;
|
|
|
|
|
static char buf[26 + TZ_ABBR_LEN + 1];
|
1986-01-13 17:21:20 -05:00
|
|
|
|
1986-01-16 08:50:51 -05:00
|
|
|
(void) strcpy(buf, asctime(newlocaltime(timep)));
|
1986-01-15 08:27:06 -05:00
|
|
|
dp = &buf[24];
|
1986-01-13 17:21:20 -05:00
|
|
|
*dp++ = ' ';
|
1986-01-16 08:50:51 -05:00
|
|
|
cp = tz_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
|
|
|
}
|