Index: trunk/src/kernel32/directory.cpp
===================================================================
--- trunk/src/kernel32/directory.cpp	(revision 3692)
+++ trunk/src/kernel32/directory.cpp	(revision 3693)
@@ -1,3 +1,3 @@
-/* $Id: directory.cpp,v 1.23 2000-06-01 11:28:44 sandervl Exp $ */
+/* $Id: directory.cpp,v 1.24 2000-06-12 13:03:00 phaller Exp $ */
 
 /*
@@ -14,5 +14,6 @@
  * Copyright 1995 Alexandre Julliard
  *
- * TODO: System/window directories should be created by install program!
+ * TODO: 
+ *  - System/window directories should be created by install program!
  *
  * Project Odin Software License can be found in LICENSE.TXT
@@ -149,23 +150,31 @@
 
 
-ODINFUNCTION1(BOOL,SetCurrentDirectoryA,LPCSTR,lpPathName)
-{
-  if(HIWORD(lpPathName) == 0) {
-	SetLastError(ERROR_INVALID_PARAMETER);
-	return FALSE;
+ODINFUNCTION1(BOOL,   SetCurrentDirectoryA,
+              LPCSTR, lpstrDirectory)
+{
+  char szBuffer[260]; // MAXPATHLEN
+  
+  if(HIWORD(lpstrDirectory) == 0)
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
   }
-  int len = strlen(lpPathName);
-  char *tmp=(char *)alloca(len + 1);
-
-  strcpy(tmp, lpPathName);
-  if(tmp[len - 1] == '/') {
-	tmp[len-1] = '\\';
+  
+  // cut off trailing backslashes
+  // not if a process wants to change to the root directory
+  int len = lstrlenA(lpstrDirectory);
+  if ( ( (lpstrDirectory[len - 1] == '\\') ||
+         (lpstrDirectory[len - 1] == '/') ) &&
+       (len != 1) )
+  {
+    lstrcpynA(szBuffer,
+              lpstrDirectory,
+              len - 1);
+    szBuffer[len - 1] = 0;
+    lpstrDirectory = szBuffer;
   }
-  //SvL: Don't remove trailing backslash if it wants to chdir to root dir
-  if((tmp[len - 1] == '\\')  && len != 1)
-    tmp[len -1] = 0;
-
-  dprintf(("SetCurrentDirectoryA %s", tmp));
-  return O32_SetCurrentDirectory((LPSTR)tmp);
+
+  dprintf(("SetCurrentDirectoryA %s", lpstrDirectory));
+  return O32_SetCurrentDirectory((LPSTR)lpstrDirectory);
 }
 
@@ -207,14 +216,26 @@
  *****************************************************************************/
 
-ODINFUNCTION2(BOOL,CreateDirectoryA,LPCSTR, arg1,PSECURITY_ATTRIBUTES,arg2)
-{
-  int len = strlen(arg1);
-  char *tmp=(char *)alloca(len + 1);
-
-  strcpy(tmp, arg1);
-  if(tmp[len -1] == '\\')
-    tmp[len -1] = 0;
-  dprintf(("CreateDirectoryA %s", tmp));
-  return O32_CreateDirectory(tmp, arg2);
+ODINFUNCTION2(BOOL,                CreateDirectoryA,
+              LPCSTR,              lpstrDirectory,
+              PSECURITY_ATTRIBUTES,arg2)
+{
+  char szBuffer[260]; // MAXPATHLEN
+  int len = strlen(lpstrDirectory);
+  
+  // cut off trailing backslashes
+  if (lpstrDirectory[len - 1] == '\\')
+  {
+    lstrcpynA(szBuffer,
+              lpstrDirectory,
+              len - 1);
+    szBuffer[len - 1] = 0;
+    lpstrDirectory = szBuffer;
+  }
+  
+  dprintf(("CreateDirectoryA %s", 
+            lpstrDirectory));
+  
+  return(O32_CreateDirectory(szBuffer,
+                             arg2));
 }
 
@@ -289,14 +310,16 @@
 
   if(lpBuffer)
-  	asciibuffer = (char *)alloca(uSize+1);
-
-  if(lpBuffer && asciibuffer == NULL) {
-	DebugInt3();
+    asciibuffer = (char *)alloca(uSize+1);
+
+  if(lpBuffer && asciibuffer == NULL) 
+  {
+    DebugInt3();
   }
 
   rc = GetSystemDirectoryA(asciibuffer, uSize);
   if(rc && asciibuffer)
-    	AsciiToUnicode(asciibuffer, lpBuffer);
-
+    AsciiToUnicode(asciibuffer, lpBuffer);
+  
+  free(asciibuffer);
   return(rc);
 }
@@ -348,14 +371,16 @@
 
   if(lpBuffer)
-  	asciibuffer = (char *)alloca(uSize+1);
-
-  if(lpBuffer && asciibuffer == NULL) {
-	DebugInt3();
+    asciibuffer = (char *)alloca(uSize+1);
+
+  if(lpBuffer && asciibuffer == NULL) 
+  {
+    DebugInt3();
   }
 
   rc = GetWindowsDirectoryA(asciibuffer, uSize);
   if(rc && asciibuffer)
-    	AsciiToUnicode(asciibuffer, lpBuffer);
-
+    AsciiToUnicode(asciibuffer, lpBuffer);
+  
+  free(asciibuffer);
   return(rc);
 }
@@ -375,16 +400,24 @@
 
 
-ODINFUNCTION1(BOOL,RemoveDirectoryA,LPCSTR,arg1)
-{
-  int len = strlen(arg1);
-  char *tmp=(char *)alloca(len + 1);
-
-  strcpy(tmp, arg1);
-  if(tmp[len -1] == '\\')
-    tmp[len -1] = 0;
-
-  dprintf(("RemoveDirectory %s", arg1));
-
-  return O32_RemoveDirectory(tmp);
+ODINFUNCTION1(BOOL,   RemoveDirectoryA,
+              LPCSTR, lpstrDirectory)
+{
+  char szBuffer[260]; // MAXPATHLEN
+  int len = strlen(lpstrDirectory);
+  
+  // cut off trailing backslashes
+  if (lpstrDirectory[len - 1] == '\\')
+  {
+    lstrcpynA(szBuffer,
+              lpstrDirectory,
+              len - 1);
+    szBuffer[len - 1] = 0;
+    lpstrDirectory = szBuffer;
+  }
+  
+  dprintf(("RemoveDirectory %s", 
+          lpstrDirectory));
+
+  return O32_RemoveDirectory(lpstrDirectory);
 }
 
