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