1 /* dlutils.c - handy functions and definitions for dl_*.xs files
3 * Currently this file is simply #included into dl_*.xs/.c files.
4 * It should really be split into a dlutils.h and dlutils.c
9 /* pointer to allocated memory for last error message */
10 static char *LastError = (char*)NULL;
12 /* flag for immediate rather than lazy linking (spots unresolved symbol) */
13 static int dl_nonlazy = 0;
15 #ifdef DL_LOADONCEONLY
16 static HV *dl_loaded_files = Nullhv; /* only needed on a few systems */
21 static int dl_debug = 0; /* value copied from $DynaLoader::dl_error */
22 #define DLDEBUG(level,code) if (dl_debug>=level) { code; }
24 #define DLDEBUG(level,code)
29 dl_generic_private_init() /* called by dl_*.xs dl_private_init() */
31 char *perl_dl_nonlazy;
33 dl_debug = SvIV( perl_get_sv("DynaLoader::dl_debug", 0x04) );
35 if ( (perl_dl_nonlazy = getenv("PERL_DL_NONLAZY")) != NULL )
36 dl_nonlazy = atoi(perl_dl_nonlazy);
38 DLDEBUG(1,fprintf(stderr,"DynaLoader bind mode is 'non-lazy'\n"));
39 #ifdef DL_LOADONCEONLY
41 dl_loaded_files = newHV(); /* provide cache for dl_*.xs if needed */
46 /* SaveError() takes printf style args and saves the result in LastError */
49 SaveError(char* pat, ...)
53 SaveError(pat, va_alist)
62 /* This code is based on croak/warn, see mess() in util.c */
69 message = mess(pat, &args);
72 len = strlen(message) + 1 ; /* include terminating null char */
74 /* Allocate some memory for the error message */
76 LastError = (char*)saferealloc(LastError, len) ;
78 LastError = safemalloc(len) ;
80 /* Copy message into LastError (including terminating null char) */
81 strncpy(LastError, message, len) ;
82 DLDEBUG(2,fprintf(stderr,"DynaLoader: stored error msg '%s'\n",LastError));
86 /* prepend underscore to s. write into buf. return buf. */
88 dl_add_underscore(s, buf)
93 (void)strcpy(buf + 1, s);