https://git.reactos.org/?p=reactos.git;a=commitdiff;h=fcd83242d4e20e86b54de…
commit fcd83242d4e20e86b54dec7f7c7091f997a537fe
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Sun Sep 13 10:03:58 2020 +0200
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Fri Sep 25 09:45:54 2020 +0200
[KERNEL32] Move some functions into a static library to be shared between kernel32 and
kernel32_vista
---
dll/win32/kernel32/CMakeLists.txt | 10 +-
dll/win32/kernel32/client/except.c | 15 ---
dll/win32/kernel32/client/file/fileinfo.c | 150 --------------------------
dll/win32/kernel32/client/file/fileutils.c | 167 +++++++++++++++++++++++++++++
dll/win32/kernel32/client/shared_utils.c | 30 ++++++
5 files changed, 206 insertions(+), 166 deletions(-)
diff --git a/dll/win32/kernel32/CMakeLists.txt b/dll/win32/kernel32/CMakeLists.txt
index 984cb8eaa0d..616e0f453b5 100644
--- a/dll/win32/kernel32/CMakeLists.txt
+++ b/dll/win32/kernel32/CMakeLists.txt
@@ -5,6 +5,14 @@ add_definitions(-D_KERNEL32_)
include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/subsys)
spec2def(kernel32.dll kernel32.spec ADD_IMPORTLIB)
+# Shared between kernel32 and kernel32_vista
+add_library(kernel32_shared
+ client/shared_utils.c
+ client/file/fileutils.c
+)
+
+add_dependencies(kernel32_shared psdk)
+
list(APPEND SOURCE
client/actctx.c
client/appcache.c
@@ -114,7 +122,7 @@ set_module_type(kernel32 win32dll ENTRYPOINT DllMain 12)
set_subsystem(kernel32 console)
################# END HACK #################
-target_link_libraries(kernel32 wine chkstk ${PSEH_LIB})
+target_link_libraries(kernel32 kernel32_shared wine chkstk ${PSEH_LIB})
add_importlibs(kernel32 ntdll)
add_pch(kernel32 k32.h SOURCE)
add_dependencies(kernel32 psdk errcodes asm)
diff --git a/dll/win32/kernel32/client/except.c b/dll/win32/kernel32/client/except.c
index dbb76b7be49..36fab314f49 100644
--- a/dll/win32/kernel32/client/except.c
+++ b/dll/win32/kernel32/client/except.c
@@ -1036,21 +1036,6 @@ SetLastError(IN DWORD dwErrCode)
if (NtCurrentTeb()->LastErrorValue != dwErrCode) NtCurrentTeb()->LastErrorValue
= dwErrCode;
}
-/*
- * @implemented
- */
-DWORD
-WINAPI
-BaseSetLastNTError(IN NTSTATUS Status)
-{
- DWORD dwErrCode;
-
- /* Convert from NT to Win32, then set */
- dwErrCode = RtlNtStatusToDosError(Status);
- SetLastError(dwErrCode);
- return dwErrCode;
-}
-
/*
* @implemented
*/
diff --git a/dll/win32/kernel32/client/file/fileinfo.c
b/dll/win32/kernel32/client/file/fileinfo.c
index 2721c826315..b70a99a137c 100644
--- a/dll/win32/kernel32/client/file/fileinfo.c
+++ b/dll/win32/kernel32/client/file/fileinfo.c
@@ -18,156 +18,6 @@ DEBUG_CHANNEL(kernel32file);
/* FUNCTIONS ****************************************************************/
-PWCHAR
-FilenameA2W(LPCSTR NameA, BOOL alloc)
-{
- ANSI_STRING str;
- UNICODE_STRING strW;
- PUNICODE_STRING pstrW;
- NTSTATUS Status;
-
- //ASSERT(NtCurrentTeb()->StaticUnicodeString.Buffer ==
NtCurrentTeb()->StaticUnicodeBuffer);
- ASSERT(NtCurrentTeb()->StaticUnicodeString.MaximumLength ==
sizeof(NtCurrentTeb()->StaticUnicodeBuffer));
-
- RtlInitAnsiString(&str, NameA);
- pstrW = alloc ? &strW : &NtCurrentTeb()->StaticUnicodeString;
-
- if (bIsFileApiAnsi)
- Status= RtlAnsiStringToUnicodeString( pstrW, &str, (BOOLEAN)alloc );
- else
- Status= RtlOemStringToUnicodeString( pstrW, &str, (BOOLEAN)alloc );
-
- if (NT_SUCCESS(Status))
- return pstrW->Buffer;
-
- if (Status== STATUS_BUFFER_OVERFLOW)
- SetLastError( ERROR_FILENAME_EXCED_RANGE );
- else
- BaseSetLastNTError(Status);
-
- return NULL;
-}
-
-
-/*
-No copy/conversion is done if the dest. buffer is too small.
-
-Returns:
- Success: number of TCHARS copied into dest. buffer NOT including nullterm
- Fail: size of buffer in TCHARS required to hold the converted filename, including
nullterm
-*/
-DWORD
-FilenameU2A_FitOrFail(
- LPSTR DestA,
- INT destLen, /* buffer size in TCHARS incl. nullchar */
- PUNICODE_STRING SourceU
- )
-{
- DWORD ret;
-
- /* destLen should never exceed MAX_PATH */
- if (destLen > MAX_PATH) destLen = MAX_PATH;
-
- ret = bIsFileApiAnsi? RtlUnicodeStringToAnsiSize(SourceU) :
RtlUnicodeStringToOemSize(SourceU);
- /* ret incl. nullchar */
-
- if (DestA && (INT)ret <= destLen)
- {
- ANSI_STRING str;
-
- str.Buffer = DestA;
- str.MaximumLength = (USHORT)destLen;
-
-
- if (bIsFileApiAnsi)
- RtlUnicodeStringToAnsiString(&str, SourceU, FALSE );
- else
- RtlUnicodeStringToOemString(&str, SourceU, FALSE );
-
- ret = str.Length; /* SUCCESS: length without terminating 0 */
- }
-
- return ret;
-}
-
-
-/*
-No copy/conversion is done if the dest. buffer is too small.
-
-Returns:
- Success: number of TCHARS copied into dest. buffer NOT including nullterm
- Fail: size of buffer in TCHARS required to hold the converted filename, including
nullterm
-*/
-DWORD
-FilenameW2A_FitOrFail(
- LPSTR DestA,
- INT destLen, /* buffer size in TCHARS incl. nullchar */
- LPCWSTR SourceW,
- INT sourceLen /* buffer size in TCHARS incl. nullchar */
- )
-{
- UNICODE_STRING strW;
-
- if (sourceLen < 0) sourceLen = wcslen(SourceW) + 1;
-
- strW.Buffer = (PWCHAR)SourceW;
- strW.MaximumLength = sourceLen * sizeof(WCHAR);
- strW.Length = strW.MaximumLength - sizeof(WCHAR);
-
- return FilenameU2A_FitOrFail(DestA, destLen, &strW);
-}
-
-
-/*
-Return: num. TCHARS copied into dest including nullterm
-*/
-DWORD
-FilenameA2W_N(
- LPWSTR dest,
- INT destlen, /* buffer size in TCHARS incl. nullchar */
- LPCSTR src,
- INT srclen /* buffer size in TCHARS incl. nullchar */
- )
-{
- DWORD ret;
-
- if (srclen < 0) srclen = strlen( src ) + 1;
-
- if (bIsFileApiAnsi)
- RtlMultiByteToUnicodeN( dest, destlen* sizeof(WCHAR), &ret, (LPSTR)src,
srclen );
- else
- RtlOemToUnicodeN( dest, destlen* sizeof(WCHAR), &ret, (LPSTR)src, srclen );
-
- if (ret) dest[(ret/sizeof(WCHAR))-1]=0;
-
- return ret/sizeof(WCHAR);
-}
-
-/*
-Return: num. TCHARS copied into dest including nullterm
-*/
-DWORD
-FilenameW2A_N(
- LPSTR dest,
- INT destlen, /* buffer size in TCHARS incl. nullchar */
- LPCWSTR src,
- INT srclen /* buffer size in TCHARS incl. nullchar */
- )
-{
- DWORD ret;
-
- if (srclen < 0) srclen = wcslen( src ) + 1;
-
- if (bIsFileApiAnsi)
- RtlUnicodeToMultiByteN( dest, destlen, &ret, (LPWSTR) src, srclen *
sizeof(WCHAR));
- else
- RtlUnicodeToOemN( dest, destlen, &ret, (LPWSTR) src, srclen * sizeof(WCHAR)
);
-
- if (ret) dest[ret-1]=0;
-
- return ret;
-}
-
/*
* @implemented
*/
diff --git a/dll/win32/kernel32/client/file/fileutils.c
b/dll/win32/kernel32/client/file/fileutils.c
new file mode 100644
index 00000000000..078f83006e2
--- /dev/null
+++ b/dll/win32/kernel32/client/file/fileutils.c
@@ -0,0 +1,167 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS system libraries
+ * FILE: dll/win32/kernel32/client/file/fileutils.c
+ * PURPOSE: File utility function shared with kernel32_vista
+ * PROGRAMMER: Taken from wine
+ */
+
+/* INCLUDES *****************************************************************/
+
+#include <k32.h>
+#define NDEBUG
+#include <debug.h>
+
+/* FUNCTIONS ****************************************************************/
+
+PWCHAR
+FilenameA2W(LPCSTR NameA, BOOL alloc)
+{
+ ANSI_STRING str;
+ UNICODE_STRING strW;
+ PUNICODE_STRING pstrW;
+ NTSTATUS Status;
+
+ //ASSERT(NtCurrentTeb()->StaticUnicodeString.Buffer ==
NtCurrentTeb()->StaticUnicodeBuffer);
+ ASSERT(NtCurrentTeb()->StaticUnicodeString.MaximumLength ==
sizeof(NtCurrentTeb()->StaticUnicodeBuffer));
+
+ RtlInitAnsiString(&str, NameA);
+ pstrW = alloc ? &strW : &NtCurrentTeb()->StaticUnicodeString;
+
+ if (bIsFileApiAnsi)
+ Status= RtlAnsiStringToUnicodeString( pstrW, &str, (BOOLEAN)alloc );
+ else
+ Status= RtlOemStringToUnicodeString( pstrW, &str, (BOOLEAN)alloc );
+
+ if (NT_SUCCESS(Status))
+ return pstrW->Buffer;
+
+ if (Status== STATUS_BUFFER_OVERFLOW)
+ SetLastError( ERROR_FILENAME_EXCED_RANGE );
+ else
+ BaseSetLastNTError(Status);
+
+ return NULL;
+}
+
+
+/*
+No copy/conversion is done if the dest. buffer is too small.
+
+Returns:
+ Success: number of TCHARS copied into dest. buffer NOT including nullterm
+ Fail: size of buffer in TCHARS required to hold the converted filename, including
nullterm
+*/
+DWORD
+FilenameU2A_FitOrFail(
+ LPSTR DestA,
+ INT destLen, /* buffer size in TCHARS incl. nullchar */
+ PUNICODE_STRING SourceU
+ )
+{
+ DWORD ret;
+
+ /* destLen should never exceed MAX_PATH */
+ if (destLen > MAX_PATH) destLen = MAX_PATH;
+
+ ret = bIsFileApiAnsi? RtlUnicodeStringToAnsiSize(SourceU) :
RtlUnicodeStringToOemSize(SourceU);
+ /* ret incl. nullchar */
+
+ if (DestA && (INT)ret <= destLen)
+ {
+ ANSI_STRING str;
+
+ str.Buffer = DestA;
+ str.MaximumLength = (USHORT)destLen;
+
+
+ if (bIsFileApiAnsi)
+ RtlUnicodeStringToAnsiString(&str, SourceU, FALSE );
+ else
+ RtlUnicodeStringToOemString(&str, SourceU, FALSE );
+
+ ret = str.Length; /* SUCCESS: length without terminating 0 */
+ }
+
+ return ret;
+}
+
+
+/*
+No copy/conversion is done if the dest. buffer is too small.
+
+Returns:
+ Success: number of TCHARS copied into dest. buffer NOT including nullterm
+ Fail: size of buffer in TCHARS required to hold the converted filename, including
nullterm
+*/
+DWORD
+FilenameW2A_FitOrFail(
+ LPSTR DestA,
+ INT destLen, /* buffer size in TCHARS incl. nullchar */
+ LPCWSTR SourceW,
+ INT sourceLen /* buffer size in TCHARS incl. nullchar */
+ )
+{
+ UNICODE_STRING strW;
+
+ if (sourceLen < 0) sourceLen = wcslen(SourceW) + 1;
+
+ strW.Buffer = (PWCHAR)SourceW;
+ strW.MaximumLength = sourceLen * sizeof(WCHAR);
+ strW.Length = strW.MaximumLength - sizeof(WCHAR);
+
+ return FilenameU2A_FitOrFail(DestA, destLen, &strW);
+}
+
+
+/*
+Return: num. TCHARS copied into dest including nullterm
+*/
+DWORD
+FilenameA2W_N(
+ LPWSTR dest,
+ INT destlen, /* buffer size in TCHARS incl. nullchar */
+ LPCSTR src,
+ INT srclen /* buffer size in TCHARS incl. nullchar */
+ )
+{
+ DWORD ret;
+
+ if (srclen < 0) srclen = strlen( src ) + 1;
+
+ if (bIsFileApiAnsi)
+ RtlMultiByteToUnicodeN( dest, destlen* sizeof(WCHAR), &ret, (LPSTR)src,
srclen );
+ else
+ RtlOemToUnicodeN( dest, destlen* sizeof(WCHAR), &ret, (LPSTR)src, srclen );
+
+ if (ret) dest[(ret/sizeof(WCHAR))-1]=0;
+
+ return ret/sizeof(WCHAR);
+}
+
+/*
+Return: num. TCHARS copied into dest including nullterm
+*/
+DWORD
+FilenameW2A_N(
+ LPSTR dest,
+ INT destlen, /* buffer size in TCHARS incl. nullchar */
+ LPCWSTR src,
+ INT srclen /* buffer size in TCHARS incl. nullchar */
+ )
+{
+ DWORD ret;
+
+ if (srclen < 0) srclen = wcslen( src ) + 1;
+
+ if (bIsFileApiAnsi)
+ RtlUnicodeToMultiByteN( dest, destlen, &ret, (LPWSTR) src, srclen *
sizeof(WCHAR));
+ else
+ RtlUnicodeToOemN( dest, destlen, &ret, (LPWSTR) src, srclen * sizeof(WCHAR)
);
+
+ if (ret) dest[ret-1]=0;
+
+ return ret;
+}
+
+/* EOF */
diff --git a/dll/win32/kernel32/client/shared_utils.c
b/dll/win32/kernel32/client/shared_utils.c
new file mode 100644
index 00000000000..05b10675e72
--- /dev/null
+++ b/dll/win32/kernel32/client/shared_utils.c
@@ -0,0 +1,30 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS system libraries
+ * FILE: dll/win32/kernel32/client/utils_shared.c
+ * PURPOSE: Utility functions shared with kernel32_vista
+ * PROGRAMMER: Thomas Faber
+*/
+
+/* INCLUDES *******************************************************************/
+
+#include <k32.h>
+#include <strsafe.h>
+
+#define NDEBUG
+#include <debug.h>
+
+/*
+* @implemented
+*/
+DWORD
+WINAPI
+BaseSetLastNTError(IN NTSTATUS Status)
+{
+ DWORD dwErrCode;
+
+ /* Convert from NT to Win32, then set */
+ dwErrCode = RtlNtStatusToDosError(Status);
+ SetLastError(dwErrCode);
+ return dwErrCode;
+}