* Copyright (c) 1985, 1987, 1988 The Regents of the University of California.
* %sccs.include.redist.c%
"@(#) Copyright (c) 1985, 1987, 1988 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)date.c 5.2 (Berkeley) %G%";
tz
.tz_dsttime
= tz
.tz_minuteswest
= 0;
while ((ch
= getopt(argc
, argv
, "d:nut:")) != EOF
)
case 'd': /* daylight savings time */
tz
.tz_dsttime
= atoi(optarg
) ? 1 : 0;
case 'n': /* don't set network */
case 'u': /* do everything in GMT */
(void)setenv("TZ", "GMT", 1);
case 't': /* minutes west of GMT */
/* error check; don't allow "PST" */
tz
.tz_minuteswest
= atoi(optarg
);
* If -d or -t, set the timezone or daylight savings time; this
* doesn't belong here, there kernel should not know about either.
if ((tz
.tz_minuteswest
|| tz
.tz_dsttime
) &&
settimeofday((struct timeval
*)NULL
, &tz
)) {
perror("date: settimeofday");
if (time(&tval
) == (time_t)-1) {
format
= "%a %b %e %H:%M:%S %Z %Y\n";
/* allow the operands in any order */
if (*argv
&& **argv
== '+') {
if (*argv
&& **argv
== '+')
(void)strftime(buf
, sizeof(buf
), format
, localtime(&tval
));
#define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2;
for (t
= p
, dot
= 0; *t
; ++t
)
if (!isdigit(*t
) && (*t
!= '.' || dot
++))
if (t
= index(p
, '.')) { /* .ss */
if (lt
->tm_year
< 69) /* hack for 2000 ;-} */
--lt
->tm_mon
; /* time struct is 0 - 11 */
/* convert broken-down time to GMT clock time */
if ((tval
= mktime(lt
)) == -1)
if (!(p
= getlogin())) /* single-user or no tty */
syslog(LOG_AUTH
| LOG_NOTICE
, "date set by %s", p
);
if (nflag
|| netsettime(tval
)) {
logwtmp("|", "date", "");
if (settimeofday(&tv
, (struct timezone
*)NULL
)) {
perror("date: settimeofday");
logwtmp("{", "date", "");
(void)fprintf(stderr
, "date: illegal time format.\n");
"usage: date [-nu] [-d dst] [-t west] [+format] [yy[mm[dd[hh]]]]mm[.ss]]\n");