Fixed compatibility of output.
[AROS.git] / compiler / posixc / __posixc_environ.c
blob099d404114bffdb2de342b8c98c063253b333476
1 /*
2 Copyright © 2012-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: AROS specific function for environ emulation handling
6 */
8 #include <proto/exec.h>
9 #include <proto/dos.h>
10 #include <dos/dos.h>
12 #include "__posixc_intbase.h"
13 #include "__env.h"
15 #include <stdio.h>
17 #define DEBUG 0
18 #include <aros/debug.h>
20 /*****************************************************************************
22 NAME */
23 #include <stdlib.h>
25 int __posixc_set_environptr (
27 /* SYNOPSIS */
28 char ***environptr)
30 /* FUNCTION
31 This function is called to enable environ emulation mode.
33 INPUTS
34 environptr - ptr to the child environ variable (== &environ).
36 RESULT
37 0 on fail, other value on succes
39 NOTES
40 This function will enable environ emulation. This means that
41 all current DOS local variables are converted to the 'var=value'
42 format and be accessible through char **environ.
44 EXAMPLE
46 BUGS
47 At the moment only a static list is supported. getenv() and setenv()
48 don't use this yet so changes done with these functions are not
49 reflected in environ.
50 This is still TODO.
52 SEE ALSO
53 __posixc_get_environptr(), getenv(), setenv()
55 INTERNALS
57 ******************************************************************************/
59 struct PosixCIntBase *PosixCBase =
60 (struct PosixCIntBase *)__aros_getbase_PosixCBase();
61 int len;
63 D(bug("Initializing POSIX environ emulation\n"));
65 PosixCBase->environptr = environptr;
67 len = __env_get_environ(NULL, 0);
68 *environptr = malloc(len);
69 return (__env_get_environ(*environptr, len) >= 0);
72 /*****************************************************************************
74 NAME */
75 #include <stdlib.h>
77 char ***__posixc_get_environptr (
79 /* SYNOPSIS */
80 void)
82 /* FUNCTION
83 This function the get pointer to the child environ global variable
84 currently used by posixc.library.
86 INPUTS
89 RESULT
90 environptr - ptr to the child environ variable (== &environ).
91 NULL is return if envirion emulation is disabled.
93 NOTES
95 EXAMPLE
97 BUGS
99 SEE ALSO
100 __posixc_set_environptr()
102 INTERNALS
104 ******************************************************************************/
106 struct PosixCIntBase *PosixCBase =
107 (struct PosixCIntBase *)__aros_getbase_PosixCBase();
109 return PosixCBase->environptr;