Piotr Caban : msvcrt: Don't duplicate _searchenv_s code in _searchenv.
Alexandre Julliard
julliard at winehq.org
Tue Jun 2 08:11:15 CDT 2020
Module: wine
Branch: stable
Commit: ea66b05c2b2a5c51f274360aa241779b2f0ce56f
URL: https://source.winehq.org/git/wine.git/?a=commit;h=ea66b05c2b2a5c51f274360aa241779b2f0ce56f
Author: Piotr Caban <piotr at codeweavers.com>
Date: Wed Jan 29 13:42:15 2020 +0100
msvcrt: Don't duplicate _searchenv_s code in _searchenv.
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit 98c554ac0617c642bc4481e6f56e0d66adec660a)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>
---
dlls/msvcrt/dir.c | 90 +++++--------------------------------------------------
1 file changed, 8 insertions(+), 82 deletions(-)
diff --git a/dlls/msvcrt/dir.c b/dlls/msvcrt/dir.c
index 806a2b0c85..83aff8bcb5 100644
--- a/dlls/msvcrt/dir.c
+++ b/dlls/msvcrt/dir.c
@@ -1640,88 +1640,6 @@ range:
return MSVCRT_ERANGE;
}
-/*********************************************************************
- * _searchenv (MSVCRT.@)
- *
- * Search for a file in a list of paths from an environment variable.
- *
- * PARAMS
- * file [I] Name of the file to search for.
- * env [I] Name of the environment variable containing a list of paths.
- * buf [O] Destination for the found file path.
- *
- * RETURNS
- * Nothing. If the file is not found, buf will contain an empty string
- * and errno is set.
- */
-void CDECL MSVCRT__searchenv(const char* file, const char* env, char *buf)
-{
- char*envVal, *penv, *end;
- char path[MAX_PATH];
- MSVCRT_size_t path_len, fname_len = strlen(file);
-
- *buf = '\0';
-
- /* Try CWD first */
- if (GetFileAttributesA( file ) != INVALID_FILE_ATTRIBUTES)
- {
- GetFullPathNameA( file, MAX_PATH, buf, NULL );
- return;
- }
-
- /* Search given environment variable */
- envVal = MSVCRT_getenv(env);
- if (!envVal)
- {
- msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
- return;
- }
-
- penv = envVal;
- TRACE(":searching for %s in paths %s\n", file, envVal);
-
- for(; *penv; penv = (*end ? end + 1 : end))
- {
- end = penv;
- path_len = 0;
- while(*end && *end != ';' && path_len < MAX_PATH)
- {
- if (*end == '"')
- {
- end++;
- while(*end && *end != '"' && path_len < MAX_PATH)
- {
- path[path_len++] = *end;
- end++;
- }
- if (*end == '"') end++;
- continue;
- }
-
- path[path_len++] = *end;
- end++;
- }
- if (!path_len || path_len >= MAX_PATH)
- continue;
-
- if (path[path_len - 1] != '/' && path[path_len - 1] != '\\')
- path[path_len++] = '\\';
- if (path_len + fname_len >= MAX_PATH)
- continue;
-
- memcpy(path + path_len, file, fname_len + 1);
- TRACE("Checking for file %s\n", path);
- if (GetFileAttributesA( path ) != INVALID_FILE_ATTRIBUTES)
- {
- memcpy(buf, path, path_len + fname_len + 1);
- return;
- }
- }
-
- msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
- return;
-}
-
/*********************************************************************
* _searchenv_s (MSVCRT.@)
*/
@@ -1807,6 +1725,14 @@ int CDECL MSVCRT__searchenv_s(const char* file, const char* env, char *buf, MSVC
return MSVCRT_ENOENT;
}
+/*********************************************************************
+ * _searchenv (MSVCRT.@)
+ */
+void CDECL MSVCRT__searchenv(const char* file, const char* env, char *buf)
+{
+ MSVCRT__searchenv_s(file, env, buf, MAX_PATH);
+}
+
/*********************************************************************
* _wsearchenv (MSVCRT.@)
*
More information about the wine-cvs
mailing list