4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <cryptoutil.h>
34 * This function returns a fullpath based on the "dir" and "filepath" input
36 * - If the filepath specified does not start with a "/" and the directory
37 * is also given, prepend the directory to the filename.
38 * - If only dir or filepath is given, this function returns a copy of the
40 * - If the filepath is fully qualified already and the "dir" is also
41 * given, return NULL to indicate an error.
44 get_fullpath(char *dir
, char *filepath
)
46 char *fullpath
= NULL
;
51 pathlen
= strlen(filepath
);
56 if (pathlen
> 0 && dirlen
> 0) {
57 if (filepath
[0] != '/') {
58 int len
= pathlen
+ dirlen
+ 2;
59 fullpath
= (char *)malloc(len
);
61 (void) snprintf(fullpath
, len
, "%s/%s",
66 } else if (pathlen
> 0) {
67 fullpath
= (char *)strdup(filepath
);
68 } else if (dirlen
> 0) {
69 fullpath
= (char *)strdup(dir
);
76 * This function converts the input string to the value of time
78 * - If the input string is NULL, return zero second.
79 * - The input string needs to be in the form of:
80 * number-second(s), number-minute(s), number-hour(s) or
84 str2lifetime(char *ltimestr
, uint32_t *ltime
)
89 if (ltimestr
== NULL
|| !strlen(ltimestr
)) {
94 (void) memset(timetok
, 0, sizeof (timetok
));
95 if (sscanf(ltimestr
, "%d-%08s", &num
, timetok
) != 2)
98 if (!strcasecmp(timetok
, "second") ||
99 !strcasecmp(timetok
, "seconds")) {
101 } else if (!strcasecmp(timetok
, "minute") ||
102 !strcasecmp(timetok
, "minutes")) {
103 *ltime
= num
* SECSPERMIN
;
104 } else if (!strcasecmp(timetok
, "day") ||
105 !strcasecmp(timetok
, "days")) {
106 *ltime
= num
* SECSPERDAY
;
107 } else if (!strcasecmp(timetok
, "hour") ||
108 !strcasecmp(timetok
, "hours")) {
109 *ltime
= num
* SECSPERHOUR
;