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 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <sys/types.h>
27 #include <sys/param.h>
29 #include <sys/statvfs.h>
30 #include <sys/sysmacros.h>
42 static void *lib_hdl
= NULL
;
44 static const char PNAME_FMT
[] = "%s: ";
45 static const char ERRNO_FMT
[] = ": %s\n";
47 static const char *pname
;
51 warn(const char *format
, ...)
57 (void) fprintf(stderr
, gettext(PNAME_FMT
), pname
);
59 va_start(alist
, format
);
60 (void) vfprintf(stderr
, format
, alist
);
63 if (strchr(format
, '\n') == NULL
)
64 (void) fprintf(stderr
, gettext(ERRNO_FMT
), strerror(err
));
69 die(const char *format
, ...)
75 (void) fprintf(stderr
, gettext(PNAME_FMT
), pname
);
77 va_start(alist
, format
);
78 (void) vfprintf(stderr
, format
, alist
);
81 if (strchr(format
, '\n') == NULL
)
82 (void) fprintf(stderr
, gettext(ERRNO_FMT
), strerror(err
));
87 getpname(const char *arg0
)
89 const char *p
= strrchr(arg0
, '/');
101 valid_abspath(const char *p
)
104 warn(gettext("pathname is not an absolute path -- %s\n"), p
);
108 if (strlen(p
) > MAXPATHLEN
) {
109 warn(gettext("pathname is too long -- %s\n"), p
);
117 * Wrapper for dlopen'ing a library.
118 * The caller must call closelib() once
119 * access to the library is no longer needed.
122 openlib(const char *lib
)
124 lib_hdl
= dlopen(lib
, RTLD_LAZY
);
132 (void) dlclose(lib_hdl
);