https://git.reactos.org/?p=reactos.git;a=commitdiff;h=cc37199dfd615ee58843175e1a9c22feb1bffa64

commit cc37199dfd615ee58843175e1a9c22feb1bffa64
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Mon Aug 21 19:14:33 2017 +0000
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Sat Oct 27 18:13:39 2018 +0200

    [SETUPLIB] Merge DoesPathExist() and DoesFileExist() into (temporarily 
called) DoesPathExistEx() function.
    
    And turn the previous two functions into macros.
    
    svn path=/branches/setup_improvements/; revision=75635
    svn path=/branches/setup_improvements/; revision=75652
---
 base/setup/lib/filesup.c | 59 ++++++++++++++----------------------------------
 base/setup/lib/filesup.h | 14 +++++++-----
 2 files changed, 25 insertions(+), 48 deletions(-)

diff --git a/base/setup/lib/filesup.c b/base/setup/lib/filesup.c
index 03d1ad8003..44a869821a 100644
--- a/base/setup/lib/filesup.c
+++ b/base/setup/lib/filesup.c
@@ -8,6 +8,7 @@
 /* INCLUDES *****************************************************************/
 
 #include "precomp.h"
+#include "filesup.h"
 
 #define NDEBUG
 #include <debug.h>
@@ -580,19 +581,17 @@ CombinePaths(
     return Status;
 }
 
-//
-// NOTE: It may be possible to merge both DoesPathExist and DoesFileExist...
-//
 BOOLEAN
-DoesPathExist(
+DoesPathExistEx(
     IN HANDLE RootDirectory OPTIONAL,
-    IN PCWSTR PathName)
+    IN PCWSTR PathName,
+    IN BOOLEAN IsDirectory)
 {
     NTSTATUS Status;
+    UNICODE_STRING Name;
     HANDLE FileHandle;
     OBJECT_ATTRIBUTES ObjectAttributes;
     IO_STATUS_BLOCK IoStatusBlock;
-    UNICODE_STRING Name;
 
     RtlInitUnicodeString(&Name, PathName);
 
@@ -603,48 +602,24 @@ DoesPathExist(
                                NULL);
 
     Status = NtOpenFile(&FileHandle,
-                        FILE_LIST_DIRECTORY | SYNCHRONIZE,
+                        IsDirectory ? (FILE_LIST_DIRECTORY | SYNCHRONIZE)
+                                    :  FILE_GENERIC_READ, // Contains 
SYNCHRONIZE
                         &ObjectAttributes,
                         &IoStatusBlock,
                         FILE_SHARE_READ | FILE_SHARE_WRITE,
-                        FILE_SYNCHRONOUS_IO_NONALERT | FILE_DIRECTORY_FILE);
-    if (NT_SUCCESS(Status))
-        NtClose(FileHandle);
-    else
-        DPRINT("Failed to open directory '%wZ', Status 0x%08lx\n", &Name, 
Status);
-
-    return NT_SUCCESS(Status);
-}
-
-BOOLEAN
-DoesFileExist(
-    IN HANDLE RootDirectory OPTIONAL,
-    IN PCWSTR PathNameToFile)
-{
-    NTSTATUS Status;
-    UNICODE_STRING FileName;
-    HANDLE FileHandle;
-    OBJECT_ATTRIBUTES ObjectAttributes;
-    IO_STATUS_BLOCK IoStatusBlock;
-
-    RtlInitUnicodeString(&FileName, PathNameToFile);
-
-    InitializeObjectAttributes(&ObjectAttributes,
-                               &FileName,
-                               OBJ_CASE_INSENSITIVE,
-                               RootDirectory,
-                               NULL);
-
-    Status = NtOpenFile(&FileHandle,
-                        FILE_GENERIC_READ, // Contains SYNCHRONIZE
-                        &ObjectAttributes,
-                        &IoStatusBlock,
-                        FILE_SHARE_READ | FILE_SHARE_WRITE,
-                        FILE_SYNCHRONOUS_IO_NONALERT | 
FILE_NON_DIRECTORY_FILE);
+                        FILE_SYNCHRONOUS_IO_NONALERT |
+                            (IsDirectory ? FILE_DIRECTORY_FILE
+                                         : FILE_NON_DIRECTORY_FILE));
     if (NT_SUCCESS(Status))
+    {
         NtClose(FileHandle);
+    }
     else
-        DPRINT("Failed to open file '%wZ', Status 0x%08lx\n", &FileName, 
Status);
+    {
+        DPRINT("Failed to open %s '%wZ', Status 0x%08lx\n",
+               IsDirectory ? "directory" : "file",
+               &Name, Status);
+    }
 
     return NT_SUCCESS(Status);
 }
diff --git a/base/setup/lib/filesup.h b/base/setup/lib/filesup.h
index 0b82069185..a9fabf4b2c 100644
--- a/base/setup/lib/filesup.h
+++ b/base/setup/lib/filesup.h
@@ -61,14 +61,16 @@ CombinePaths(
     IN /* PCWSTR */ ...);
 
 BOOLEAN
-DoesPathExist(
+DoesPathExistEx(
     IN HANDLE RootDirectory OPTIONAL,
-    IN PCWSTR PathName);
+    IN PCWSTR PathName,
+    IN BOOLEAN IsDirectory);
 
-BOOLEAN
-DoesFileExist(
-    IN HANDLE RootDirectory OPTIONAL,
-    IN PCWSTR PathNameToFile);
+#define DoesPathExist(RootDirectory, PathName)  \
+    DoesPathExistEx((RootDirectory), (PathName), TRUE)
+
+#define DoesFileExist(RootDirectory, FileName)  \
+    DoesPathExistEx((RootDirectory), (FileName), FALSE)
 
 // FIXME: DEPRECATED! HACKish function that needs to be deprecated!
 BOOLEAN

Reply via email to