ReactOS  0.4.14-dev-77-gd9e7c48
RegDeleteTree.c File Reference
#include "advapi32_vista.h"
Include dependency graph for RegDeleteTree.c:

Go to the source code of this file.

Functions

static voidheap_alloc (size_t len) __WINE_ALLOC_SIZE(1)
 
static BOOL heap_free (void *mem)
 
LSTATUS WINAPI RegDeleteTreeW (HKEY hKey, LPCWSTR lpszSubKey)
 
LSTATUS WINAPI RegDeleteTreeA (HKEY hKey, LPCSTR lpszSubKey)
 

Function Documentation

◆ heap_alloc()

static void * heap_alloc ( size_t  len)
inlinestatic

Definition at line 6 of file RegDeleteTree.c.

7 {
8  return HeapAlloc( GetProcessHeap(), 0, len );
9 }
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
GLenum GLsizei len
Definition: glext.h:6722

Referenced by RegDeleteTreeW().

◆ heap_free()

static BOOL heap_free ( void mem)
inlinestatic

Definition at line 11 of file RegDeleteTree.c.

12 {
13  return HeapFree( GetProcessHeap(), 0, mem );
14 }
#define GetProcessHeap()
Definition: compat.h:395
Definition: mem.c:156
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by RegDeleteTreeW().

◆ RegDeleteTreeA()

LSTATUS WINAPI RegDeleteTreeA ( HKEY  hKey,
LPCSTR  lpszSubKey 
)

Definition at line 92 of file RegDeleteTree.c.

93 {
94  LONG ret;
95  UNICODE_STRING lpszSubKeyW;
96 
97  if (lpszSubKey) RtlCreateUnicodeStringFromAsciiz( &lpszSubKeyW, lpszSubKey);
98  else lpszSubKeyW.Buffer = NULL;
99  ret = RegDeleteTreeW( hKey, lpszSubKeyW.Buffer);
100  RtlFreeUnicodeString( &lpszSubKeyW );
101  return ret;
102 }
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeStringFromAsciiz(_Out_ PUNICODE_STRING Destination, _In_ PCSZ Source)
LSTATUS WINAPI RegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey)
Definition: RegDeleteTree.c:22
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
int ret

◆ RegDeleteTreeW()

LSTATUS WINAPI RegDeleteTreeW ( HKEY  hKey,
LPCWSTR  lpszSubKey 
)

Definition at line 22 of file RegDeleteTree.c.

23 {
24  LONG ret;
25  DWORD dwMaxSubkeyLen, dwMaxValueLen;
26  DWORD dwMaxLen, dwSize;
27  WCHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
28  HKEY hSubKey = hKey;
29 
30  if(lpszSubKey)
31  {
32  ret = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
33  if (ret) return ret;
34  }
35 
36  /* Get highest length for keys, values */
37  ret = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL,
38  &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
39  if (ret) goto cleanup;
40 
41  dwMaxSubkeyLen++;
42  dwMaxValueLen++;
43  dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
44  if (dwMaxLen > sizeof(szNameBuf)/sizeof(WCHAR))
45  {
46  /* Name too big: alloc a buffer for it */
47  if (!(lpszName = heap_alloc( dwMaxLen*sizeof(WCHAR))))
48  {
50  goto cleanup;
51  }
52  }
53 
54 
55  /* Recursively delete all the subkeys */
56  while (TRUE)
57  {
58  dwSize = dwMaxLen;
59  if (RegEnumKeyExW(hSubKey, 0, lpszName, &dwSize, NULL,
60  NULL, NULL, NULL)) break;
61 
62  ret = RegDeleteTreeW(hSubKey, lpszName);
63  if (ret) goto cleanup;
64  }
65 
66  if (lpszSubKey)
67  ret = RegDeleteKeyW(hKey, lpszSubKey);
68  else
69  while (TRUE)
70  {
71  dwSize = dwMaxLen;
72  if (RegEnumValueW(hKey, 0, lpszName, &dwSize,
73  NULL, NULL, NULL, NULL)) break;
74 
75  ret = RegDeleteValueW(hKey, lpszName);
76  if (ret) goto cleanup;
77  }
78 
79 cleanup:
80  /* Free buffer if allocated */
81  if (lpszName != szNameBuf)
82  heap_free( lpszName);
83  if(lpszSubKey)
84  RegCloseKey(hSubKey);
85  return ret;
86 }
#define max(a, b)
Definition: svc.c:63
#define TRUE
Definition: types.h:120
static BOOL heap_free(void *mem)
Definition: RegDeleteTree.c:11
#define KEY_READ
Definition: nt_native.h:1023
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1237
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
static void * heap_alloc(size_t len) __WINE_ALLOC_SIZE(1)
Definition: RegDeleteTree.c:6
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
long LONG
Definition: pedump.c:60
LONG WINAPI RegEnumValueW(_In_ HKEY hKey, _In_ DWORD index, _Out_ LPWSTR value, _Inout_ PDWORD val_count, _Reserved_ PDWORD reserved, _Out_opt_ PDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ PDWORD count)
Definition: reg.c:2853
smooth NULL
Definition: ftsmooth.c:416
LSTATUS WINAPI RegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey)
Definition: RegDeleteTree.c:22
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3686
int ret
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2355
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
char * cleanup(char *str)
Definition: wpickclick.c:99
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2527
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

Referenced by RegDeleteTreeA().