/*1* tclLoadDl.c --2*3* This procedure provides a version of the TclLoadFile that4* works with the "dlopen" and "dlsym" library procedures for5* dynamic loading.6*7* Copyright (c) 1995 Sun Microsystems, Inc.8*9* See the file "license.terms" for information on usage and redistribution10* of this file, and for a DISCLAIMER OF ALL WARRANTIES.11*12* SCCS: @(#) tclLoadDl.c 1.7 96/03/14 09:03:3313*/1415#include "tclInt.h"16#ifdef NO_DLFCN_H17# include "../compat/dlfcn.h"18#else19# include <dlfcn.h>20#endif2122/*23* In some systems, like SunOS 4.1.3, the RTLD_NOW flag isn't defined24* and this argument to dlopen must always be 1. The RTLD_GLOBAL25* flag is needed on some systems (e.g. SCO and UnixWare) but doesn't26* exist on others; if it doesn't exist, set it to 0 so it has no effect.27*/2829#ifndef RTLD_NOW30# define RTLD_NOW 131#endif3233#ifndef RTLD_GLOBAL34# define RTLD_GLOBAL 035#endif3637/*38*----------------------------------------------------------------------39*40* TclLoadFile --41*42* Dynamically loads a binary code file into memory and returns43* the addresses of two procedures within that file, if they44* are defined.45*46* Results:47* A standard Tcl completion code. If an error occurs, an error48* message is left in interp->result. *proc1Ptr and *proc2Ptr49* are filled in with the addresses of the symbols given by50* *sym1 and *sym2, or NULL if those symbols can't be found.51*52* Side effects:53* New code suddenly appears in memory.54*55*----------------------------------------------------------------------56*/5758int59TclLoadFile(interp, fileName, sym1, sym2, proc1Ptr, proc2Ptr)60Tcl_Interp *interp; /* Used for error reporting. */61char *fileName; /* Name of the file containing the desired62* code. */63char *sym1, *sym2; /* Names of two procedures to look up in64* the file's symbol table. */65Tcl_PackageInitProc **proc1Ptr, **proc2Ptr;66/* Where to return the addresses corresponding67* to sym1 and sym2. */68{69VOID *handle;7071handle = dlopen(fileName, RTLD_NOW | RTLD_GLOBAL);72if (handle == NULL) {73Tcl_AppendResult(interp, "couldn't load file \"", fileName,74"\": ", dlerror(), (char *) NULL);75return TCL_ERROR;76}77*proc1Ptr = (Tcl_PackageInitProc *) dlsym(handle, sym1);78*proc2Ptr = (Tcl_PackageInitProc *) dlsym(handle, sym2);79return TCL_OK;80}8182/*83*----------------------------------------------------------------------84*85* TclGuessPackageName --86*87* If the "load" command is invoked without providing a package88* name, this procedure is invoked to try to figure it out.89*90* Results:91* Always returns 0 to indicate that we couldn't figure out a92* package name; generic code will then try to guess the package93* from the file name. A return value of 1 would have meant that94* we figured out the package name and put it in bufPtr.95*96* Side effects:97* None.98*99*----------------------------------------------------------------------100*/101102int103TclGuessPackageName(fileName, bufPtr)104char *fileName; /* Name of file containing package (already105* translated to local form if needed). */106Tcl_DString *bufPtr; /* Initialized empty dstring. Append107* package name to this if possible. */108{109return 0;110}111112113