reactos/lib/msvcrt/misc
diff -u -r1.21 -r1.22
--- dllmain.c 11 May 2004 20:44:30 -0000 1.21
+++ dllmain.c 27 May 2004 11:49:48 -0000 1.22
@@ -1,4 +1,4 @@
-/* $Id: dllmain.c,v 1.21 2004/05/11 20:44:30 gvg Exp $
+/* $Id: dllmain.c,v 1.22 2004/05/27 11:49:48 hbirr Exp $
*
* dllmain.c
*
@@ -14,9 +14,9 @@
* DISCLAMED. This includes but is not limited to warrenties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Revision: 1.21 $
- * $Author: gvg $
- * $Date: 2004/05/11 20:44:30 $
+ * $Revision: 1.22 $
+ * $Author: hbirr $
+ * $Date: 2004/05/27 11:49:48 $
*
*/
@@ -48,8 +48,6 @@
/* LIBRARY GLOBAL VARIABLES ***************************************************/
-static int nAttachCount = 0;
-
HANDLE hHeap = NULL; /* handle for heap */
@@ -69,22 +67,11 @@
_winminor = _osver & 0xFF;
_winver = (_winmajor << 8) + _winminor;
_osver = (_osver >> 16) & 0xFFFF;
- if (hHeap == NULL || hHeap == INVALID_HANDLE_VALUE)
- {
- hHeap = HeapCreate(0, 100000, 0);
- if (hHeap == NULL || hHeap == INVALID_HANDLE_VALUE)
- {
- return FALSE;
- }
- }
- if (nAttachCount==0)
- {
- if (!__fileno_init()) {
- HeapDestroy(hHeap);
- hHeap = NULL;
- return FALSE;
- }
- }
+ hHeap = HeapCreate(0, 100000, 0);
+ if (hHeap == NULL)
+ return FALSE;
+ if (!__fileno_init())
+ return FALSE;
/* create tls stuff */
if (!CreateThreadData())
@@ -102,7 +89,6 @@
msvcrt_init_mt_locks();
msvcrt_init_args();
- nAttachCount++;
DPRINT("Attach done\n");
break;
@@ -115,42 +101,26 @@
case DLL_PROCESS_DETACH://0
DPRINT("Detach %d\n", nAttachCount);
- if (nAttachCount > 0)
- {
- nAttachCount--;
-
- /* Deinitialization of the WINE code */
- msvcrt_free_args();
- msvcrt_free_mt_locks();
-
- /* FIXME: more cleanup... */
- _fcloseall();
-
- /* destroy tls stuff */
- DestroyThreadData();
-
- /* destroy heap */
- if (nAttachCount == 0)
- {
- if (__initenv && __initenv != _environ)
- {
- FreeEnvironmentStringsA(__initenv[0]);
- free(__initenv);
- __initenv = NULL;
- }
- if (_environ)
- {
- FreeEnvironmentStringsA(_environ[0]);
- free(_environ);
- _environ = NULL;
- }
-#if 1
- HeapDestroy(hHeap);
- hHeap = NULL;
-#endif
- }
+ /* FIXME: more cleanup... */
+ _fcloseall();
+
+ /* destroy tls stuff */
+ DestroyThreadData();
+
+ if (__initenv && __initenv != _environ)
+ {
+ free(__initenv[0]);
+ free(__initenv);
+ }
+ if (_environ)
+ {
+ free(_environ[0]);
+ free(_environ);
+ }
+ /* destroy heap */
+ HeapDestroy(hHeap);
+
DPRINT("Detach done\n");
- }
break;
}
reactos/lib/msvcrt/misc
diff -u -r1.7 -r1.8
--- environ.c 21 Feb 2004 08:02:49 -0000 1.7
+++ environ.c 27 May 2004 11:49:48 -0000 1.8
@@ -1,4 +1,4 @@
-/* $Id: environ.c,v 1.7 2004/02/21 08:02:49 tamlin Exp $
+/* $Id: environ.c,v 1.8 2004/05/27 11:49:48 hbirr Exp $
*
* dllmain.c
*
@@ -20,6 +20,7 @@
unsigned int _winver = 0;
char *_acmdln = NULL; /* pointer to ascii command line */
+unsigned _envvar_count; /* number of environment vars within current environment */
#undef _environ
char **_environ = NULL; /* pointer to environment block */
char ***_environ_dll = &_environ;/* pointer to environment block */
@@ -43,46 +44,73 @@
int BlockEnvToEnviron(void)
{
char * ptr, * ptr2;
- int i, count;
+ int i, count, len, size;
DPRINT("BlockEnvToEnviron()\n");
- if (_environ && _environ != __initenv) {
- FreeEnvironmentStringsA(_environ[0]);
- free(_environ);
- }
- _environ = NULL;
ptr2 = ptr = (char*)GetEnvironmentStringsA();
if (ptr == NULL) {
- DPRINT("GetEnvironmentStringsA() returnd NULL\n");
- return -1;
+ return -1;
}
+
+ size = 0;
count = 0;
while (*ptr2) {
- /* skip current directory of the form "=C:=C:\directory\" */
- if (*ptr2 != '=') {
- count++;
- }
- ptr2 += strlen(ptr2) + 1;
- }
- _environ = malloc((count + 1) * sizeof(char*));
- if (_environ == NULL) {
- FreeEnvironmentStringsA(ptr);
- return -1;
+ len = strlen(ptr2);
+ if (*ptr2 != '=') {
+ count++;
+ size += len + 1;
+ }
+ ptr2 += len + 1;
+ }
+
+ if (count != _envvar_count) {
+ if (_environ && _environ != __initenv) {
+ free(_environ[0]);
+ _environ = realloc(_environ, (count + 1) * sizeof(char*));
+ } else {
+ _environ = malloc((count + 1) * sizeof(char*));
+ }
+ if (_environ == NULL) {
+ FreeEnvironmentStringsA(ptr);
+ _envvar_count = 0;
+ return -1;
+ }
+ _environ[0] = NULL;
+ }
+ if (_environ[0] != NULL) {
+ free(_environ[0]);
+ }
+
+ _environ[0] = malloc(size);
+ if (_environ[0] == NULL) {
+ FreeEnvironmentStringsA(ptr);
+ free(_environ);
+ _envvar_count = 0;
+ return -1;
}
+
+ ptr2 = ptr;
i = 0;
- while (i < count && *ptr) {
- if (*ptr != '=') {
- _environ[i] = ptr;
- ++i;
- }
- ptr += strlen(ptr) + 1;
+ while (*ptr2 && i < count) {
+ len = strlen(ptr2);
+ /* skip current directory of the form "=C:=C:\directory\" */
+ if (*ptr2 != '=') {
+ memcpy(_environ[i], ptr2, len + 1);
+ i++;
+ if (i < count) {
+ _environ[i] = _environ[i - 1] + len + 1;
+ }
+ }
+ ptr2 += len + 1;
}
_environ[i] = NULL;
- if (__initenv == NULL)
+ _envvar_count = count;
+ if (__initenv == NULL)
{
__initenv = _environ;
}
+ FreeEnvironmentStringsA(ptr);
return 0;
}