[PATCH 07/14] [Msvcrt*]: implemented (w)searchenv_s
Eric Pouech
eric.pouech at orange.fr
Tue Nov 2 16:03:17 CDT 2010
A+
---
dlls/msvcr100/msvcr100.spec | 4 +
dlls/msvcr80/msvcr80.spec | 4 +
dlls/msvcr90/msvcr90.spec | 4 +
dlls/msvcrt/dir.c | 145 +++++++++++++++++++++++++++++++++++++++++++
dlls/msvcrt/msvcrt.spec | 4 +
5 files changed, 153 insertions(+), 8 deletions(-)
diff --git a/dlls/msvcr100/msvcr100.spec b/dlls/msvcr100/msvcr100.spec
index 31d94b6..747dfde 100644
--- a/dlls/msvcr100/msvcr100.spec
+++ b/dlls/msvcr100/msvcr100.spec
@@ -1064,7 +1064,7 @@
@ stub _scwprintf_p
@ stub _scwprintf_p_l
@ cdecl _searchenv(str str ptr) msvcrt._searchenv
-@ stub _searchenv_s
+@ cdecl _searchenv_s(str str ptr long) msvcrt._searchenv_s
@ stub _seh_longjmp_unwind4
@ stdcall -i386 _seh_longjmp_unwind(ptr) msvcrt._seh_longjmp_unwind
@ cdecl _set_SSE2_enable(long) msvcrt._set_SSE2_enable
@@ -1379,7 +1379,7 @@
@ varargs _wscanf_l(wstr ptr) msvcrt._wscanf_l
@ varargs _wscanf_s_l(wstr ptr) msvcrt._wscanf_s_l
@ cdecl _wsearchenv(wstr wstr ptr) msvcrt._wsearchenv
-@ stub _wsearchenv_s
+@ cdecl _wsearchenv_s(wstr wstr ptr long) msvcrt._wsearchenv_s
@ cdecl _wsetlocale(long wstr) msvcrt._wsetlocale
@ varargs _wsopen(wstr long long) msvcrt._wsopen
@ stub _wsopen_s
diff --git a/dlls/msvcr80/msvcr80.spec b/dlls/msvcr80/msvcr80.spec
index 1a26865..6b89e4c 100644
--- a/dlls/msvcr80/msvcr80.spec
+++ b/dlls/msvcr80/msvcr80.spec
@@ -916,7 +916,7 @@
@ stub _scwprintf_p
@ stub _scwprintf_p_l
@ cdecl _searchenv(str str ptr) msvcrt._searchenv
-@ stub _searchenv_s
+@ cdecl _searchenv_s(str str ptr long) msvcrt._searchenv_s
@ stub _seh_longjmp_unwind4
@ stdcall -i386 _seh_longjmp_unwind(ptr) msvcrt._seh_longjmp_unwind
@ cdecl _set_SSE2_enable(long) msvcrt._set_SSE2_enable
@@ -1235,7 +1235,7 @@
@ varargs _wscanf_l(wstr ptr) msvcrt._wscanf_l
@ varargs _wscanf_s_l(wstr ptr) msvcrt._wscanf_s_l
@ cdecl _wsearchenv(wstr wstr ptr) msvcrt._wsearchenv
-@ stub _wsearchenv_s
+@ cdecl _wsearchenv_s(wstr wstr ptr long) msvcrt._wsearchenv_s
@ cdecl _wsetlocale(long wstr) msvcrt._wsetlocale
@ varargs _wsopen(wstr long long) msvcrt._wsopen
@ stub _wsopen_s
diff --git a/dlls/msvcr90/msvcr90.spec b/dlls/msvcr90/msvcr90.spec
index 98fea07..0f19b6c 100644
--- a/dlls/msvcr90/msvcr90.spec
+++ b/dlls/msvcr90/msvcr90.spec
@@ -902,7 +902,7 @@
@ stub _scwprintf_p
@ stub _scwprintf_p_l
@ cdecl _searchenv(str str ptr) msvcrt._searchenv
-@ stub _searchenv_s
+@ cdecl _searchenv_s(str str ptr long) msvcrt._searchenv_s
@ stub _seh_longjmp_unwind4
@ stdcall -i386 _seh_longjmp_unwind(ptr) msvcrt._seh_longjmp_unwind
@ cdecl _set_SSE2_enable(long) msvcrt._set_SSE2_enable
@@ -1219,7 +1219,7 @@
@ varargs _wscanf_l(wstr ptr) msvcrt._wscanf_l
@ varargs _wscanf_s_l(wstr ptr) msvcrt._wscanf_s_l
@ cdecl _wsearchenv(wstr wstr ptr) msvcrt._wsearchenv
-@ stub _wsearchenv_s
+@ cdecl _wsearchenv_s(wstr wstr ptr long) msvcrt._wsearchenv_s
@ cdecl _wsetlocale(long wstr) msvcrt._wsetlocale
@ varargs _wsopen(wstr long long) msvcrt._wsopen
@ stub _wsopen_s
diff --git a/dlls/msvcrt/dir.c b/dlls/msvcrt/dir.c
index 5b5f641..8ff5158 100644
--- a/dlls/msvcrt/dir.c
+++ b/dlls/msvcrt/dir.c
@@ -1413,6 +1413,78 @@ void CDECL _searchenv(const char* file, const char* env, char *buf)
}
/*********************************************************************
+ * _searchenv_s (MSVCRT.@)
+ */
+int CDECL _searchenv_s(const char* file, const char* env, char *buf, MSVCRT_size_t count)
+{
+ char*envVal, *penv;
+ char curPath[MAX_PATH];
+
+ if (!MSVCRT_CHECK_PMT(file != NULL) || !MSVCRT_CHECK_PMT(buf != NULL) ||
+ !MSVCRT_CHECK_PMT(count > 0))
+ {
+ *MSVCRT__errno() = MSVCRT_EINVAL;
+ return MSVCRT_EINVAL;
+ }
+
+ *buf = '\0';
+
+ /* Try CWD first */
+ if (GetFileAttributesA( file ) != INVALID_FILE_ATTRIBUTES)
+ {
+ if (GetFullPathNameA( file, count, buf, NULL )) return 0;
+ msvcrt_set_errno(GetLastError());
+ return 0;
+ }
+
+ /* Search given environment variable */
+ envVal = MSVCRT_getenv(env);
+ if (!envVal)
+ {
+ *MSVCRT__errno() = MSVCRT_ENOENT;
+ return MSVCRT_ENOENT;
+ }
+
+ penv = envVal;
+ TRACE(":searching for %s in paths %s\n", file, envVal);
+
+ do
+ {
+ char *end = penv;
+
+ while(*end && *end != ';') end++; /* Find end of next path */
+ if (penv == end || !*penv)
+ {
+ *MSVCRT__errno() = MSVCRT_ENOENT;
+ return MSVCRT_ENOENT;
+ }
+ memcpy(curPath, penv, end - penv);
+ if (curPath[end - penv] != '/' && curPath[end - penv] != '\\')
+ {
+ curPath[end - penv] = '\\';
+ curPath[end - penv + 1] = '\0';
+ }
+ else
+ curPath[end - penv] = '\0';
+
+ strcat(curPath, file);
+ TRACE("Checking for file %s\n", curPath);
+ if (GetFileAttributesA( curPath ) != INVALID_FILE_ATTRIBUTES)
+ {
+ if (strlen(curPath) + 1 > count)
+ {
+ MSVCRT_INVALID_PMT("buf[count] is too small");
+ *MSVCRT__errno() = MSVCRT_ERANGE;
+ return MSVCRT_ERANGE;
+ }
+ strcpy(buf, curPath);
+ return 0;
+ }
+ penv = *end ? end + 1 : end;
+ } while(1);
+}
+
+/*********************************************************************
* _wsearchenv (MSVCRT.@)
*
* Unicode version of _searchenv
@@ -1474,3 +1546,76 @@ void CDECL _wsearchenv(const MSVCRT_wchar_t* file, const MSVCRT_wchar_t* env, MS
penv = *end ? end + 1 : end;
} while(1);
}
+
+/*********************************************************************
+ * _wsearchenv_s (MSVCRT.@)
+ */
+int CDECL _wsearchenv_s(const MSVCRT_wchar_t* file, const MSVCRT_wchar_t* env,
+ MSVCRT_wchar_t *buf, MSVCRT_size_t count)
+{
+ MSVCRT_wchar_t* envVal, *penv;
+ MSVCRT_wchar_t curPath[MAX_PATH];
+
+ if (!MSVCRT_CHECK_PMT(file != NULL) || !MSVCRT_CHECK_PMT(buf != NULL) ||
+ !MSVCRT_CHECK_PMT(count > 0))
+ {
+ *MSVCRT__errno() = MSVCRT_EINVAL;
+ return MSVCRT_EINVAL;
+ }
+ *buf = '\0';
+
+ /* Try CWD first */
+ if (GetFileAttributesW( file ) != INVALID_FILE_ATTRIBUTES)
+ {
+ if (GetFullPathNameW( file, count, buf, NULL )) return 0;
+ msvcrt_set_errno(GetLastError());
+ return 0;
+ }
+
+ /* Search given environment variable */
+ envVal = _wgetenv(env);
+ if (!envVal)
+ {
+ *MSVCRT__errno() = MSVCRT_ENOENT;
+ return MSVCRT_ENOENT;
+ }
+
+ penv = envVal;
+ TRACE(":searching for %s in paths %s\n", debugstr_w(file), debugstr_w(envVal));
+
+ do
+ {
+ MSVCRT_wchar_t *end = penv;
+
+ while(*end && *end != ';') end++; /* Find end of next path */
+ if (penv == end || !*penv)
+ {
+ *MSVCRT__errno() = MSVCRT_ENOENT;
+ return MSVCRT_ENOENT;
+ }
+ memcpy(curPath, penv, (end - penv) * sizeof(MSVCRT_wchar_t));
+ if (curPath[end - penv] != '/' && curPath[end - penv] != '\\')
+ {
+ curPath[end - penv] = '\\';
+ curPath[end - penv + 1] = '\0';
+ }
+ else
+ curPath[end - penv] = '\0';
+
+ strcatW(curPath, file);
+ TRACE("Checking for file %s\n", debugstr_w(curPath));
+ if (GetFileAttributesW( curPath ) != INVALID_FILE_ATTRIBUTES)
+ {
+ if (strlenW(curPath) + 1 > count)
+ {
+ MSVCRT_INVALID_PMT("buf[count] is too small");
+ *MSVCRT__errno() = MSVCRT_ERANGE;
+ return MSVCRT_ERANGE;
+ }
+ strcpyW(buf, curPath);
+ return 0;
+ }
+ penv = *end ? end + 1 : end;
+ } while(1);
+}
+
diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec
index 99366d8..9a86918 100644
--- a/dlls/msvcrt/msvcrt.spec
+++ b/dlls/msvcrt/msvcrt.spec
@@ -843,7 +843,7 @@
# stub _scwprintf_l
# stub _scwprintf_p_l
@ cdecl _searchenv(str str ptr)
-# stub _searchenv_s
+@ cdecl _searchenv_s(str str ptr long)
# stub _seh_longjmp_unwind4
@ stdcall -i386 _seh_longjmp_unwind(ptr)
@ cdecl _set_SSE2_enable(long) MSVCRT__set_SSE2_enable
@@ -1150,7 +1150,7 @@
@ varargs _wscanf_l(wstr ptr) MSVCRT__wscanf_l
@ varargs _wscanf_s_l(wstr ptr) MSVCRT__wscanf_s_l
@ cdecl _wsearchenv(wstr wstr ptr)
-# stub _wsearchenv_s
+@ cdecl _wsearchenv_s(wstr wstr ptr long)
@ cdecl _wsetlocale(long wstr) MSVCRT__wsetlocale
@ varargs _wsopen (wstr long long) MSVCRT__wsopen
# stub _wsopen_s
More information about the wine-patches
mailing list