Add NAME attribute to suppress MakeMaker "guess" warning
[p5sagit/p5-mst-13.2.git] / ext / DynaLoader / dlutils.c
CommitLineData
a0d0e21e 1/* dlutils.c - handy functions and definitions for dl_*.xs files
2 *
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
5 *
6 */
7
8
9/* pointer to allocated memory for last error message */
10static char *LastError = (char*)NULL;
11
8e07c86e 12/* flag for immediate rather than lazy linking (spots unresolved symbol) */
13static int dl_nonlazy = 0;
14
15#ifdef DL_LOADONCEONLY
16static HV *dl_loaded_files = Nullhv; /* only needed on a few systems */
17#endif
a0d0e21e 18
19
20#ifdef DEBUGGING
8e07c86e 21static int dl_debug = 0; /* value copied from $DynaLoader::dl_error */
22#define DLDEBUG(level,code) if (dl_debug>=level) { code; }
a0d0e21e 23#else
24#define DLDEBUG(level,code)
25#endif
26
27
28static void
29dl_generic_private_init() /* called by dl_*.xs dl_private_init() */
30{
8e07c86e 31 char *perl_dl_nonlazy;
a0d0e21e 32#ifdef DEBUGGING
8e07c86e 33 dl_debug = SvIV( perl_get_sv("DynaLoader::dl_debug", 0x04) );
34#endif
35 if ( (perl_dl_nonlazy = getenv("PERL_DL_NONLAZY")) != NULL )
36 dl_nonlazy = atoi(perl_dl_nonlazy);
37 if (dl_nonlazy)
38 DLDEBUG(1,fprintf(stderr,"DynaLoader bind mode is 'non-lazy'\n"));
39#ifdef DL_LOADONCEONLY
40 if (!dl_loaded_files)
41 dl_loaded_files = newHV(); /* provide cache for dl_*.xs if needed */
a0d0e21e 42#endif
43}
44
45
46/* SaveError() takes printf style args and saves the result in LastError */
47#ifdef STANDARD_C
48static void
49SaveError(char* pat, ...)
50#else
51/*VARARGS0*/
52static void
53SaveError(pat, va_alist)
54 char *pat;
55 va_dcl
56#endif
57{
58 va_list args;
59 char *message;
60 int len;
61
8e07c86e 62 /* This code is based on croak/warn, see mess() in util.c */
a0d0e21e 63
64#ifdef I_STDARG
65 va_start(args, pat);
66#else
67 va_start(args);
68#endif
69 message = mess(pat, &args);
70 va_end(args);
71
72 len = strlen(message) + 1 ; /* include terminating null char */
73
74 /* Allocate some memory for the error message */
75 if (LastError)
76 LastError = (char*)saferealloc(LastError, len) ;
77 else
78 LastError = safemalloc(len) ;
79
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));
83}
84
85
86/* prepend underscore to s. write into buf. return buf. */
87char *
88dl_add_underscore(s, buf)
89char *s;
90char *buf;
91{
92 *buf = '_';
93 (void)strcpy(buf + 1, s);
94 return buf;
95}
96