Commit 83d87f3b authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

msvcrt: Implemented (w)searchenv_s.

parent fc186c3b
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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);
}
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment