8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / backup / dump / unctime.c
blob8c252e38c8c777c93dc87caca613b2f3b3ddc66d
1 /*
2 * Copyright (c) 1998,2001 by Sun Microsystems, Inc.
3 * All rights reserved.
4 */
6 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
7 /* All Rights Reserved */
9 /*
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>
18 #include <time.h>
19 #include <string.h>
20 #include <stdlib.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.
32 #define E_MONTH 4
33 #define E_DAY 8
34 #define E_HOUR 11
35 #define E_MINUTE 14
36 #define E_SECOND 17
37 #define E_YEAR 20
39 #ifdef __STDC__
40 static int lookup(char *);
41 static time_t emitl(struct tm *);
42 #else
43 static int lookup();
44 static time_t emitl();
45 #endif
47 time_t
48 unctime(str)
49 char *str;
51 struct tm then;
52 char dbuf[30];
54 /* Definition of ctime(3) is 24 characters + newline + NUL */
55 (void) strncpy(dbuf, str, 24);
56 dbuf[24] = '\0';
57 dbuf[E_MONTH+3] = '\0';
58 then.tm_mon = lookup(&dbuf[E_MONTH]);
59 if (then.tm_mon < 0) {
60 return (-1);
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";
73 static int
74 lookup(str)
75 char *str;
77 char *cp, *cp2;
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);
83 return (-1);
86 * Routine to convert a localtime(3) format date back into
87 * a system format date.
89 static time_t
90 emitl(dp)
91 struct tm *dp;
93 dp->tm_isdst = -1;
94 return (mktime(dp));