4 * This procedure provides a version of the TclLoadFile that
5 * works with the "dlopen" and "dlsym" library procedures for
6 * dynamic loading. It is identical to tclLoadDl.c except that
7 * it adds a "_" character to symbol names before looking them
10 * Copyright (c) 1995 Sun Microsystems, Inc.
12 * See the file "license.terms" for information on usage and redistribution
13 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15 * SCCS: @(#) tclLoadDl2.c 1.3 96/02/15 11:58:45
22 * In some systems, like SunOS 4.1.3, the RTLD_NOW flag isn't defined
23 * and this argument to dlopen must always be 1.
31 *----------------------------------------------------------------------
35 * Dynamically loads a binary code file into memory and returns
36 * the addresses of two procedures within that file, if they
40 * A standard Tcl completion code. If an error occurs, an error
41 * message is left in interp->result. *proc1Ptr and *proc2Ptr
42 * are filled in with the addresses of the symbols given by
43 * *sym1 and *sym2, or NULL if those symbols can't be found.
46 * New code suddenly appears in memory.
48 *----------------------------------------------------------------------
52 TclLoadFile(interp, fileName, sym1, sym2, proc1Ptr, proc2Ptr)
53 Tcl_Interp *interp; /* Used for error reporting. */
54 char *fileName; /* Name of the file containing the desired
56 char *sym1, *sym2; /* Names of two procedures to look up in
57 * the file's symbol table. */
58 Tcl_PackageInitProc **proc1Ptr, **proc2Ptr;
59 /* Where to return the addresses corresponding
60 * to sym1 and sym2. */
65 handle = dlopen(fileName, RTLD_NOW);
67 Tcl_AppendResult(interp, "couldn't load file \"", fileName,
68 "\": ", dlerror(), (char *) NULL);
71 Tcl_DStringInit(&newName);
72 Tcl_DStringAppend(&newName, "_", 1);
73 Tcl_DStringAppend(&newName, sym1, -1);
74 *proc1Ptr = (Tcl_PackageInitProc *) dlsym(handle,
75 Tcl_DStringValue(&newName));
76 Tcl_DStringSetLength(&newName, 0);
77 Tcl_DStringAppend(&newName, "_", 1);
78 Tcl_DStringAppend(&newName, sym2, -1);
79 *proc2Ptr = (Tcl_PackageInitProc *) dlsym(handle,
80 Tcl_DStringValue(&newName));
81 Tcl_DStringFree(&newName);
86 *----------------------------------------------------------------------
88 * TclGuessPackageName --
90 * If the "load" command is invoked without providing a package
91 * name, this procedure is invoked to try to figure it out.
94 * Always returns 0 to indicate that we couldn't figure out a
95 * package name; generic code will then try to guess the package
96 * from the file name. A return value of 1 would have meant that
97 * we figured out the package name and put it in bufPtr.
102 *----------------------------------------------------------------------
106 TclGuessPackageName(fileName, bufPtr)
107 char *fileName; /* Name of file containing package (already
108 * translated to local form if needed). */
109 Tcl_DString *bufPtr; /* Initialized empty dstring. Append
110 * package name to this if possible. */