plan 9 kernel history: overview | file list | diff list

1992/0611/boot/settime.c (diff list | history)

1992/0325/sys/src/9/boot/settime.c:3,81992/0611/sys/src/9/boot/settime.c:3,10 (short | long | prev | next)
1992/0318    
#include <fcall.h> 
#include "../boot/boot.h" 
 
1992/0611    
static long lusertime(char*); 
 
1992/0318    
void 
settime(int islocal) 
{ 
1992/0325/sys/src/9/boot/settime.c:25,311992/0611/sys/src/9/boot/settime.c:27,36
1992/0318    
				timeset = 1; 
			} 
			close(f); 
		} 
1992/0611    
		}else do{ 
			strcpy(dirbuf, "yymmddhhmm[ss]"); 
			outin("\ndate/time ", dirbuf, sizeof(dirbuf)); 
		}while((timeset=lusertime(dirbuf)) <= 0); 
1992/0318    
	} 
	if(timeset == 0){ 
		/* 
1992/0325/sys/src/9/boot/settime.c:52,611992/0611/sys/src/9/boot/settime.c:57,152
1992/0318    
			write(f, dirbuf, strlen(dirbuf)); 
			close(f); 
		} 
		close(f); 
	} 
 
	f = open("#c/time", OWRITE); 
	write(f, dirbuf, strlen(dirbuf)); 
1992/0611    
	if(write(f, dirbuf, strlen(dirbuf)) < 0) 
		warning("can't set #c/time"); 
1992/0318    
	close(f); 
1992/0611    
} 
 
#define SEC2MIN 60L 
#define SEC2HOUR (60L*SEC2MIN) 
#define SEC2DAY (24L*SEC2HOUR) 
 
int 
g2(char **pp) 
{ 
	int v; 
 
	v = 10*((*pp)[0]-'0') + (*pp)[1]-'0'; 
	*pp += 2; 
	return v; 
} 
 
/* 
 *  days per month plus days/year 
 */ 
static	int	dmsize[] = 
{ 
	365, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 
}; 
static	int	ldmsize[] = 
{ 
	366, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 
}; 
 
/* 
 *  return the days/month for the given year 
 */ 
static int * 
yrsize(int yr) 
{ 
	if((yr % 4) == 0) 
		return ldmsize; 
	else 
		return dmsize; 
} 
 
/* 
 *  compute seconds since Jan 1 1970 
 */ 
static long 
lusertime(char *argbuf) 
{ 
	char *buf; 
	ulong secs; 
	int i, y, m; 
	int *d2m; 
 
	buf = argbuf; 
	i = strlen(buf); 
	if(i != 10 && i != 12) 
		return -1; 
	secs = 0; 
	y = g2(&buf); 
	m = g2(&buf); 
	if(y < 70) 
		y += 2000; 
	else 
		y += 1900; 
 
	/* 
	 *  seconds per year 
	 */ 
	for(i = 1970; i < y; i++){ 
		d2m = yrsize(i); 
		secs += d2m[0] * SEC2DAY; 
	} 
 
	/* 
	 *  seconds per month 
	 */ 
	d2m = yrsize(y); 
	for(i = 1; i < m; i++) 
		secs += d2m[i] * SEC2DAY; 
 
	secs += (g2(&buf)-1) * SEC2DAY; 
	secs += g2(&buf) * SEC2HOUR; 
	secs += g2(&buf) * SEC2MIN; 
	if(*buf) 
		secs += g2(&buf); 
 
	sprint(argbuf, "%ld", secs); 
	return secs; 
1992/0318    
} 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)