File:  [Power 6/32 Unix Tahoe 4.2BSD] / cci / usr / src / usr.bin / timezone.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Sun Jul 28 12:24:19 2019 UTC (6 years, 11 months ago) by root
Branches: bsd, MAIN
CVS tags: v12b, v121, HEAD
Power 6/32 Unix version 1.2b

#ifndef lint
static char *sccsid = "@(#)timezone.c	1.0 (Power 6 Unix) 11/30/1984";
#endif

/*
 * Date - print and set date
 */

#include <stdio.h>
#include <sys/time.h>
#include <utmp.h>
#define WTMP "/usr/adm/wtmp"


struct utmp wtmp[2] = {
	{ "|", "", "", 0 },
	{ "{", "", "", 0 }
};
struct	timeval tv;
struct	timezone tz, newtz;
/*
 * The folowing definitions and zone_table HAVE to agree with
 * what's defined in /usr/src/lib/libc/gen/timezone.c !
 */
#define	DST_NONE	0	/* not on dst */
#define	DST_USA		1	/* USA style dst */
#define	DST_AUST	2	/* Australian style dst */
#define	DST_WET		3	/* Western European dst */
#define	DST_MET		4	/* Middle European dst */
#define	DST_EET		5	/* Eastern European dst */

struct	zone_table {
	char *zone_name;
	struct timezone this_zone;
} zone_table[] =	{
	"ADT", {4*60, DST_USA},		/* Atlantic */
	"AST", {4*60, DST_NONE},	/* Atlantic */
	"CADT", {-10*60+30, DST_AUST},	/* Aust: Central */
	"CAST", {-10*60+30, DST_NONE},	/* Aust: Central */
	"CDT", {6*60, DST_USA},		/* Central */
	"CST", {6*60, DST_NONE},	/* Central */
	"EADT", {-10*60, DST_AUST},	/* Aust: Eastern */
	"EAST", {-10*60, DST_NONE},	/* Aust: Eastern */
	"EDT", {5*60, DST_USA},		/* Eastern */
	"EEDT", {-2*60, DST_EET},	/* Eastern European */
	"EEST", {-2*60, DST_NONE},	/* Eastern European */
	"EST", {5*60, DST_NONE},	/* Eastern */
	"MDT", {7*60, DST_USA}, 	/* Mountain */
	"MEDT", {-1*60, DST_MET},	/* Middle European */
	"MEST", {-1*60, DST_NONE},	/* Middle European */
	"MST", {7*60, DST_NONE},	/* Mountain */
	"PDT", {8*60, DST_USA}, 	/* Pacific */
	"PST", {8*60, DST_NONE},	/* Pacific */
	"WADT", {-8*60, DST_AUST},	/* Aust: Western */
	"WAST", {-8*60, DST_NONE},	/* Aust: Western */
	"WEDT", {0*60, DST_WET},	/* Western European */
	"WEST", {0*60, DST_NONE},	/* Western European */
	0, {0, 0},
};


main(argc, argv)
	int argc;
	char *argv[];
{
	int wf;

	if (argc != 2) {
		printf("Usage : timezone zone-name\n");
		exit(0);
	}
	if ( !identified(argv[1]) ) {
		printf("Unknown time zone name : %s\n", argv[1]);
		exit(0);
	}
	gettimeofday(&tv, &tz);
	if (settimeofday(&tv, &newtz) < 0) {
		perror("Failed to set new time zone");
	} else if ((wf = open(WTMP, 1)) >= 0) {
		time(&wtmp[1].ut_time);
		lseek(wf, 0L, 2);
		write(wf, (char *)wtmp, sizeof(wtmp));
		close(wf);
	}
}

int
identified (name)
char *name;
{
	register int i;

	for (i=0; zone_table[i].zone_name; i++) {
		if ( strcmp (name, zone_table[i].zone_name) == 0 ) {
			newtz = zone_table[i].this_zone;
			return (1);
		}
	}
	return (0);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.