xref: /freebsd/lib/libc/iconv/citrus_module.c (revision 559a218c9b257775fb249b67945fe4a05b7a6b9f)
1ad30f8e7SGabor Kovesdan /* $NetBSD: citrus_module.c,v 1.9 2009/01/11 02:46:24 christos Exp $ */
2ad30f8e7SGabor Kovesdan 
3ad30f8e7SGabor Kovesdan /*-
4d915a14eSPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause
5d915a14eSPedro F. Giffuni  *
6ad30f8e7SGabor Kovesdan  * Copyright (c)1999, 2000, 2001, 2002 Citrus Project,
7ad30f8e7SGabor Kovesdan  * All rights reserved.
8ad30f8e7SGabor Kovesdan  *
9ad30f8e7SGabor Kovesdan  * Redistribution and use in source and binary forms, with or without
10ad30f8e7SGabor Kovesdan  * modification, are permitted provided that the following conditions
11ad30f8e7SGabor Kovesdan  * are met:
12ad30f8e7SGabor Kovesdan  * 1. Redistributions of source code must retain the above copyright
13ad30f8e7SGabor Kovesdan  *    notice, this list of conditions and the following disclaimer.
14ad30f8e7SGabor Kovesdan  * 2. Redistributions in binary form must reproduce the above copyright
15ad30f8e7SGabor Kovesdan  *    notice, this list of conditions and the following disclaimer in the
16ad30f8e7SGabor Kovesdan  *    documentation and/or other materials provided with the distribution.
17ad30f8e7SGabor Kovesdan  *
18ad30f8e7SGabor Kovesdan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19ad30f8e7SGabor Kovesdan  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20ad30f8e7SGabor Kovesdan  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ad30f8e7SGabor Kovesdan  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22ad30f8e7SGabor Kovesdan  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23ad30f8e7SGabor Kovesdan  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24ad30f8e7SGabor Kovesdan  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25ad30f8e7SGabor Kovesdan  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26ad30f8e7SGabor Kovesdan  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27ad30f8e7SGabor Kovesdan  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28ad30f8e7SGabor Kovesdan  * SUCH DAMAGE.
29ad30f8e7SGabor Kovesdan  */
30ad30f8e7SGabor Kovesdan 
31ad30f8e7SGabor Kovesdan /*-
32ad30f8e7SGabor Kovesdan  * Copyright (c) 1998 The NetBSD Foundation, Inc.
33ad30f8e7SGabor Kovesdan  * All rights reserved.
34ad30f8e7SGabor Kovesdan  *
35ad30f8e7SGabor Kovesdan  * This code is derived from software contributed to The NetBSD Foundation
36ad30f8e7SGabor Kovesdan  * by Paul Kranenburg.
37ad30f8e7SGabor Kovesdan  *
38ad30f8e7SGabor Kovesdan  * Redistribution and use in source and binary forms, with or without
39ad30f8e7SGabor Kovesdan  * modification, are permitted provided that the following conditions
40ad30f8e7SGabor Kovesdan  * are met:
41ad30f8e7SGabor Kovesdan  * 1. Redistributions of source code must retain the above copyright
42ad30f8e7SGabor Kovesdan  *    notice, this list of conditions and the following disclaimer.
43ad30f8e7SGabor Kovesdan  * 2. Redistributions in binary form must reproduce the above copyright
44ad30f8e7SGabor Kovesdan  *    notice, this list of conditions and the following disclaimer in the
45ad30f8e7SGabor Kovesdan  *    documentation and/or other materials provided with the distribution.
46ad30f8e7SGabor Kovesdan  *
47ad30f8e7SGabor Kovesdan  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
48ad30f8e7SGabor Kovesdan  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
49ad30f8e7SGabor Kovesdan  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
50ad30f8e7SGabor Kovesdan  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
51ad30f8e7SGabor Kovesdan  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
52ad30f8e7SGabor Kovesdan  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
53ad30f8e7SGabor Kovesdan  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
54ad30f8e7SGabor Kovesdan  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
55ad30f8e7SGabor Kovesdan  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
56ad30f8e7SGabor Kovesdan  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
57ad30f8e7SGabor Kovesdan  * POSSIBILITY OF SUCH DAMAGE.
58ad30f8e7SGabor Kovesdan  */
59ad30f8e7SGabor Kovesdan 
60ad30f8e7SGabor Kovesdan /*-
61ad30f8e7SGabor Kovesdan  * Copyright (c) 1993
62ad30f8e7SGabor Kovesdan  *	The Regents of the University of California.  All rights reserved.
63ad30f8e7SGabor Kovesdan  *
64ad30f8e7SGabor Kovesdan  * This code is derived from software contributed to Berkeley by
65ad30f8e7SGabor Kovesdan  * Paul Borman at Krystal Technologies.
66ad30f8e7SGabor Kovesdan  *
67ad30f8e7SGabor Kovesdan  * Redistribution and use in source and binary forms, with or without
68ad30f8e7SGabor Kovesdan  * modification, are permitted provided that the following conditions
69ad30f8e7SGabor Kovesdan  * are met:
70ad30f8e7SGabor Kovesdan  * 1. Redistributions of source code must retain the above copyright
71ad30f8e7SGabor Kovesdan  *    notice, this list of conditions and the following disclaimer.
72ad30f8e7SGabor Kovesdan  * 2. Redistributions in binary form must reproduce the above copyright
73ad30f8e7SGabor Kovesdan  *    notice, this list of conditions and the following disclaimer in the
74ad30f8e7SGabor Kovesdan  *    documentation and/or other materials provided with the distribution.
75ad30f8e7SGabor Kovesdan  * 3. Neither the name of the University nor the names of its contributors
76ad30f8e7SGabor Kovesdan  *    may be used to endorse or promote products derived from this software
77ad30f8e7SGabor Kovesdan  *    without specific prior written permission.
78ad30f8e7SGabor Kovesdan  *
79ad30f8e7SGabor Kovesdan  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
80ad30f8e7SGabor Kovesdan  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
81ad30f8e7SGabor Kovesdan  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
82ad30f8e7SGabor Kovesdan  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
83ad30f8e7SGabor Kovesdan  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
84ad30f8e7SGabor Kovesdan  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
85ad30f8e7SGabor Kovesdan  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
86ad30f8e7SGabor Kovesdan  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
87ad30f8e7SGabor Kovesdan  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
88ad30f8e7SGabor Kovesdan  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
89ad30f8e7SGabor Kovesdan  * SUCH DAMAGE.
90ad30f8e7SGabor Kovesdan  */
91ad30f8e7SGabor Kovesdan 
92ad30f8e7SGabor Kovesdan #include <sys/types.h>
93ad30f8e7SGabor Kovesdan 
94ad30f8e7SGabor Kovesdan #include <assert.h>
95ad30f8e7SGabor Kovesdan #include <dirent.h>
96ad30f8e7SGabor Kovesdan #include <dlfcn.h>
97ad30f8e7SGabor Kovesdan #include <errno.h>
98ad30f8e7SGabor Kovesdan #include <limits.h>
99ad30f8e7SGabor Kovesdan #include <paths.h>
100ad30f8e7SGabor Kovesdan #include <stdbool.h>
101ad30f8e7SGabor Kovesdan #include <stddef.h>
102ad30f8e7SGabor Kovesdan #include <stdio.h>
103ad30f8e7SGabor Kovesdan #include <stdlib.h>
104ad30f8e7SGabor Kovesdan #include <string.h>
105ad30f8e7SGabor Kovesdan #include <unistd.h>
106ad30f8e7SGabor Kovesdan 
1072300a22cSKyle Evans #define	I18NMODULE_MAJOR	5
108ad30f8e7SGabor Kovesdan 
109ad30f8e7SGabor Kovesdan #include "citrus_namespace.h"
110ad30f8e7SGabor Kovesdan #include "citrus_bcs.h"
111ad30f8e7SGabor Kovesdan #include "citrus_module.h"
1123e65b9c6SColin Percival #include "libc_private.h"
113ad30f8e7SGabor Kovesdan 
114ad30f8e7SGabor Kovesdan static int		 _getdewey(int[], char *);
115ad30f8e7SGabor Kovesdan static int		 _cmpndewey(int[], int, int[], int);
116ad30f8e7SGabor Kovesdan static const char	*_findshlib(char *, int *, int *);
117ad30f8e7SGabor Kovesdan 
118ad30f8e7SGabor Kovesdan static const char *_pathI18nModule = NULL;
119ad30f8e7SGabor Kovesdan 
120ad30f8e7SGabor Kovesdan /* from libexec/ld.aout_so/shlib.c */
121ad30f8e7SGabor Kovesdan #undef major
122ad30f8e7SGabor Kovesdan #undef minor
123ad30f8e7SGabor Kovesdan #define MAXDEWEY	3	/*ELF*/
124ad30f8e7SGabor Kovesdan 
125ad30f8e7SGabor Kovesdan static int
_getdewey(int dewey[],char * cp)126ad30f8e7SGabor Kovesdan _getdewey(int dewey[], char *cp)
127ad30f8e7SGabor Kovesdan {
128ad30f8e7SGabor Kovesdan 	int i, n;
129ad30f8e7SGabor Kovesdan 
130ad30f8e7SGabor Kovesdan 	for (n = 0, i = 0; i < MAXDEWEY; i++) {
131ad30f8e7SGabor Kovesdan 		if (*cp == '\0')
132ad30f8e7SGabor Kovesdan 			break;
133ad30f8e7SGabor Kovesdan 
134ad30f8e7SGabor Kovesdan 		if (*cp == '.') cp++;
135ad30f8e7SGabor Kovesdan 		if (*cp < '0' || '9' < *cp)
136ad30f8e7SGabor Kovesdan 			return (0);
137ad30f8e7SGabor Kovesdan 
138ad30f8e7SGabor Kovesdan 		dewey[n++] = (int)_bcs_strtol(cp, &cp, 10);
139ad30f8e7SGabor Kovesdan 	}
140ad30f8e7SGabor Kovesdan 
141ad30f8e7SGabor Kovesdan 	return (n);
142ad30f8e7SGabor Kovesdan }
143ad30f8e7SGabor Kovesdan 
144ad30f8e7SGabor Kovesdan /*
145ad30f8e7SGabor Kovesdan  * Compare two dewey arrays.
146ad30f8e7SGabor Kovesdan  * Return -1 if `d1' represents a smaller value than `d2'.
147ad30f8e7SGabor Kovesdan  * Return  1 if `d1' represents a greater value than `d2'.
148ad30f8e7SGabor Kovesdan  * Return  0 if equal.
149ad30f8e7SGabor Kovesdan  */
150ad30f8e7SGabor Kovesdan static int
_cmpndewey(int d1[],int n1,int d2[],int n2)151ad30f8e7SGabor Kovesdan _cmpndewey(int d1[], int n1, int d2[], int n2)
152ad30f8e7SGabor Kovesdan {
153ad30f8e7SGabor Kovesdan 	int i;
154ad30f8e7SGabor Kovesdan 
155ad30f8e7SGabor Kovesdan 	for (i = 0; i < n1 && i < n2; i++) {
156ad30f8e7SGabor Kovesdan 		if (d1[i] < d2[i])
157ad30f8e7SGabor Kovesdan 			return (-1);
158ad30f8e7SGabor Kovesdan 		if (d1[i] > d2[i])
159ad30f8e7SGabor Kovesdan 			return (1);
160ad30f8e7SGabor Kovesdan 	}
161ad30f8e7SGabor Kovesdan 
162ad30f8e7SGabor Kovesdan 	if (n1 == n2)
163ad30f8e7SGabor Kovesdan 		return (0);
164ad30f8e7SGabor Kovesdan 
165ad30f8e7SGabor Kovesdan 	if (i == n1)
166ad30f8e7SGabor Kovesdan 		return (-1);
167ad30f8e7SGabor Kovesdan 
168ad30f8e7SGabor Kovesdan 	if (i == n2)
169ad30f8e7SGabor Kovesdan 		return (1);
170ad30f8e7SGabor Kovesdan 
171ad30f8e7SGabor Kovesdan 	/* cannot happen */
172ad30f8e7SGabor Kovesdan 	return (0);
173ad30f8e7SGabor Kovesdan }
174ad30f8e7SGabor Kovesdan 
175ad30f8e7SGabor Kovesdan static const char *
_findshlib(char * name,int * majorp,int * minorp)176ad30f8e7SGabor Kovesdan _findshlib(char *name, int *majorp, int *minorp)
177ad30f8e7SGabor Kovesdan {
178ad30f8e7SGabor Kovesdan 	char *lname;
179ad30f8e7SGabor Kovesdan 	const char *search_dirs[1];
180ad30f8e7SGabor Kovesdan 	static char path[PATH_MAX];
181ad30f8e7SGabor Kovesdan 	int dewey[MAXDEWEY], tmp[MAXDEWEY];
182ad30f8e7SGabor Kovesdan 	int i, len, major, minor, ndewey, n_search_dirs;
183ad30f8e7SGabor Kovesdan 
184ad30f8e7SGabor Kovesdan 	n_search_dirs = 1;
185ad30f8e7SGabor Kovesdan 	major = *majorp;
186ad30f8e7SGabor Kovesdan 	minor = *minorp;
187ad30f8e7SGabor Kovesdan 	path[0] = '\0';
188ad30f8e7SGabor Kovesdan 	search_dirs[0] = _pathI18nModule;
189ad30f8e7SGabor Kovesdan 	len = strlen(name);
190ad30f8e7SGabor Kovesdan 	lname = name;
191ad30f8e7SGabor Kovesdan 
192ad30f8e7SGabor Kovesdan 	ndewey = 0;
193ad30f8e7SGabor Kovesdan 
194ad30f8e7SGabor Kovesdan 	for (i = 0; i < n_search_dirs; i++) {
195ad30f8e7SGabor Kovesdan 		struct dirent *dp;
196ad30f8e7SGabor Kovesdan 		DIR *dd = opendir(search_dirs[i]);
197ad30f8e7SGabor Kovesdan 		int found_dot_a = 0, found_dot_so = 0;
198ad30f8e7SGabor Kovesdan 
199ad30f8e7SGabor Kovesdan 		if (dd == NULL)
200ad30f8e7SGabor Kovesdan 			break;
201ad30f8e7SGabor Kovesdan 
202ad30f8e7SGabor Kovesdan 		while ((dp = readdir(dd)) != NULL) {
203ad30f8e7SGabor Kovesdan 			int n;
204ad30f8e7SGabor Kovesdan 
205ad30f8e7SGabor Kovesdan 			if (dp->d_namlen < len + 4)
206ad30f8e7SGabor Kovesdan 				continue;
207ad30f8e7SGabor Kovesdan 			if (strncmp(dp->d_name, lname, (size_t)len) != 0)
208ad30f8e7SGabor Kovesdan 				continue;
209ad30f8e7SGabor Kovesdan 			if (strncmp(dp->d_name+len, ".so.", 4) != 0)
210ad30f8e7SGabor Kovesdan 				continue;
211ad30f8e7SGabor Kovesdan 
212ad30f8e7SGabor Kovesdan 			if ((n = _getdewey(tmp, dp->d_name+len+4)) == 0)
213ad30f8e7SGabor Kovesdan 				continue;
214ad30f8e7SGabor Kovesdan 
215ad30f8e7SGabor Kovesdan 			if (major != -1 && found_dot_a)
216ad30f8e7SGabor Kovesdan 				found_dot_a = 0;
217ad30f8e7SGabor Kovesdan 
218ad30f8e7SGabor Kovesdan 			/* XXX should verify the library is a.out/ELF? */
219ad30f8e7SGabor Kovesdan 
220ad30f8e7SGabor Kovesdan 			if (major == -1 && minor == -1)
221ad30f8e7SGabor Kovesdan 				goto compare_version;
222ad30f8e7SGabor Kovesdan 			else if (major != -1 && minor == -1) {
223ad30f8e7SGabor Kovesdan 				if (tmp[0] == major)
224ad30f8e7SGabor Kovesdan 					goto compare_version;
225ad30f8e7SGabor Kovesdan 			} else if (major != -1 && minor != -1) {
226ad30f8e7SGabor Kovesdan 				if (tmp[0] == major) {
227ad30f8e7SGabor Kovesdan 					if (n == 1 || tmp[1] >= minor)
228ad30f8e7SGabor Kovesdan 						goto compare_version;
229ad30f8e7SGabor Kovesdan 				}
230ad30f8e7SGabor Kovesdan 			}
231ad30f8e7SGabor Kovesdan 
232ad30f8e7SGabor Kovesdan 			/* else, this file does not qualify */
233ad30f8e7SGabor Kovesdan 			continue;
234ad30f8e7SGabor Kovesdan 
235ad30f8e7SGabor Kovesdan 		compare_version:
236ad30f8e7SGabor Kovesdan 			if (_cmpndewey(tmp, n, dewey, ndewey) <= 0)
237ad30f8e7SGabor Kovesdan 				continue;
238ad30f8e7SGabor Kovesdan 
239ad30f8e7SGabor Kovesdan 			/* We have a better version */
240ad30f8e7SGabor Kovesdan 			found_dot_so = 1;
241ad30f8e7SGabor Kovesdan 			snprintf(path, sizeof(path), "%s/%s", search_dirs[i],
242ad30f8e7SGabor Kovesdan 			    dp->d_name);
243ad30f8e7SGabor Kovesdan 			found_dot_a = 0;
244ad30f8e7SGabor Kovesdan 			bcopy(tmp, dewey, sizeof(dewey));
245ad30f8e7SGabor Kovesdan 			ndewey = n;
246ad30f8e7SGabor Kovesdan 			*majorp = dewey[0];
247ad30f8e7SGabor Kovesdan 			*minorp = dewey[1];
248ad30f8e7SGabor Kovesdan 		}
249ad30f8e7SGabor Kovesdan 		closedir(dd);
250ad30f8e7SGabor Kovesdan 
251ad30f8e7SGabor Kovesdan 		if (found_dot_a || found_dot_so)
252ad30f8e7SGabor Kovesdan 			/*
253ad30f8e7SGabor Kovesdan 			 * There's a lib in this dir; take it.
254ad30f8e7SGabor Kovesdan 			 */
255ad30f8e7SGabor Kovesdan 			return (path[0] ? path : NULL);
256ad30f8e7SGabor Kovesdan 	}
257ad30f8e7SGabor Kovesdan 
258ad30f8e7SGabor Kovesdan 	return (path[0] ? path : NULL);
259ad30f8e7SGabor Kovesdan }
260ad30f8e7SGabor Kovesdan 
261ad30f8e7SGabor Kovesdan void *
_citrus_find_getops(_citrus_module_t handle,const char * modname,const char * ifname)262ad30f8e7SGabor Kovesdan _citrus_find_getops(_citrus_module_t handle, const char *modname,
263ad30f8e7SGabor Kovesdan     const char *ifname)
264ad30f8e7SGabor Kovesdan {
265ad30f8e7SGabor Kovesdan 	char name[PATH_MAX];
266ad30f8e7SGabor Kovesdan 	void *p;
267ad30f8e7SGabor Kovesdan 
268ad30f8e7SGabor Kovesdan 	snprintf(name, sizeof(name), "_citrus_%s_%s_getops",
269ad30f8e7SGabor Kovesdan 	    modname, ifname);
270ad30f8e7SGabor Kovesdan 	p = dlsym((void *)handle, name);
271ad30f8e7SGabor Kovesdan 	return (p);
272ad30f8e7SGabor Kovesdan }
273ad30f8e7SGabor Kovesdan 
274ad30f8e7SGabor Kovesdan int
_citrus_load_module(_citrus_module_t * rhandle,const char * encname)275ad30f8e7SGabor Kovesdan _citrus_load_module(_citrus_module_t *rhandle, const char *encname)
276ad30f8e7SGabor Kovesdan {
277ad30f8e7SGabor Kovesdan 	const char *p;
278ad30f8e7SGabor Kovesdan 	char path[PATH_MAX];
279ad30f8e7SGabor Kovesdan 	void *handle;
280ad30f8e7SGabor Kovesdan 	int maj, min;
281ad30f8e7SGabor Kovesdan 
282ad30f8e7SGabor Kovesdan 	if (_pathI18nModule == NULL) {
283*68ca8363SMark Johnston 		p = secure_getenv("PATH_I18NMODULE");
284*68ca8363SMark Johnston 		if (p != NULL) {
285ad30f8e7SGabor Kovesdan 			_pathI18nModule = strdup(p);
286ad30f8e7SGabor Kovesdan 			if (_pathI18nModule == NULL)
287ad30f8e7SGabor Kovesdan 				return (ENOMEM);
288ad30f8e7SGabor Kovesdan 		} else
289ad30f8e7SGabor Kovesdan 			_pathI18nModule = _PATH_I18NMODULE;
290ad30f8e7SGabor Kovesdan 	}
291ad30f8e7SGabor Kovesdan 
292ad30f8e7SGabor Kovesdan 	(void)snprintf(path, sizeof(path), "lib%s", encname);
293ad30f8e7SGabor Kovesdan 	maj = I18NMODULE_MAJOR;
294ad30f8e7SGabor Kovesdan 	min = -1;
295ad30f8e7SGabor Kovesdan 	p = _findshlib(path, &maj, &min);
296ad30f8e7SGabor Kovesdan 	if (!p)
297ad30f8e7SGabor Kovesdan 		return (EINVAL);
2983e65b9c6SColin Percival 	handle = libc_dlopen(p, RTLD_LAZY);
299ad30f8e7SGabor Kovesdan 	if (!handle) {
300ad30f8e7SGabor Kovesdan 		printf("%s", dlerror());
301ad30f8e7SGabor Kovesdan 		return (EINVAL);
302ad30f8e7SGabor Kovesdan 	}
303ad30f8e7SGabor Kovesdan 
304ad30f8e7SGabor Kovesdan 	*rhandle = (_citrus_module_t)handle;
305ad30f8e7SGabor Kovesdan 
306ad30f8e7SGabor Kovesdan 	return (0);
307ad30f8e7SGabor Kovesdan }
308ad30f8e7SGabor Kovesdan 
309ad30f8e7SGabor Kovesdan void
_citrus_unload_module(_citrus_module_t handle)310ad30f8e7SGabor Kovesdan _citrus_unload_module(_citrus_module_t handle)
311ad30f8e7SGabor Kovesdan {
312ad30f8e7SGabor Kovesdan 
313ad30f8e7SGabor Kovesdan 	if (handle)
314ad30f8e7SGabor Kovesdan 		dlclose((void *)handle);
315ad30f8e7SGabor Kovesdan }
316