-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathenviron.c
More file actions
103 lines (82 loc) · 2.17 KB
/
environ.c
File metadata and controls
103 lines (82 loc) · 2.17 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <dos/var.h>
#include <utility/hooks.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/utility.h>
char **environ = NULL;
#ifdef __amigaos4__
#define MAX_ENV_SIZE 1024 /* maximum number of environ entries */
#ifdef AUTOINIT
#ifdef __GNUC__
void ___makeenviron() __attribute__((constructor));
void ___freeenviron() __attribute__((destructor));
#endif
#ifdef __VBCC__
#define ___makeenviron() _INIT_9_makeenviron()
#define ___freeenviron() _EXIT_9_makeenviron()
#endif
#endif
uint32
copy_env(struct Hook *hook, APTR userdata, struct ScanVarsMsg *message)
{
static uint32 env_size = 1; /* environ is null terminated */
if(strlen(message->sv_GDir) <= 4)
{
if ( env_size == MAX_ENV_SIZE )
{
return 0;
}
++env_size;
char **env = (char **)hook->h_Data;
uint32 size = strlen(message->sv_Name) + 1 + message->sv_VarLen + 1 + 1;
char *buffer=(char *)malloc(size);
snprintf(buffer,size-1,"%s=%s", message->sv_Name, message->sv_Var);
*env = buffer;
env++;
hook->h_Data = env;
}
return 0;
}
void
___makeenviron()
{
struct Hook hook;
char varbuf[8];
uint32 flags=0;
size_t environ_size=MAX_ENV_SIZE * sizeof(char*);
if(GetVar("ABCSH_IMPORT_LOCAL",varbuf,sizeof(varbuf),GVF_LOCAL_ONLY) > 0)
{
flags = GVF_LOCAL_ONLY;
}
else
{
flags = GVF_GLOBAL_ONLY;
}
environ = (char **)malloc(environ_size);
if (!environ)
{
return;
}
memset(environ, 0, environ_size);
memset(&hook, 0, sizeof(struct Hook));
hook.h_Entry = copy_env;
hook.h_Data = environ;
ScanVars(&hook, flags, 0);
}
void
___freeenviron()
{
char **i;
for(i=environ;*i!=NULL;i++)
{
free(*i);
}
free(environ);
}
#endif