Module: wine Branch: master Commit: ca7a1139a8f690d4a6c130b2233092aa977939f8 URL: https://gitlab.winehq.org/wine/wine/-/commit/ca7a1139a8f690d4a6c130b2233092a...
Author: Piotr Caban piotr@codeweavers.com Date: Tue Nov 21 10:23:54 2023 +0100
msvcrt: Factor out env_get_index helper.
---
dlls/msvcrt/environ.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/dlls/msvcrt/environ.c b/dlls/msvcrt/environ.c index 2c2a3353582..f0c3705a030 100644 --- a/dlls/msvcrt/environ.c +++ b/dlls/msvcrt/environ.c @@ -25,25 +25,28 @@
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
-static char * getenv_helper(const char *name) +static int env_get_index(const char *name) { - char **env; - size_t len; + int i, len;
- if (!name) return NULL; len = strlen(name); - - for (env = MSVCRT__environ; *env; env++) + for (i = 0; MSVCRT__environ[i]; i++) { - char *str = *env; - char *pos = strchr(str,'='); - if (pos && ((pos - str) == len) && !_strnicmp(str, name, len)) - { - TRACE("(%s): got %s\n", debugstr_a(name), debugstr_a(pos + 1)); - return pos + 1; - } + if (!strncmp(name, MSVCRT__environ[i], len) && MSVCRT__environ[i][len] == '=') + return i; } - return NULL; + return i; +} + +static char * getenv_helper(const char *name) +{ + int idx; + + if (!name) return NULL; + + idx = env_get_index(name); + if (!MSVCRT__environ[idx]) return NULL; + return strchr(MSVCRT__environ[idx], '=') + 1; }
/*********************************************************************