summaryrefslogtreecommitdiffstats
path: root/tkimg/compat/tclLoadShl.c
blob: 113744c9d36c46845cf1e28d0572d2156ca6a254 (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
/*

 * tclLoadShl.c --

 *

 *	This procedure provides a version of the TclLoadFile that works

 *	with the "shl_load" and "shl_findsym" library procedures for

 *	dynamic loading (e.g. for HP machines).

 *

 * Copyright (c) 1995-1996 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: @(#) tclLoadShl.c 1.5 96/03/15 15:01:44

 */

#include <dl.h>


/*

 * On some HP machines, dl.h defines EXTERN; remove that definition.

 */

#ifdef EXTERN

#   undef EXTERN

#endif


#include "tcl.h"

#include "compat/dlfcn.h"

#include <errno.h>


#ifndef DYNAMIC_PATH

#    define DYNAMIC_PATH 0

#endif


void *
dlopen(path, mode)
    const char *path;
    int mode;
{
    int flags, length;

    if (path == (char *) NULL) {
	return (void *) PROG_HANDLE;
    }
    flags = ((mode & RTLD_NOW) ? BIND_IMMEDIATE : BIND_DEFERRED) |
	    DYNAMIC_PATH;
#ifdef BIND_VERBOSE

    length = strlen(path);
    if ((length > 2) && !(strcmp(path+length-3,".sl"))) {
	flags |= BIND_VERBOSE;
    }
#endif

    return (void *) shl_load(path, flags, 0L);
}

void *
dlsym(handle, symbol)
    void *handle;
    const char *symbol;
{   void *address;

    if (shl_findsym((shl_t *)&handle, symbol,
	    (short) TYPE_UNDEFINED, &address) != 0) {
	address = NULL;
    }
    return address;
}

char *
dlerror()
{
    return (char *) Tcl_ErrnoMsg(errno);
}

int
dlclose(handle)
    void *handle;
{
    return shl_unload((shl_t) handle);
}