File: tclLoadDld.c

package info (click to toggle)
tcltrf 2.1.4-dfsg3-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 9,628 kB
  • sloc: ansic: 73,134; sh: 3,155; tcl: 1,343; makefile: 176; exp: 22
file content (95 lines) | stat: -rw-r--r-- 2,013 bytes parent folder | download | duplicates (7)
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
/* 
 * 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 "transformInt.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 "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;
}