[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wine-devel
Subject:    Re: [PATCH 2/6] reg: Add path/key conversion functions
From:       Stefan Dösinger <stefandoesinger () gmail ! com>
Date:       2014-10-27 23:26:49
Message-ID: 544ED4B9.6000300 () gmail ! com
[Download RAW message or body]

-----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).

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJUTtS5AAoJEN0/YqbEcdMw+kEP/0DwI2fMgk2o6bKh1mCVwzeg
AFH+EKh1pAwpHBmIRHX7XzyDBAusd0GVH0+B5WQFnl+Fr49ybYqp8CGfytqm0H/e
lgqS0SCDZjaDTI5WO5zT/L5/VGhQ5tQHSQJiHS3UhXX3IBDXd7aYcbreSMHNcyJ8
ZPaFmVVCH8iRiR4qqMS8cJKXPxzx5tg5Ec9TpXfyYraI8YDPTNPOGlUipl9m5kwa
lrqjD+TbGbCOczq1mx6WSJnVxKWboWhz3FnzYDM0C8PzpJlRyzODWlfUHVMSLSmQ
xu9K/lXl2XJpmXbjFsCPZ5C4K3pRVH3poAtPNs+yOEeHkWTE2Pf3uyKNBwpW4ONU
3PFhn0beJM1scJY/LRjpCWLi74xA+FdBq6WDuxx2BpMoDvKCe/zV+LEY6zbymtxY
OsXQXXQwpcVBAC3mWQK0EWce8g2/he4PoPi8/l4ZakkCEAF4dqtdfSEQAccf9KfV
EeI8PJOAZRLoKAUQgKse2mYHG8V4EJEp8IQA0HcuWgR9zEMTpIUt08xdmU5cIWfu
Ena2T9phlAWmDIjcgr9haIHEreZkMI8DZI07XOmVAlZL44rSdkVop816I/ItTE98
CTwU6N0pD/V4htZcwWN7ZVojPK4AA7UD9NW7sg326drl2KIpk5j0ZmYq0/WwSL2o
uS2pHS9eKgBarX7GCXyd
=k2ys
-----END PGP SIGNATURE-----


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic