File: dat_osd.c

package info (click to toggle)
dapl 2.0.19-1.1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 4,300 kB
  • sloc: ansic: 39,217; sh: 10,475; makefile: 529
file content (183 lines) | stat: -rw-r--r-- 5,468 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
 * Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved.
 *
 * This Software is licensed under one of the following licenses:
 *
 * 1) under the terms of the "Common Public License 1.0" a copy of which is
 *    in the file LICENSE.txt in the root directory. The license is also
 *    available from the Open Source Initiative, see
 *    http://www.opensource.org/licenses/cpl.php.
 *
 * 2) under the terms of the "The BSD License" a copy of which is in the file
 *    LICENSE2.txt in the root directory. The license is also available from
 *    the Open Source Initiative, see
 *    http://www.opensource.org/licenses/bsd-license.php.
 *
 * 3) under the terms of the "GNU General Public License (GPL) Version 2" a 
 *    copy of which is in the file LICENSE3.txt in the root directory. The 
 *    license is also available from the Open Source Initiative, see
 *    http://www.opensource.org/licenses/gpl-license.php.
 *
 * Licensee has the right to choose one of the above licenses.
 *
 * Redistributions of source code must retain the above copyright
 * notice and one of the license notices.
 *
 * Redistributions in binary form must reproduce both the above copyright
 * notice, one of the license notices in the documentation
 * and/or other materials provided with the distribution.
 */

/**********************************************************************
 *
 * MODULE: dat_osd.c
 *
 * PURPOSE: Operating System Dependent layer
 * Description:
 *	Provide OS dependent functions with a canonical DAPL
 *	interface. Designed to be portable and hide OS specific quirks
 *	of common functions.
 *
 * $Id: dat_osd.c,v 1.14 2005/04/25 17:29:41 jlentini Exp $
 **********************************************************************/

#include "dat_osd.h"


/*********************************************************************
 *                                                                   *
 * Constants                                                         *
 *                                                                   *
 *********************************************************************/

#define DAT_DBG_TYPE_ENV 	"DAT_DBG_TYPE"
#define DAT_DBG_DEST_ENV 	"DAT_DBG_DEST"


/*********************************************************************
 *                                                                   *
 * Enumerations                                                      *
 *                                                                   *
 *********************************************************************/

typedef int 			DAT_OS_DBG_DEST;

typedef enum
{
    DAT_OS_DBG_DEST_STDOUT  		= 0x1,
    DAT_OS_DBG_DEST_SYSLOG  		= 0x2,
    DAT_OS_DBG_DEST_ALL  		= 0x3
} DAT_OS_DBG_DEST_TYPE;


/*********************************************************************
 *                                                                   *
 * Global Variables                                                  *
 *                                                                   *
 *********************************************************************/

static DAT_OS_DBG_TYPE_VAL 	g_dbg_type = DAT_OS_DBG_TYPE_ERROR;
static DAT_OS_DBG_DEST 		g_dbg_dest = DAT_OS_DBG_DEST_STDOUT;


/***********************************************************************
 * Function: dat_os_dbg_init
 ***********************************************************************/

void
dat_os_dbg_init ( void )
{
    char *dbg_type;
    char *dbg_dest;

    if ( NULL != (dbg_type = dat_os_getenv (DAT_DBG_TYPE_ENV)) )
    {
	g_dbg_type = dat_os_strtol (dbg_type, NULL, 0);
    }

    if ( NULL != (dbg_dest = dat_os_getenv (DAT_DBG_DEST_ENV)) )
    {
	g_dbg_dest = dat_os_strtol (dbg_dest, NULL, 0);
    }
}


/***********************************************************************
 * Function: dat_os_dbg_print
 ***********************************************************************/

void
dat_os_dbg_print (
    DAT_OS_DBG_TYPE_VAL		type,
    const char *		fmt,
    ...)
{
    if (type & g_dbg_type)
    {
	va_list args;

	if ( DAT_OS_DBG_DEST_STDOUT & g_dbg_dest )
	{
	    va_start (args, fmt);
	    vfprintf (stdout, fmt, args);
	    fflush (stdout);
	    va_end (args);
	}

	if ( DAT_OS_DBG_DEST_SYSLOG & g_dbg_dest )
	{
	    va_start (args, fmt);
	    vsyslog (LOG_USER | LOG_DEBUG, fmt, args);
	    va_end (args);
	}
    }
}


/***********************************************************************
 * Function: dat_os_library_load
 ***********************************************************************/

DAT_RETURN
dat_os_library_load (
    const char 			*library_path,
    DAT_OS_LIBRARY_HANDLE 	*library_handle_ptr)
{
    DAT_OS_LIBRARY_HANDLE       library_handle;

    if ( NULL != (library_handle = dlopen (library_path, RTLD_NOW | RTLD_GLOBAL)) )
    {
	if ( NULL != library_handle_ptr )
	{
	    *library_handle_ptr = library_handle;
	}

	return DAT_SUCCESS;
    }
    else
    {
	dat_os_dbg_print (DAT_OS_DBG_TYPE_ERROR,
			 "DAT: library load failure: %s\n",
			 dlerror ());
	return DAT_INTERNAL_ERROR;
    }
}


/***********************************************************************
 * Function: dat_os_library_unload
 ***********************************************************************/

DAT_RETURN
dat_os_library_unload (
    const DAT_OS_LIBRARY_HANDLE library_handle)
{
    if ( 0 != dlclose (library_handle) )
    {
	return DAT_INTERNAL_ERROR;
    }
    else
    {
	return DAT_SUCCESS;
    }
}