Eric Pouech : msvcrt: Implemented (w)searchenv_s.

Alexandre Julliard julliard at winehq.org
Wed Nov 3 11:37:03 CDT 2010


Module: wine
Branch: master
Commit: 83d87f3b13f87128b44465471c95cde88342d647
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=83d87f3b13f87128b44465471c95cde88342d647

Author: Eric Pouech <eric.pouech at orange.fr>
Date:   Tue Nov  2 22:03:17 2010 +0100

msvcrt: Implemented (w)searchenv_s.

---

 dlls/msvcr100/msvcr100.spec |    4 +-
 dlls/msvcr80/msvcr80.spec   |    4 +-
 dlls/msvcr90/msvcr90.spec   |    4 +-
 dlls/msvcrt/dir.c           |  144 +++++++++++++++++++++++++++++++++++++++++++
 dlls/msvcrt/msvcrt.spec     |    4 +-
 5 files changed, 152 insertions(+), 8 deletions(-)

diff --git a/dlls/msvcr100/msvcr100.spec b/dlls/msvcr100/msvcr100.spec
index 9ceb3e2..cace374 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 2dec3a4..9ac3094 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 9b87c0a..a307afe 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 b45a459..f175ac0 100644
--- a/dlls/msvcrt/dir.c
+++ b/dlls/msvcrt/dir.c
@@ -1472,6 +1472,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
@@ -1533,3 +1605,75 @@ 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 ca2607c..0f9fdb4 100644
--- a/dlls/msvcrt/msvcrt.spec
+++ b/dlls/msvcrt/msvcrt.spec
@@ -846,7 +846,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
@@ -1154,7 +1154,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-cvs mailing list