This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
This is my patch patch.1m for perl5.001.
[perl5.git] / ext / DynaLoader / dlutils.c
... / ...
CommitLineData
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
12
13
14#ifdef DEBUGGING
15/* currently not connected to $DynaLoader::dl_error but should be */
16static int dl_debug = 0;
17#define DLDEBUG(level,code) if(dl_debug>=level){ code; }
18#else
19#define DLDEBUG(level,code)
20#endif
21
22
23static void
24dl_generic_private_init() /* called by dl_*.xs dl_private_init() */
25{
26#ifdef DEBUGGING
27 char *perl_dl_debug = getenv("PERL_DL_DEBUG");
28 if (perl_dl_debug)
29 dl_debug = atoi(perl_dl_debug);
30#endif
31}
32
33
34/* SaveError() takes printf style args and saves the result in LastError */
35#ifdef STANDARD_C
36static void
37SaveError(char* pat, ...)
38#else
39/*VARARGS0*/
40static void
41SaveError(pat, va_alist)
42 char *pat;
43 va_dcl
44#endif
45{
46 va_list args;
47 char *message;
48 int len;
49
50 /* This code is based on croak/warn but I'm not sure where mess() */
51 /* gets its buffer space from! */
52
53#ifdef I_STDARG
54 va_start(args, pat);
55#else
56 va_start(args);
57#endif
58 message = mess(pat, &args);
59 va_end(args);
60
61 len = strlen(message) + 1 ; /* include terminating null char */
62
63 /* Allocate some memory for the error message */
64 if (LastError)
65 LastError = (char*)saferealloc(LastError, len) ;
66 else
67 LastError = safemalloc(len) ;
68
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));
72}
73
74
75/* prepend underscore to s. write into buf. return buf. */
76char *
77dl_add_underscore(s, buf)
78char *s;
79char *buf;
80{
81 *buf = '_';
82 (void)strcpy(buf + 1, s);
83 return buf;
84}
85