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) 2002-2003, Network Appliance, Inc. All rights reserved.
27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 #pragma ident "%Z%%M% %I% %E% SMI"
37 * PURPOSE: Operating System Dependent layer
39 * Provide OS dependent functions with a canonical DAPL
40 * interface. Designed to be portable and hide OS specific quirks
41 * of common functions.
43 * $Id: dat_osd.c,v 1.8 2003/08/15 20:09:52 jlentini Exp $
55 #define DAT_DBG_TYPE_ENV "DAT_DBG_TYPE"
56 #define DAT_DBG_DEST_ENV "DAT_DBG_DEST"
65 typedef int DAT_OS_DBG_DEST
;
69 DAT_OS_DBG_DEST_STDOUT
= 0x1,
70 DAT_OS_DBG_DEST_SYSLOG
= 0x2,
71 DAT_OS_DBG_DEST_ALL
= 0x3
72 } DAT_OS_DBG_DEST_TYPE
;
81 static DAT_OS_DBG_TYPE_VAL g_dbg_type
= 0;
82 static DAT_OS_DBG_DEST g_dbg_dest
= DAT_OS_DBG_DEST_STDOUT
;
86 * Function: dat_os_dbg_init
95 if (NULL
!= (dbg_type
= dat_os_getenv(DAT_DBG_TYPE_ENV
))) {
96 g_dbg_type
= dat_os_strtol(dbg_type
, NULL
, 0);
99 if (NULL
!= (dbg_dest
= dat_os_getenv(DAT_DBG_DEST_ENV
))) {
100 g_dbg_dest
= dat_os_strtol(dbg_dest
, NULL
, 0);
106 * Function: dat_os_dbg_print
111 DAT_OS_DBG_TYPE_VAL type
,
115 if ((DAT_OS_DBG_TYPE_ERROR
== type
) || (type
& g_dbg_type
)) {
120 if (DAT_OS_DBG_DEST_STDOUT
& g_dbg_dest
) {
121 (void) vfprintf(stdout
, fmt
, args
);
122 (void) fflush(stdout
);
125 if (DAT_OS_DBG_DEST_SYSLOG
& g_dbg_dest
) {
126 vsyslog(LOG_USER
| LOG_DEBUG
, fmt
, args
);
135 * Function: dat_os_library_load
140 const char *library_path
,
141 DAT_OS_LIBRARY_HANDLE
*library_handle_ptr
)
143 DAT_OS_LIBRARY_HANDLE library_handle
;
145 if (NULL
!= (library_handle
= dlopen(library_path
, RTLD_NOW
))) {
146 if (NULL
!= library_handle_ptr
) {
147 *library_handle_ptr
= library_handle
;
150 return (DAT_SUCCESS
);
152 dat_os_dbg_print(DAT_OS_DBG_TYPE_ERROR
,
153 "DAT: library load failure: %s\n",
155 return (DAT_INTERNAL_ERROR
);
161 * Function: dat_os_library_unload
165 dat_os_library_unload(
166 const DAT_OS_LIBRARY_HANDLE library_handle
)
168 if (0 != dlclose(library_handle
)) {
169 return (DAT_INTERNAL_ERROR
);
171 return (DAT_SUCCESS
);