-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Am 2014-10-27 13:10, schrieb Jonathan Vollebregt:
+#define ARRAY_COUNT(A) (sizeof(A)/sizeof(*A))
Other places that use a macro like this call it ARRAY_SIZE.
+typedef struct {
- HKEY key;
- const WCHAR *short_name;
- const WCHAR *long_name;
+} hkey_rel;
Style :-)
+static inline int path_rootname_cmp(const WCHAR *path, const WCHAR *name) +{
- DWORD length = strlenW(name);
- return (strncmpiW(path, name, length) == 0 && (path[length] == 0 || path[length] == '\'));
+}
I don't like the names "path" and "name". I wondered why you're relying on the length of name. A better name for "path" could be "input", but I can't think of anything for "name".
+static HKEY path_get_rootkey(const WCHAR *path) +{
- DWORD i;
- for (i = 0; i < ARRAY_COUNT(root_rels); i++)
- {
if (path_rootname_cmp(path, root_rels[i].short_name) ||
path_rootname_cmp(path, root_rels[i].long_name))
return root_rels[i].key;
- }
- reg_message(STRING_INVALID_KEY);
- return NULL;
+}
Is it a good idea to write an error message from deep inside a helper function? What happens when you just pass the NULL root to RegOpenKey? Can you tell the cases for STRING_INVALID_KEY and STRING_CANNOT_FIND apart base on the return value?
You could also consider a function that returns an error string ID for each advapi32 Reg* error result. Then you can propagate the advapi32 return codes to main() and write the error string there. Depending on the possible failure modes this may or may not be possible.
- path = strchrW(path, '\');
- if (!path)
return k;
I see that this is why you need the trailing backslash elimination in the previous patch. But still, do you need this? What happens when you call e.g. RegOpenKey(HKEY_CURRENT_USER, "\", &k)? If it returns HKEY_CURRENT_USER or a handle that points to HKEY_CURRENT_USER you're fine. Similarly for RegOpenKey(HKEY_CURRENT_USER, "", &k).