/* dl_next.xs * * Platform: NeXT NS 3.2 * Author: Anno Siegel (siegel@zrz.TU-Berlin.DE) * Based on: dl_dlopen.xs by Paul Marquess * Created: Aug 15th, 1994 * */ /* And Gandalf said: 'Many folk like to know beforehand what is to be set on the table; but those who have laboured to prepare the feast like to keep their secret; for wonder makes the words of praise louder.' */ /* Porting notes: dl_next.xs is itself a port from dl_dlopen.xs by Paul Marquess. It should not be used as a base for further ports though it may be used as an example for how dl_dlopen.xs can be ported to other platforms. The method used here is just to supply the sun style dlopen etc. functions in terms of NeXTs rld_*. The xs code proper is unchanged from Paul's original. The port could use some streamlining. For one, error handling could be simplified. Anno Siegel */ /* include these before perl headers */ #include #include #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #define DL_LOADONCEONLY #include "dlutils.c" /* SaveError() etc */ static char * dl_last_error = (char *) 0; static AV *dl_resolve_using = Nullav; NXStream * OpenError() { return NXOpenMemory( (char *) 0, 0, NX_WRITEONLY); } void TransferError( s) NXStream *s; { char *buffer; int len, maxlen; if ( dl_last_error ) { safefree(dl_last_error); } NXGetMemoryBuffer(s, &buffer, &len, &maxlen); dl_last_error = safemalloc(len); strcpy(dl_last_error, buffer); } void CloseError( s) NXStream *s; { if ( s ) { NXCloseMemory( s, NX_FREEBUFFER); } } char *dlerror() { return dl_last_error; } char * dlopen(path, mode) char * path; int mode; /* mode is ignored */ { int rld_success; NXStream *nxerr; I32 i, psize; char *result; char **p; /* Do not load what is already loaded into this process */ if (hv_fetch(dl_loaded_files, path, strlen(path), 0)) return path; nxerr = OpenError(); psize = AvFILL(dl_resolve_using) + 3; p = (char **) safemalloc(psize * sizeof(char*)); p[0] = path; for(i=1; i