Fixed CreateDirectoryExW.

svn path=/trunk/; revision=489
This commit is contained in:
Eric Kohl 1999-05-19 17:57:57 +00:00
parent 0495cfd8d4
commit cf7d159791

View file

@ -22,6 +22,10 @@
#define NDEBUG #define NDEBUG
#include <kernel32/kernel32.h> #include <kernel32/kernel32.h>
/* EXTERNS ******************************************************************/
DWORD STDCALL GetCurrentDriveW(DWORD nBufferLength, PWSTR lpBuffer);
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
WINBOOL STDCALL CreateDirectoryA(LPCSTR lpPathName, WINBOOL STDCALL CreateDirectoryA(LPCSTR lpPathName,
@ -88,6 +92,9 @@ WINBOOL STDCALL CreateDirectoryExW(LPCWSTR lpTemplateDirectory,
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING DirectoryNameString; UNICODE_STRING DirectoryNameString;
IO_STATUS_BLOCK IoStatusBlock; IO_STATUS_BLOCK IoStatusBlock;
WCHAR PathNameW[MAX_PATH];
WCHAR DirectoryNameW[MAX_PATH];
UINT Len = 0;
DPRINT("lpTemplateDirectory %w lpNewDirectory %w lpSecurityAttributes %p\n", DPRINT("lpTemplateDirectory %w lpNewDirectory %w lpSecurityAttributes %p\n",
lpTemplateDirectory, lpNewDirectory, lpSecurityAttributes); lpTemplateDirectory, lpNewDirectory, lpSecurityAttributes);
@ -99,9 +106,52 @@ WINBOOL STDCALL CreateDirectoryExW(LPCWSTR lpTemplateDirectory,
return(FALSE); return(FALSE);
} }
DirectoryNameString.Length = lstrlenW(lpNewDirectory)*sizeof(WCHAR); if (lpNewDirectory[1] == (WCHAR)':')
DirectoryNameString.Buffer = (WCHAR *)lpNewDirectory; {
DirectoryNameString.MaximumLength = DirectoryNameString.Length+sizeof(WCHAR); wcscpy(PathNameW, lpNewDirectory);
}
else if (wcslen(lpNewDirectory) > 4 &&
lpNewDirectory[0] == (WCHAR)'\\' &&
lpNewDirectory[1] == (WCHAR)'\\' &&
lpNewDirectory[2] == (WCHAR)'.' &&
lpNewDirectory[3] == (WCHAR)'\\')
{
wcscpy(PathNameW, lpNewDirectory);
}
else if (lpNewDirectory[0] == (WCHAR)'\\')
{
GetCurrentDriveW(MAX_PATH,PathNameW);
wcscat(PathNameW, lpNewDirectory);
}
else
{
Len = GetCurrentDirectoryW(MAX_PATH,PathNameW);
if ( Len == 0 )
return NULL;
if ( PathNameW[Len-1] != L'\\' ) {
PathNameW[Len] = L'\\';
PathNameW[Len+1] = 0;
}
wcscat(PathNameW,lpNewDirectory);
}
DirectoryNameW[0] = '\\';
DirectoryNameW[1] = '?';
DirectoryNameW[2] = '?';
DirectoryNameW[3] = '\\';
DirectoryNameW[4] = 0;
wcscat(DirectoryNameW,PathNameW);
DirectoryNameString.Length = wcslen (DirectoryNameW)*sizeof(WCHAR);
if ( DirectoryNameString.Length == 0 )
return NULL;
if ( DirectoryNameString.Length > MAX_PATH*sizeof(WCHAR) )
return NULL;
DirectoryNameString.Buffer = (WCHAR *)DirectoryNameW;
DirectoryNameString.MaximumLength = DirectoryNameString.Length + sizeof(WCHAR);
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL; ObjectAttributes.RootDirectory = NULL;
@ -118,7 +168,7 @@ WINBOOL STDCALL CreateDirectoryExW(LPCWSTR lpTemplateDirectory,
FILE_ATTRIBUTE_DIRECTORY, FILE_ATTRIBUTE_DIRECTORY,
0, 0,
FILE_CREATE, FILE_CREATE,
0, FILE_DIRECTORY_FILE,
NULL, NULL,
0); 0);
DPRINT("errCode: %x\n", errCode); DPRINT("errCode: %x\n", errCode);
@ -140,13 +190,13 @@ WINBOOL STDCALL RemoveDirectoryA(LPCSTR lpPathName)
WCHAR PathNameW[MAX_PATH]; WCHAR PathNameW[MAX_PATH];
ULONG i; ULONG i;
i = 0; i = 0;
while ((*lpPathName)!=0 && i < MAX_PATH) while ((*lpPathName)!=0 && i < MAX_PATH)
{ {
PathNameW[i] = *lpPathName; PathNameW[i] = *lpPathName;
lpPathName++; lpPathName++;
i++; i++;
} }
PathNameW[i] = 0; PathNameW[i] = 0;
return RemoveDirectoryW(PathNameW); return RemoveDirectoryW(PathNameW);
} }
@ -167,7 +217,7 @@ WINBOOL STDCALL RemoveDirectoryW(LPCWSTR lpPathName)
ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT; ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT;
ObjectAttributes.SecurityDescriptor = NULL; ObjectAttributes.SecurityDescriptor = NULL;
ObjectAttributes.SecurityQualityOfService = NULL; ObjectAttributes.SecurityQualityOfService = NULL;
errCode = NtDeleteFile(&ObjectAttributes); errCode = NtDeleteFile(&ObjectAttributes);
if (!NT_SUCCESS(errCode)) if (!NT_SUCCESS(errCode))
@ -203,13 +253,13 @@ DWORD STDCALL GetFullPathNameA(LPCSTR lpFileName,
{ {
PSTR p; PSTR p;
PSTR prev = NULL; PSTR prev = NULL;
DPRINT("GetFullPathNameA(lpFileName %s, nBufferLength %d, lpBuffer %p, " DPRINT("GetFullPathNameA(lpFileName %s, nBufferLength %d, lpBuffer %p, "
"lpFilePart %p)\n",lpFileName,nBufferLength,lpBuffer,lpFilePart); "lpFilePart %p)\n",lpFileName,nBufferLength,lpBuffer,lpFilePart);
if (!lpFileName || !lpBuffer) if (!lpFileName || !lpBuffer)
return 0; return 0;
if (isalpha(lpFileName[0]) && lpFileName[1] == ':') if (isalpha(lpFileName[0]) && lpFileName[1] == ':')
{ {
if (lpFileName[2] == '\\') if (lpFileName[2] == '\\')
@ -247,7 +297,7 @@ DWORD STDCALL GetFullPathNameA(LPCSTR lpFileName,
} }
lstrcatA(lpBuffer, lpFileName); lstrcatA(lpBuffer, lpFileName);
} }
DPRINT("lpBuffer %s\n",lpBuffer); DPRINT("lpBuffer %s\n",lpBuffer);
p = lpBuffer + 2; p = lpBuffer + 2;
@ -265,9 +315,9 @@ DWORD STDCALL GetFullPathNameA(LPCSTR lpFileName,
{ {
prev = p; prev = p;
do do
{ {
p++; p++;
} }
while ((*p) != 0 && (*p) != '\\'); while ((*p) != 0 && (*p) != '\\');
} }
else if (dwDotLen == 1) else if (dwDotLen == 1)
@ -277,7 +327,7 @@ DWORD STDCALL GetFullPathNameA(LPCSTR lpFileName,
else else
{ {
if (dwDotLen > 2) if (dwDotLen > 2)
{ {
int n = dwDotLen - 2; int n = dwDotLen - 2;
while (n > 0 && prev > (lpBuffer+2)) while (n > 0 && prev > (lpBuffer+2))
@ -286,7 +336,7 @@ DWORD STDCALL GetFullPathNameA(LPCSTR lpFileName,
if ((*prev) == '\\') if ((*prev) == '\\')
n--; n--;
} }
} }
if (*(p+dwDotLen+1) == 0) if (*(p+dwDotLen+1) == 0)
*(prev+1) = 0; *(prev+1) = 0;
@ -310,7 +360,7 @@ DWORD STDCALL GetFullPathNameA(LPCSTR lpFileName,
} }
DPRINT("lpBuffer %s\n",lpBuffer); DPRINT("lpBuffer %s\n",lpBuffer);
return strlen(lpBuffer); return strlen(lpBuffer);
} }
@ -340,13 +390,13 @@ DWORD STDCALL GetFullPathNameW(LPCWSTR lpFileName,
{ {
PWSTR p; PWSTR p;
PWSTR prev = NULL; PWSTR prev = NULL;
DPRINT("GetFullPathNameW(lpFileName %w, nBufferLength %d, lpBuffer %p, " DPRINT("GetFullPathNameW(lpFileName %w, nBufferLength %d, lpBuffer %p, "
"lpFilePart %p)\n",lpFileName,nBufferLength,lpBuffer,lpFilePart); "lpFilePart %p)\n",lpFileName,nBufferLength,lpBuffer,lpFilePart);
if (!lpFileName || !lpBuffer) if (!lpFileName || !lpBuffer)
return 0; return 0;
if (isalpha(lpFileName[0]) && lpFileName[1] == L':') if (isalpha(lpFileName[0]) && lpFileName[1] == L':')
{ {
if (lpFileName[2] == L'\\') if (lpFileName[2] == L'\\')
@ -371,7 +421,7 @@ DWORD STDCALL GetFullPathNameW(LPCWSTR lpFileName,
else if (lpFileName[0] == L'\\') else if (lpFileName[0] == L'\\')
{ {
GetCurrentDirectoryW(nBufferLength, lpBuffer); GetCurrentDirectoryW(nBufferLength, lpBuffer);
lstrcpyW(&lpBuffer[2], lpFileName); lstrcpyW(&lpBuffer[2], lpFileName);
} }
else else
{ {
@ -382,23 +432,23 @@ DWORD STDCALL GetFullPathNameW(LPCWSTR lpFileName,
lpBuffer[len] = L'\\'; lpBuffer[len] = L'\\';
lpBuffer[len + 1] = 0; lpBuffer[len + 1] = 0;
} }
lstrcatW(lpBuffer, lpFileName); lstrcatW(lpBuffer, lpFileName);
} }
DPRINT("lpBuffer %w\n",lpBuffer); DPRINT("lpBuffer %w\n",lpBuffer);
p = lpBuffer + 2; p = lpBuffer + 2;
prev = p; prev = p;
while ((*p) != 0 || ((*p) == L'\\' && (*(p+1)) == 0)) while ((*p) != 0 || ((*p) == L'\\' && (*(p+1)) == 0))
{ {
DWORD dwDotLen; DWORD dwDotLen;
dwDotLen = GetDotSequenceLengthW (p+1); dwDotLen = GetDotSequenceLengthW (p+1);
DPRINT("DotSequenceLength %u\n", dwDotLen); DPRINT("DotSequenceLength %u\n", dwDotLen);
DPRINT("prev %w p %w\n",prev,p); DPRINT("prev %w p %w\n",prev,p);
if (dwDotLen == 0) if (dwDotLen == 0)
{ {
prev = p; prev = p;
do do
@ -407,11 +457,11 @@ DWORD STDCALL GetFullPathNameW(LPCWSTR lpFileName,
} }
while ((*p) != 0 && (*p) != L'\\'); while ((*p) != 0 && (*p) != L'\\');
} }
else if (dwDotLen == 1) else if (dwDotLen == 1)
{ {
lstrcpyW(p, p+2); lstrcpyW(p, p+2);
} }
else else
{ {
if (dwDotLen > 2) if (dwDotLen > 2)
{ {
@ -443,11 +493,11 @@ DWORD STDCALL GetFullPathNameW(LPCWSTR lpFileName,
if (lpFilePart != NULL) if (lpFilePart != NULL)
{ {
(*lpFilePart) = prev + 1; (*lpFilePart) = prev + 1;
} }
DPRINT("lpBuffer %w\n",lpBuffer); DPRINT("lpBuffer %w\n",lpBuffer);
return wcslen(lpBuffer); return wcslen(lpBuffer);
} }
@ -470,7 +520,7 @@ GetShortPathNameA(
//4 Increment the ~1 string if the resulting name allready exists //4 Increment the ~1 string if the resulting name allready exists
} }
DWORD DWORD
STDCALL STDCALL
@ -480,7 +530,7 @@ GetShortPathNameW(
DWORD cchBuffer DWORD cchBuffer
) )
{ {
} }
DWORD DWORD
@ -506,36 +556,36 @@ SearchPathA(
i = 0; i = 0;
while ((*lpPath)!=0 && i < MAX_PATH) while ((*lpPath)!=0 && i < MAX_PATH)
{ {
PathW[i] = *lpPath; PathW[i] = *lpPath;
lpPath++; lpPath++;
i++; i++;
} }
PathW[i] = 0; PathW[i] = 0;
i = 0; i = 0;
while ((*lpFileName)!=0 && i < MAX_PATH) while ((*lpFileName)!=0 && i < MAX_PATH)
{ {
FileNameW[i] = *lpFileName; FileNameW[i] = *lpFileName;
lpFileName++; lpFileName++;
i++; i++;
} }
FileNameW[i] = 0; FileNameW[i] = 0;
i = 0; i = 0;
while ((*lpExtension)!=0 && i < MAX_PATH) while ((*lpExtension)!=0 && i < MAX_PATH)
{ {
ExtensionW[i] = *lpExtension; ExtensionW[i] = *lpExtension;
lpExtension++; lpExtension++;
i++; i++;
} }
ExtensionW[i] = 0; ExtensionW[i] = 0;
RetValue = SearchPathW(PathW,FileNameW,ExtensionW,nBufferLength,BufferW,&FilePartW); RetValue = SearchPathW(PathW,FileNameW,ExtensionW,nBufferLength,BufferW,&FilePartW);
for(i=0;i<nBufferLength;i++) for(i=0;i<nBufferLength;i++)
lpBuffer[i] = (char)BufferW[i]; lpBuffer[i] = (char)BufferW[i];
*lpFilePart = strrchr(lpBuffer,'\\')+1; *lpFilePart = strrchr(lpBuffer,'\\')+1;
return RetValue; return RetValue;
} }
@ -579,8 +629,6 @@ DWORD STDCALL SearchPathW(LPCWSTR lpPath,
* On failure, zero. * On failure, zero.
*/ */
{ {
NTSTATUS errCode; NTSTATUS errCode;
DWORD retCode = 0; DWORD retCode = 0;
HANDLE FileHandle = NULL; HANDLE FileHandle = NULL;
@ -590,32 +638,30 @@ DWORD STDCALL SearchPathW(LPCWSTR lpPath,
WCHAR BufferW[MAX_PATH]; WCHAR BufferW[MAX_PATH];
WCHAR FileAndExtensionW[MAX_PATH]; WCHAR FileAndExtensionW[MAX_PATH];
WCHAR *EnvironmentBufferW = NULL; WCHAR *EnvironmentBufferW = NULL;
UNICODE_STRING PathString; UNICODE_STRING PathString;
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK IoStatusBlock; IO_STATUS_BLOCK IoStatusBlock;
dprintf("SearchPath\n"); dprintf("SearchPath\n");
if ( lpPath == NULL ) { if ( lpPath == NULL ) {
// check the directory from which the application loaded // check the directory from which the application loaded
if ( GetCurrentDirectoryW( MAX_PATH, BufferW ) > 0 ) { if ( GetCurrentDirectoryW( MAX_PATH, BufferW ) > 0 ) {
retCode = SearchPathW(BufferW,lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart ); retCode = SearchPathW(BufferW,lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart );
if ( retCode != 0 ) if ( retCode != 0 )
return retCode; return retCode;
} }
if ( GetSystemDirectoryW( BufferW, MAX_PATH ) > 0 ) { if ( GetSystemDirectoryW( BufferW, MAX_PATH ) > 0 ) {
retCode = SearchPathW(BufferW,lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart ); retCode = SearchPathW(BufferW,lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart );
if ( retCode != 0 ) if ( retCode != 0 )
return retCode; return retCode;
} }
if ( GetWindowsDirectoryW( BufferW, MAX_PATH ) > 0 ) { if ( GetWindowsDirectoryW( BufferW, MAX_PATH ) > 0 ) {
retCode = SearchPathW(BufferW,lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart ); retCode = SearchPathW(BufferW,lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart );
if ( retCode != 0 ) if ( retCode != 0 )
return retCode; return retCode;
} }
@ -630,17 +676,12 @@ DWORD STDCALL SearchPathW(LPCWSTR lpPath,
} }
i = 0; i = 0;
while ( retCode == 0 && i < j ) { while ( retCode == 0 && i < j ) {
if ( EnvironmentBufferW[i] != 0 ) if ( EnvironmentBufferW[i] != 0 )
retCode = SearchPathW(&EnvironmentBufferW[i],lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart ); retCode = SearchPathW(&EnvironmentBufferW[i],lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart );
i += lstrlenW(&EnvironmentBufferW[i]) + 1; i += lstrlenW(&EnvironmentBufferW[i]) + 1;
} }
HeapFree(GetProcessHeap(),0,EnvironmentBufferW);
HeapFree(GetProcessHeap(),0,EnvironmentBufferW);
return retCode; return retCode;
@ -665,14 +706,11 @@ DWORD STDCALL SearchPathW(LPCWSTR lpPath,
} }
else else
wcscpy(FileAndExtensionW,lpFileName); wcscpy(FileAndExtensionW,lpFileName);
lstrcatW(BufferW,L"\\??\\"); lstrcatW(BufferW,L"\\??\\");
lstrcatW(BufferW,lpPath); lstrcatW(BufferW,lpPath);
//printf("%S\n",FileAndExtensionW);
//printf("%S\n",FileAndExtensionW);
i = wcslen(BufferW); i = wcslen(BufferW);
if ( BufferW[i-1] != L'\\' ) { if ( BufferW[i-1] != L'\\' ) {
@ -686,14 +724,11 @@ DWORD STDCALL SearchPathW(LPCWSTR lpPath,
PathString.Buffer = BufferW; PathString.Buffer = BufferW;
PathString.Length = lstrlenW(PathString.Buffer)*sizeof(WCHAR); PathString.Length = lstrlenW(PathString.Buffer)*sizeof(WCHAR);
PathString.MaximumLength = PathString.Length + sizeof(WCHAR); PathString.MaximumLength = PathString.Length + sizeof(WCHAR);
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL; ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = &PathString; ObjectAttributes.ObjectName = &PathString;
ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT; ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT;
ObjectAttributes.SecurityDescriptor = NULL; ObjectAttributes.SecurityDescriptor = NULL;
ObjectAttributes.SecurityQualityOfService = NULL; ObjectAttributes.SecurityQualityOfService = NULL;
@ -702,11 +737,10 @@ DWORD STDCALL SearchPathW(LPCWSTR lpPath,
&FileHandle, &FileHandle,
GENERIC_ALL|FILE_LIST_DIRECTORY, GENERIC_ALL|FILE_LIST_DIRECTORY,
&ObjectAttributes, &ObjectAttributes,
&IoStatusBlock, &IoStatusBlock,
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
0 0
); );
if ( !NT_SUCCESS(errCode) ) { if ( !NT_SUCCESS(errCode) ) {
return 0; return 0;
@ -714,7 +748,7 @@ DWORD STDCALL SearchPathW(LPCWSTR lpPath,
else { else {
NtClose(FileHandle); NtClose(FileHandle);
wcscpy(lpBuffer,&BufferW[4]); wcscpy(lpBuffer,&BufferW[4]);
*lpFilePart = wcsrchr(lpBuffer,'\\')+1; *lpFilePart = wcsrchr(lpBuffer,'\\')+1;
} }
} }