2 #include <exec/memory.h>
5 #include <utility/hooks.h>
6 #include <proto/exec.h>
8 #include <proto/utility.h>
10 char **environ
= NULL
;
13 #if defined(__amigaos4__) || defined(__AROS__)
15 #define MAX_ENV_SIZE 1024 /* maximum number of environ entries */
19 void ___makeenviron() __attribute__((constructor
));
20 void ___freeenviron() __attribute__((destructor
));
23 #define ___makeenviron() _INIT_9_makeenviron()
24 #define ___freeenviron() _EXIT_9_makeenviron()
30 copy_env(struct Hook
*hook
, APTR userdata
, struct ScanVarsMsg
*message
)
32 static uint32 env_size
= 1; /* environ is null terminated */
34 if(strlen(message
->sv_GDir
) <= 4)
36 if ( env_size
== MAX_ENV_SIZE
)
41 char **env
= (char **)hook
->h_Data
;
42 uint32 size
= strlen(message
->sv_Name
) + 1 + message
->sv_VarLen
+ 1 + 1;
43 char *buffer
=(char *)malloc(size
);
51 snprintf(buffer
,size
-1,"%s=%.*s", message
->sv_Name
, (int)message
->sv_VarLen
, message
->sv_Var
);
66 size_t environ_size
=MAX_ENV_SIZE
* sizeof(char*);
68 if(GetVar("ABCSH_IMPORT_LOCAL",varbuf
,sizeof(varbuf
),GVF_LOCAL_ONLY
) > 0)
70 flags
= GVF_LOCAL_ONLY
;
74 flags
= GVF_GLOBAL_ONLY
;
77 environ
= (char **)malloc(environ_size
);
83 memset(environ
, 0, environ_size
);
86 memset(&hook
, 0, sizeof(struct Hook
));
87 hook
.h_Entry
= copy_env
;
88 hook
.h_Data
= environ
;
90 ScanVars(&hook
, flags
, 0);
96 if ( environ
!= NULL
)
99 for ( i
= environ
; *i
!= NULL
; i
++ )