8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / print / libpapi-dynamic / common / psm.c
blobaf31f24b4e492255c063c28bce884a6a4768e593
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 /* $Id: psm.c 146 2006-03-24 00:26:54Z njacobs $ */
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <stdio.h>
33 #include <unistd.h>
34 #include <errno.h>
35 #include <string.h>
36 #include <dlfcn.h>
37 #include <papi_impl.h>
39 #ifndef RTLD_GROUP
40 #define RTLD_GROUP 0
41 #endif /* RTLD_GROUP */
43 #ifndef PSM_DIR
44 #define PSM_DIR "/usr/lib/print"
45 #endif
47 papi_status_t
48 psm_open(service_t *svc, char *scheme)
50 papi_status_t result = PAPI_OK;
51 char path[BUFSIZ];
53 if ((scheme == NULL) || (strchr(scheme, '/') != NULL))
54 return (PAPI_BAD_ARGUMENT);
56 snprintf(path, sizeof (path), PSM_DIR "/psm-%s.so", scheme);
58 svc->so_handle = dlopen(path, RTLD_LAZY|RTLD_LOCAL|RTLD_GROUP);
59 if (svc->so_handle == NULL) { /* failed, set the result/message */
60 if ((access(path, F_OK) < 0) && (errno == ENOENT))
61 result = PAPI_URI_SCHEME;
62 else
63 result = PAPI_NOT_POSSIBLE;
64 #ifdef DEBUG
65 detailed_error(svc, "psm_open(%s): %s: %s", scheme, path,
66 dlerror());
67 #endif
70 return (result);
73 void
74 psm_close(void *handle)
76 dlclose(handle);
79 void *
80 psm_sym(service_t *svc, char *name)
82 char *error = "invalid input";
83 void *func = NULL;
85 if ((svc != NULL) && (svc->so_handle != NULL) && (name != NULL)) {
86 if ((func = dlsym(svc->so_handle, name)) == NULL)
87 error = dlerror();
89 #ifdef DEBUG
90 if (func == NULL)
91 detailed_error(svc, "psm_sym(%s): %s", name, error);
92 #endif
94 return (func);