4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1998 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/param.h>
39 static const char PNAME_FMT
[] = "%s: ";
40 static const char ERRNO_FMT
[] = ": %s\n";
42 static const char *pname
;
46 warn(const char *format
, ...)
52 (void) fprintf(stderr
, gettext(PNAME_FMT
), pname
);
54 va_start(alist
, format
);
55 (void) vfprintf(stderr
, format
, alist
);
58 if (strchr(format
, '\n') == NULL
)
59 (void) fprintf(stderr
, gettext(ERRNO_FMT
), strerror(err
));
64 die(const char *format
, ...)
70 (void) fprintf(stderr
, gettext(PNAME_FMT
), pname
);
72 va_start(alist
, format
);
73 (void) vfprintf(stderr
, format
, alist
);
76 if (strchr(format
, '\n') == NULL
)
77 (void) fprintf(stderr
, gettext(ERRNO_FMT
), strerror(err
));
83 getpname(const char *arg0
)
85 const char *p
= strrchr(arg0
, '/');
97 valid_abspath(const char *p
)
100 warn(gettext("pathname is not an absolute path -- %s\n"), p
);
104 if (strlen(p
) > MAXPATHLEN
) {
105 warn(gettext("pathname is too long -- %s\n"), p
);
113 valid_str2int(const char *p
, int *ip
)
119 i
= (int)strtol(p
, &q
, 10);
121 if (errno
!= 0 || q
== p
|| i
< 0 || (*q
!= '\0' && *q
!= '\n'))
129 valid_str2ull(const char *p
, unsigned long long *ullp
)
135 ll
= strtoll(p
, &q
, 10);
137 if (errno
!= 0 || q
== p
|| ll
< 0LL || (*q
!= '\0' && *q
!= '\n'))
140 *ullp
= (unsigned long long)ll
;