Hans Leidekker : msvcrt: Implement _wsearchenv.

Alexandre Julliard julliard at winehq.org
Mon Sep 24 08:08:05 CDT 2007


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

Author: Hans Leidekker <hans at it.vu.nl>
Date:   Fri Sep 21 15:49:37 2007 +0200

msvcrt: Implement _wsearchenv.

---

 dlls/msvcrt/dir.c       |   63 +++++++++++++++++++++++++++++++++++++++++++++++
 dlls/msvcrt/msvcrt.h    |    1 +
 dlls/msvcrt/msvcrt.spec |    2 +-
 3 files changed, 65 insertions(+), 1 deletions(-)

diff --git a/dlls/msvcrt/dir.c b/dlls/msvcrt/dir.c
index 06013c6..3da6efa 100644
--- a/dlls/msvcrt/dir.c
+++ b/dlls/msvcrt/dir.c
@@ -1010,3 +1010,66 @@ void CDECL _searchenv(const char* file, const char* env, char *buf)
     penv = *end ? end + 1 : end;
   } while(1);
 }
+
+/*********************************************************************
+ *      _wsearchenv (MSVCRT.@)
+ *
+ * Unicode version of _searchenv
+ */
+void CDECL _wsearchenv(const MSVCRT_wchar_t* file, const MSVCRT_wchar_t* env, MSVCRT_wchar_t *buf)
+{
+  MSVCRT_wchar_t *envVal, *penv;
+  MSVCRT_wchar_t curPath[MAX_PATH];
+
+  *buf = '\0';
+
+  /* Try CWD first */
+  if (GetFileAttributesW( file ) != INVALID_FILE_ATTRIBUTES)
+  {
+    GetFullPathNameW( file, MAX_PATH, buf, NULL );
+    /* Sigh. This error is *always* set, regardless of success */
+    msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
+    return;
+  }
+
+  /* Search given environment variable */
+  envVal = _wgetenv(env);
+  if (!envVal)
+  {
+    msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
+    return;
+  }
+
+  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_set_errno(ERROR_FILE_NOT_FOUND);
+      return;
+    }
+    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)
+    {
+      strcpyW(buf, curPath);
+      msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
+      return; /* Found */
+    }
+    penv = *end ? end + 1 : end;
+  } while(1);
+}
diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h
index 3a9d5c3..cc3cdd7 100644
--- a/dlls/msvcrt/msvcrt.h
+++ b/dlls/msvcrt/msvcrt.h
@@ -651,6 +651,7 @@ int           MSVCRT__close(int);
 int           MSVCRT__dup(int);
 int           MSVCRT__dup2(int, int);
 int           MSVCRT__pipe(int *, unsigned int, int);
+MSVCRT_wchar_t* _wgetenv(const MSVCRT_wchar_t*);
 #endif
 
 #endif /* __WINE_MSVCRT_H */
diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec
index 10a8686..74d1fad 100644
--- a/dlls/msvcrt/msvcrt.spec
+++ b/dlls/msvcrt/msvcrt.spec
@@ -552,7 +552,7 @@
 @ cdecl _wrename(wstr wstr)
 @ cdecl _write(long ptr long) MSVCRT__write
 @ cdecl _wrmdir(wstr)
-@ stub _wsearchenv #(wstr wstr ptr)
+@ stdcall _wsearchenv(wstr wstr ptr)
 @ cdecl _wsetlocale(long wstr) MSVCRT__wsetlocale
 @ varargs _wsopen (wstr long long) MSVCRT__wsopen
 @ stub _wspawnl #(long wstr wstr) varargs




More information about the wine-cvs mailing list