update for HEAD-2003091401
[reactos.git] / lib / msvcrt / misc / environ.c
1 /* $Id$
2  *
3  * dllmain.c
4  *
5  * ReactOS MSVCRT.DLL Compatibility Library
6  */
7
8 #include <windows.h>
9 #include <msvcrt/internal/tls.h>
10 #include <msvcrt/stdlib.h>
11
12 #define NDEBUG
13 #include <msvcrt/msvcrtdbg.h>
14
15
16 unsigned int _osver = 0;
17 unsigned int _winminor = 0;
18 unsigned int _winmajor = 0;
19 unsigned int _winver = 0;
20
21 char *_acmdln = NULL;       /* pointer to ascii command line */
22 #undef _environ
23 char **_environ = NULL;     /* pointer to environment block */
24 char ***_environ_dll = &_environ;/* pointer to environment block */
25 char **__initenv = NULL;
26 char *_pgmptr = NULL;       /* pointer to program name */
27 int __app_type = 0; //_UNKNOWN_APP; /* application type */
28 int __mb_cur_max = 1;
29
30 int _commode = _IOCOMMIT;
31
32
33 /*
34  * @implemented
35  */
36 int *__p__commode(void) // not exported by NTDLL
37 {
38    return &_commode;
39 }
40
41 int BlockEnvToEnviron(void)
42 {
43     char * ptr, * ptr2;
44     int i, len;
45
46     DPRINT("BlockEnvToEnviron()\n");
47
48     if (_environ && _environ != __initenv) {
49         FreeEnvironmentStringsA(_environ[0]);
50         free(_environ);
51     }
52     _environ = NULL;
53     ptr2 = ptr = (char*)GetEnvironmentStringsA();
54     if (ptr == NULL) {
55         DPRINT("GetEnvironmentStringsA() returnd NULL\n");
56         return -1;
57     }
58     len = 0;
59     while (*ptr2) {
60         len++;
61         ptr2 += strlen(ptr2) + 1;
62     }
63     _environ = malloc((len + 1) * sizeof(char*));
64     if (_environ == NULL) {
65         FreeEnvironmentStringsA(ptr);
66         return -1;
67     }
68     for (i = 0; i < len && *ptr; i++) {
69         _environ[i] = ptr;
70         ptr += strlen(ptr) + 1;
71     }
72     _environ[i] = NULL;
73     if (__initenv == NULL)
74     {
75        __initenv = _environ;
76     }
77     return 0;
78 }
79
80 /*
81  * @implemented
82  */
83 void __set_app_type(int app_type)
84 {
85     __app_type = app_type;
86 }
87
88 /*
89  * @implemented
90  */
91 char **__p__acmdln(void)
92 {
93     return &_acmdln;
94 }
95
96 /*
97  * @implemented
98  */
99 char ***__p__environ(void)
100 {
101     return _environ_dll;
102 }
103
104 /*
105  * @implemented
106  */
107 char ***__p___initenv(void)
108 {
109     return &__initenv;
110 }
111
112 /*
113  * @implemented
114  */
115 int *__p___mb_cur_max(void)
116 {
117     return &__mb_cur_max;
118 }
119
120 /*
121  * @implemented
122  */
123 unsigned int *__p__osver(void)
124 {
125     return &_osver;
126 }
127
128 /*
129  * @implemented
130  */
131 char **__p__pgmptr(void)
132 {
133     return &_pgmptr;
134 }
135
136 /*
137  * @implemented
138  */
139 unsigned int *__p__winmajor(void)
140 {
141     return &_winmajor;
142 }
143
144 /*
145  * @implemented
146  */
147 unsigned int *__p__winminor(void)
148 {
149     return &_winminor;
150 }
151
152 /*
153  * @implemented
154  */
155 unsigned int *__p__winver(void)
156 {
157     return &_winver;
158 }
159
160 /* EOF */