(4th) Janitorial dlls/advapi32/registry.c W->A cleanup
Tony Lambregts
tony_lambregts at telusplanet.net
Fri Mar 7 16:09:39 CST 2003
This one is implementaed using Dimi's wrapper function *asciiz_to_unicode
Change Log: Janitorial. Get rid of W->A calls
Files Changed: dlls/advapi32/registry.c
--
Tony Lambregts
-------------- next part --------------
Index: registry.c
===================================================================
RCS file: /home/wine/wine/dlls/advapi32/registry.c,v
retrieving revision 1.50
diff -u -r1.50 registry.c
--- registry.c 20 Jan 2003 23:23:12 -0000 1.50
+++ registry.c 7 Mar 2003 22:10:47 -0000
@@ -37,6 +37,8 @@
#include "wine/server.h"
#include "wine/debug.h"
#include "winternl.h"
+#include "thread.h"
+
WINE_DEFAULT_DEBUG_CHANNEL(reg);
@@ -139,6 +141,26 @@
return ret;
}
+/*
+ * asciiz_to_unicode (internal)
+ * Does not check for NULL. This is a duty of a higher level API.
+ */
+UNICODE_STRING *asciiz_to_unicode(LPCSTR src)
+{
+ UNICODE_STRING *unicode = &NtCurrentTeb()->StaticUnicodeString;
+ STRING ansi;
+ NTSTATUS status;
+
+ RtlInitAnsiString(&ansi, src);
+ status = RtlAnsiStringToUnicodeString(unicode, &ansi, FALSE);
+ if (!status) return unicode;
+
+ if (status == STATUS_BUFFER_OVERFLOW)
+ SetLastError(ERROR_FILENAME_EXCED_RANGE);
+ else
+ SetLastError(RtlNtStatusToDosError(status));
+ return NULL;
+}
/******************************************************************************
* RegCreateKeyExW [ADVAPI32.@]
@@ -1536,39 +1558,44 @@
/******************************************************************************
- * RegSaveKeyA [ADVAPI32.@]
+ * RegSaveKeyW [ADVAPI32.@]
*
* PARAMS
* hkey [I] Handle of key where save begins
* lpFile [I] Address of filename to save to
* sa [I] Address of security structure
*/
-LONG WINAPI RegSaveKeyA( HKEY hkey, LPCSTR file, LPSECURITY_ATTRIBUTES sa )
+LONG WINAPI RegSaveKeyW( HKEY hkey, LPCWSTR file, LPSECURITY_ATTRIBUTES sa )
{
- char buffer[1024];
+ WCHAR buffer[1024];
int count = 0;
- LPSTR name;
- DWORD ret, err;
+ LPWSTR nameW;
+ char *nameA;
+ DWORD ret, err, len;
HANDLE handle;
- TRACE( "(%p,%s,%p)\n", hkey, debugstr_a(file), sa );
+ TRACE( "(%p,%s,%p)\n", hkey, debugstr_w(file), sa );
if (!file || !*file) return ERROR_INVALID_PARAMETER;
if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
err = GetLastError();
- GetFullPathNameA( file, sizeof(buffer), buffer, &name );
+ GetFullPathNameW( file, sizeof(buffer), buffer, &nameW );
+ len = WideCharToMultiByte(CP_ACP, 0, nameW, -1, NULL, 0, NULL, NULL);
+ nameA = HeapAlloc(GetProcessHeap(), 0, len);
+ WideCharToMultiByte(CP_ACP, 0, nameW, -1, nameA, len, NULL, NULL);
+
for (;;)
{
- sprintf( name, "reg%04x.tmp", count++ );
- handle = CreateFileA( buffer, GENERIC_WRITE, 0, NULL,
+ sprintf( nameA, "reg%04x.tmp", count++ );
+ handle = CreateFileW( buffer, GENERIC_WRITE, 0, NULL,
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
if (handle != INVALID_HANDLE_VALUE) break;
if ((ret = GetLastError()) != ERROR_ALREADY_EXISTS) goto done;
/* Something gone haywire ? Please report if this happens abnormally */
if (count >= 100)
- MESSAGE("Wow, we are already fiddling with a temp file %s with an ordinal as high as %d !\nYou might want to delete all corresponding temp files in that directory.\n", buffer, count);
+ MESSAGE("Wow, we are already fiddling with a temp file %s with an ordinal as high as %d !\nYou might want to delete all corresponding temp files in that directory.\n", debugstr_w(buffer), count);
}
SERVER_START_REQ( save_registry )
@@ -1582,29 +1609,40 @@
CloseHandle( handle );
if (!ret)
{
- if (!MoveFileExA( buffer, file, MOVEFILE_REPLACE_EXISTING ))
+ if (!MoveFileExW( buffer, file, MOVEFILE_REPLACE_EXISTING ))
{
- ERR( "Failed to move %s to %s\n", buffer, file );
+ ERR( "Failed to move %s to %s\n", debugstr_w(buffer),
+ debugstr_w(file) );
ret = GetLastError();
}
}
- if (ret) DeleteFileA( buffer );
+ if (ret) DeleteFileW( buffer );
done:
+ HeapFree( GetProcessHeap(), 0, nameA );
SetLastError( err ); /* restore last error code */
return ret;
}
/******************************************************************************
- * RegSaveKeyW [ADVAPI32.@]
+ * RegSaveKeyA [ADVAPI32.@]
*/
-LONG WINAPI RegSaveKeyW( HKEY hkey, LPCWSTR file, LPSECURITY_ATTRIBUTES sa )
+LONG WINAPI RegSaveKeyA( HKEY hkey, LPCSTR file, LPSECURITY_ATTRIBUTES sa )
{
- LPSTR fileA = HEAP_strdupWtoA( GetProcessHeap(), 0, file );
- DWORD ret = RegSaveKeyA( hkey, fileA, sa );
- if (fileA) HeapFree( GetProcessHeap(), 0, fileA );
- return ret;
+
+ UNICODE_STRING *fileW;
+
+ if (!file || !*file)
+ {
+ SetLastError(ERROR_PATH_NOT_FOUND);
+ return FALSE;
+ }
+
+ fileW = asciiz_to_unicode(file);
+ if (fileW) return RegSaveKeyW(hkey, fileW->Buffer, sa);
+ return FALSE;
+
}
@@ -1819,7 +1857,7 @@
if (!lpMachineName || !*lpMachineName) {
/* Use the local machine name */
- return RegOpenKeyA( hKey, "", phkResult );
+ return RegOpenKeyW( hKey, NULL, phkResult );
}
FIXME("Cannot connect to %s\n",debugstr_w(lpMachineName));
More information about the wine-patches
mailing list