2 * Copyright (c) 1998,2001 by Sun Microsystems, Inc.
6 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
7 /* All Rights Reserved */
10 * Copyright (c) 1980 Regents of the University of California.
11 * All rights reserved. The Berkeley software License Agreement
12 * specifies the terms and conditions for redistribution.
15 #pragma ident "%Z%%M% %I% %E% SMI"
17 #include <sys/types.h>
22 * Convert a ctime(3) format string into a system format date.
23 * Return the date thus calculated.
25 * Return -1 if the string is not in ctime format.
29 * Offsets into the ctime string to various parts.
40 static int lookup(char *);
41 static time_t emitl(struct tm
*);
44 static time_t emitl();
54 /* Definition of ctime(3) is 24 characters + newline + NUL */
55 (void) strncpy(dbuf
, str
, 24);
57 dbuf
[E_MONTH
+3] = '\0';
58 then
.tm_mon
= lookup(&dbuf
[E_MONTH
]);
59 if (then
.tm_mon
< 0) {
62 then
.tm_mday
= atoi(&dbuf
[E_DAY
]);
63 then
.tm_hour
= atoi(&dbuf
[E_HOUR
]);
64 then
.tm_min
= atoi(&dbuf
[E_MINUTE
]);
65 then
.tm_sec
= atoi(&dbuf
[E_SECOND
]);
66 then
.tm_year
= atoi(&dbuf
[E_YEAR
]) - 1900;
67 return (emitl(&then
));
70 static char months
[] =
71 "JanFebMarAprMayJunJulAugSepOctNovDec";
79 for (cp
= months
, cp2
= str
; *cp
!= 0; cp
+= 3)
80 if (strncmp(cp
, cp2
, 3) == 0)
81 /* LINTED ptr arith will give < INT_MAX result */
82 return (((int)(cp
-months
)) / 3);
86 * Routine to convert a localtime(3) format date back into
87 * a system format date.