From 5a22e5bcf080f86711c2d5d3435654e99da21eca Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Tue, 25 May 2004 20:04:14 +0000 Subject: [PATCH] - Fixed definition of assert macro. - Fixed few DPRINTs to compile. - Handle OF_CREATE flag of OpenFile. svn path=/trunk/; revision=9492 --- reactos/lib/kernel32/file/file.c | 65 +++++++++++++++++++--------- reactos/lib/kernel32/include/debug.h | 2 +- reactos/lib/kernel32/mem/section.c | 6 +-- 3 files changed, 49 insertions(+), 24 deletions(-) diff --git a/reactos/lib/kernel32/file/file.c b/reactos/lib/kernel32/file/file.c index 80d24faea74..7c50bcaaa2a 100644 --- a/reactos/lib/kernel32/file/file.c +++ b/reactos/lib/kernel32/file/file.c @@ -1,4 +1,4 @@ -/* $Id: file.c,v 1.53 2004/03/18 18:29:18 weiden Exp $ +/* $Id: file.c,v 1.54 2004/05/25 20:04:13 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -89,19 +89,22 @@ OpenFile(LPCSTR lpFileName, RtlAnsiStringToUnicodeString (&FileNameU, &FileName, TRUE); else RtlOemStringToUnicodeString (&FileNameU, &FileName, TRUE); - - Len = SearchPathW (NULL, - FileNameU.Buffer, - NULL, - OFS_MAXPATHNAME, - PathNameW, - &FilePart); - - RtlFreeUnicodeString(&FileNameU); - - if (Len == 0 || Len > OFS_MAXPATHNAME) + + if ((uStyle & OF_CREATE) == 0) { - return (HFILE)INVALID_HANDLE_VALUE; + Len = SearchPathW (NULL, + FileNameU.Buffer, + NULL, + OFS_MAXPATHNAME, + PathNameW, + &FilePart); + + RtlFreeUnicodeString(&FileNameU); + + if (Len == 0 || Len > OFS_MAXPATHNAME) + { + return (HFILE)INVALID_HANDLE_VALUE; + } } FileName.Buffer = lpReOpenBuff->szPathName; @@ -124,13 +127,6 @@ OpenFile(LPCSTR lpFileName, return (HFILE)INVALID_HANDLE_VALUE; } - ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); - ObjectAttributes.RootDirectory = NULL; - ObjectAttributes.ObjectName = &FileNameString; - ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT; - ObjectAttributes.SecurityDescriptor = NULL; - ObjectAttributes.SecurityQualityOfService = NULL; - // FILE_SHARE_READ // FILE_NO_INTERMEDIATE_BUFFERING @@ -140,6 +136,35 @@ OpenFile(LPCSTR lpFileName, return (HFILE)NULL; } + if ((uStyle & OF_CREATE) == OF_CREATE) + { + DWORD Sharing; + switch (uStyle & 0x70) + { + case OF_SHARE_EXCLUSIVE: Sharing = 0; break; + case OF_SHARE_DENY_WRITE: Sharing = FILE_SHARE_READ; break; + case OF_SHARE_DENY_READ: Sharing = FILE_SHARE_WRITE; break; + case OF_SHARE_DENY_NONE: + case OF_SHARE_COMPAT: + default: + Sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; + } + return (HFILE) CreateFileA (lpFileName, + GENERIC_READ | GENERIC_WRITE, + Sharing, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + 0); + } + + ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); + ObjectAttributes.RootDirectory = NULL; + ObjectAttributes.ObjectName = &FileNameString; + ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT; + ObjectAttributes.SecurityDescriptor = NULL; + ObjectAttributes.SecurityQualityOfService = NULL; + errCode = NtOpenFile (&FileHandle, GENERIC_READ|SYNCHRONIZE, &ObjectAttributes, diff --git a/reactos/lib/kernel32/include/debug.h b/reactos/lib/kernel32/include/debug.h index 45a87555015..a0ddb9833f4 100644 --- a/reactos/lib/kernel32/include/debug.h +++ b/reactos/lib/kernel32/include/debug.h @@ -16,7 +16,7 @@ #ifdef assert #undef assert #endif -#define assert(x) do { if(!x) RtlAssert(x, __FILE__,__LINE__, ""); } while(0); +#define assert(x) do { if(!x) RtlAssert("#x", __FILE__,__LINE__, ""); } while(0); #endif #define DPRINT1(args...) do { DbgPrint("(KERNEL32:%s:%d) ",__FILE__,__LINE__); DbgPrint(args); } while(0); diff --git a/reactos/lib/kernel32/mem/section.c b/reactos/lib/kernel32/mem/section.c index fcc397a4939..5590c377328 100644 --- a/reactos/lib/kernel32/mem/section.c +++ b/reactos/lib/kernel32/mem/section.c @@ -1,4 +1,4 @@ -/* $Id: section.c,v 1.24 2004/02/08 10:42:15 jfilby Exp $ +/* $Id: section.c,v 1.25 2004/05/25 20:04:14 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -66,7 +66,7 @@ CreateFileMappingA(HANDLE hFile, FileStandardInformation); if (!NT_SUCCESS(Status)) { - DPRINT("Status 0x%08x obtaining FileStandardInformation for source\n", errCode); + DPRINT("Status 0x%08x obtaining FileStandardInformation for source\n", Status); SetLastErrorByStatus(Status); return NULL; } @@ -149,7 +149,7 @@ CreateFileMappingW(HANDLE hFile, FileStandardInformation); if (!NT_SUCCESS(Status)) { - DPRINT("Status 0x%08x obtaining FileStandardInformation for source\n", errCode); + DPRINT("Status 0x%08x obtaining FileStandardInformation for source\n", Status); SetLastErrorByStatus(Status); return NULL; }