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;
15 /* currently not connected to $DynaLoader::dl_error but should be */
16 static int dl_debug = 0;
17 #define DLDEBUG(level,code) if(dl_debug>=level){ code; }
19 #define DLDEBUG(level,code)
24 dl_generic_private_init() /* called by dl_*.xs dl_private_init() */
27 char *perl_dl_debug = getenv("PERL_DL_DEBUG");
29 dl_debug = atoi(perl_dl_debug);
34 /* SaveError() takes printf style args and saves the result in LastError */
37 SaveError(char* pat, ...)
41 SaveError(pat, va_alist)
50 /* This code is based on croak/warn but I'm not sure where mess() */
51 /* gets its buffer space from! */
58 message = mess(pat, &args);
61 len = strlen(message) + 1 ; /* include terminating null char */
63 /* Allocate some memory for the error message */
65 LastError = (char*)saferealloc(LastError, len) ;
67 LastError = safemalloc(len) ;
69 /* Copy message into LastError (including terminating null char) */
70 strncpy(LastError, message, len) ;
71 DLDEBUG(2,fprintf(stderr,"DynaLoader: stored error msg '%s'\n",LastError));
75 /* prepend underscore to s. write into buf. return buf. */
77 dl_add_underscore(s, buf)
82 (void)strcpy(buf + 1, s);