summaryrefslogtreecommitdiffstats
path: root/tkimg/compat/tclLoadDld.c
blob: 3b96a04e7186b21698fabcb74ef806a6e77ac38d (plain)
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
/*

 * tclLoadDld.c --

 *

 *	This procedure provides a version of dlopen() that

 *	works with the "dld_link" and "dld_get_func" library procedures

 *	for dynamic loading.  It has been tested on Linux 1.1.95 and

 *	dld-3.2.7.  This file probably isn't needed anymore, since it

 *	makes more sense to use "dl_open" etc.

 *

 * Copyright (c) 1995 Sun Microsystems, Inc.

 *

 * See the file "license.terms" for information on usage and redistribution

 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.

 *

 * SCCS: @(#) tclLoadDld.c 1.4 96/02/15 11:58:46

 */

#include "tcl.h"

#include "compat/dlfcn.h"

#include "dld.h"


/*

 *----------------------------------------------------------------------

 *

 * dlopen --

 *

 *	This function is an implementation of dlopen() using

 *	the dld library.

 *

 * Results:

 *	Returns the handle of the newly loaded library, or NULL on

 *	failure.

 *

 * Side effects:

 *	Loads the specified library into the process.

 *

 *----------------------------------------------------------------------

 */

static int returnCode = 0;

extern char *tclExecutableName;

void *dlopen(path, mode)
    const char *path;
    int mode;
{
    static int firstTime = 1;

    /*

     *  The dld package needs to know the pathname to the tcl binary.

     *  If that's not know, return an error.

     */

    returnCode = 0;
    if (firstTime) {
	if (tclExecutableName == NULL) {
	    return (void *) NULL;
	}
	returnCode = dld_init(tclExecutableName);
	if (returnCode != 0) {
	    return (void *) NULL;
	}
	firstTime = 0;
    }

    if ((path != NULL) && ((returnCode = dld_link(path)) != 0)) {
	return (void *) NULL;
    }

    return (void *) 1;
}

void *
dlsym(handle, symbol)
    void *handle;
    const char *symbol;
{
    return (void *) dld_get_func(symbol);
}

char *
dlerror()
{
    if (tclExecutableName == NULL) {
	return (char *) "don't know name of application binary file, so can't initialize dynamic loader";
    }
    return dld_strerror(returnCode);
}

int
dlclose(handle)
    void *handle;
{
    return 0;
}