4 /* uses get_registry_path to replace patterns */
5 HRESULT
create_reg_entries(const HKEY root
, reg_value
const info
[])
10 for (i
= 0; NULL
!= info
[i
].path
; ++i
) {
11 char path
[MAX_REGISTRY_PATH
];
12 char name
[MAX_REGISTRY_PATH
], *regname
= NULL
;
13 char value
[MAX_REGISTRY_PATH
], *regvalue
= NULL
;
18 get_registry_path(info
[i
].path
, path
);
19 result
= RegCreateKeyEx(root
, path
,
20 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
,
22 if (ERROR_SUCCESS
!= result
)
25 regname
= get_registry_path(info
[i
].name
, name
);
26 regvalue
= get_registry_path(info
[i
].value
, value
);
29 * regname can legitimately be NULL,
30 * but if value is NULL, it's just a key
32 if (NULL
!= regvalue
) {
34 DWORD dwValue
= strtoul(regvalue
, &endptr
, 10);
35 if (endptr
&& !*endptr
)
36 result
= RegSetValueEx(key
, regname
, 0,
41 result
= RegSetValueEx(key
, regname
, 0,
44 (DWORD
)strlen(regvalue
));
48 if (ERROR_SUCCESS
!= result
)
55 static inline HRESULT
mask_errors(HRESULT
const result
)
58 case ERROR_FILE_NOT_FOUND
: return ERROR_SUCCESS
;
64 HRESULT
delete_reg_entries(HKEY
const root
, reg_value
const info
[])
69 /* count items in the array */
70 while (NULL
!= info
[i
].path
)
72 /* at this point, i is the __count__, so
73 make it an offset to the last element */
76 /* walk the array backwards (we're at the terminating triple-null) */
78 char path
[MAX_REGISTRY_PATH
];
83 get_registry_path(info
[i
].path
, path
);
85 if (info
[i
].name
|| info
[i
].value
) {
86 /* delete the value */
88 char name
[MAX_REGISTRY_PATH
], *regname
= NULL
;
90 result
= mask_errors(RegOpenKeyEx(root
, path
,
92 if (ERROR_SUCCESS
!= result
)
96 * some of our errors are masked (e.g. not found)
97 * don't work on this key if we could not open it
102 regname
= get_registry_path(info
[i
].name
, name
);
103 result
= mask_errors(RegDeleteValue(key
, regname
));
106 } else /* not the value, delete the key */
107 result
= mask_errors(RegDeleteKey(root
, path
));
109 if (ERROR_SUCCESS
!= result
)
113 return ERROR_SUCCESS
;