summaryrefslogtreecommitdiff
path: root/win32/ipenv.c
blob: 9033b55138d6b09edda8702098a1f762fe5f1c56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*

	ipenv.c
	Interface for perl environment functions

*/

#include <ipenv.h>
#include <stdlib.h>

class CPerlEnv : public IPerlEnv
{
public:
	CPerlEnv() { w32_perldll_handle = INVALID_HANDLE_VALUE; pPerl = NULL; };
	virtual char *Getenv(const char *varname, int &err);
	virtual int Putenv(const char *envstring, int &err);
	virtual char* LibPath(char *sfx, ...);

	inline void SetPerlObj(CPerlObj *p) { pPerl = p; };
protected:
	char	w32_perllib_root[MAX_PATH+1];
	HANDLE	w32_perldll_handle;
	CPerlObj *pPerl;
};

char *CPerlEnv::Getenv(const char *varname, int &err)
{
	return getenv(varname);
}

int CPerlEnv::Putenv(const char *envstring, int &err)
{
	return _putenv(envstring);
}

char* CPerlEnv::LibPath(char *sfx, ...)
{
    va_list ap;
    char *end;
    va_start(ap,sfx);
    GetModuleFileName((w32_perldll_handle == INVALID_HANDLE_VALUE) 
		      ? GetModuleHandle(NULL)
		      : w32_perldll_handle,
		      w32_perllib_root, 
		      sizeof(w32_perllib_root));
    *(end = strrchr(w32_perllib_root, '\\')) = '\0';
    if (stricmp(end-4,"\\bin") == 0)
     end -= 4;
    strcpy(end,"\\lib");
    while (sfx)
     {
      strcat(end,"\\");
      strcat(end,sfx);
      sfx = va_arg(ap,char *);
     }
    va_end(ap); 
    return (w32_perllib_root);
}