xref: /titanic_52/usr/src/lib/libbc/libc/gen/common/mblib.c (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
1 /*
2  * CDDL HEADER START
3  *
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
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1990 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * misc routines
29  */
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #if !defined(lint) && defined(SCCSIDS)
34 static  char *sccsid = "%Z%%M%	%I%	%E% SMI";
35 #endif
36 
37 #include <stdio.h>
38 #include <sys/types.h>
39 #include "codeset.h"
40 #include "mbextern.h"
41 #include <dlfcn.h>
42 
43 static void *handle = (void *)NULL;	/* initialize it with -1 */
44 
45 /*
46  * Close current library library
47  */
48 _ml_close_library()
49 {
50 	if (handle == (void *)NULL) {
51 		_code_set_info.open_flag = NULL;
52 		return;
53 	}
54 
55 	dlclose(handle);
56 	_code_set_info.open_flag = NULL;
57 	handle = (void *)NULL;
58 	return(0);
59 }
60 
61 /*
62  * Open the given library
63  */
64 void *
65 _ml_open_library()
66 {
67 	char buf[BUFSIZ];
68 
69 	if (handle != (void *)NULL) /* This library is already opened */
70 		return(handle);
71 
72 	/*
73 	 * Open the given library
74 	 */
75 	strcpy(buf, LIBRARY_PATH);
76 	strcat(buf, _code_set_info.code_name);
77 	strcat(buf, ".so");
78 #ifdef DEBUG
79 	printf ("ml_open_library: buf = '%s'\n", buf);
80 #endif
81 	handle = dlopen(buf, 1);
82 	if (handle != (void *)NULL)
83 		_code_set_info.open_flag = 1;
84 #ifdef DEBUG
85 	else
86 		printf ("_ml_open_library: dlopen failed\n");
87 #endif
88 	return(handle);
89 }
90