update for HEAD-2003050101
[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 int *__p__commode(void) // not exported by NTDLL
34 {
35    return &_commode;
36 }
37
38 int BlockEnvToEnviron(void)
39 {
40     char * ptr, * ptr2;
41     int i, len;
42
43     DPRINT("BlockEnvToEnviron()\n");
44
45     if (_environ) {
46         FreeEnvironmentStringsA(_environ[0]);
47         if (__initenv == _environ) {
48             __initenv[0] == NULL;
49         } else {
50             free(_environ);
51         }
52     }
53     _environ = NULL;
54     ptr2 = ptr = (char*)GetEnvironmentStringsA();
55     if (ptr == NULL) {
56         DPRINT("GetEnvironmentStringsA() returnd NULL\n");
57         return -1;
58     }
59     len = 0;
60     while (*ptr2) {
61         len++;
62         while (*ptr2++);
63     }
64     _environ = malloc((len + 1) * sizeof(char*));
65     if (_environ == NULL) {
66         FreeEnvironmentStringsA(ptr);
67         return -1;
68     }
69     for (i = 0; i < len && *ptr; i++) {
70         _environ[i] = ptr;
71         while (*ptr++);
72     }
73     _environ[i] = NULL;
74     if (__initenv == NULL)
75     {
76        __initenv = _environ;
77     }
78     return 0;
79 }
80
81 void __set_app_type(int app_type)
82 {
83     __app_type = app_type;
84 }
85
86 char **__p__acmdln(void)
87 {
88     return &_acmdln;
89 }
90
91 char ***__p__environ(void)
92 {
93     return _environ_dll;
94 }
95
96 char ***__p___initenv(void)
97 {
98     return &__initenv;
99 }
100
101 int *__p___mb_cur_max(void)
102 {
103     return &__mb_cur_max;
104 }
105
106 unsigned int *__p__osver(void)
107 {
108     return &_osver;
109 }
110
111 char **__p__pgmptr(void)
112 {
113     return &_pgmptr;
114 }
115
116 unsigned int *__p__winmajor(void)
117 {
118     return &_winmajor;
119 }
120
121 unsigned int *__p__winminor(void)
122 {
123     return &_winminor;
124 }
125
126 unsigned int *__p__winver(void)
127 {
128     return &_winver;
129 }
130
131 /* EOF */