ReactOS 0.4.15-dev-8236-g99f0937
senv.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/sdk/crt/stdlib/senv.c
5 * PURPOSE: Unknown
6 * PROGRAMER: Unknown
7 * UPDATE HISTORY:
8 * 25/11/05: Added license header
9 */
10
11#include <precomp.h>
12#include <stdlib.h>
13#include <string.h>
14#include <tchar.h>
15
16#ifdef _UNICODE
17 #define sT "S"
18#else
19 #define sT "s"
20#endif
21
22#define MK_STR(s) #s
23
24/*
25 * @implemented
26 */
28{
30 _TCHAR* x;
31 _TCHAR* y;
32 _TCHAR* FilePart;
33
34 TRACE(MK_STR(_tsearchenv)"()\n");
35
36 x = _tcschr(env,'=');
37 if ( x != NULL ) {
38 *x = 0;
39 x++;
40 }
41 y = _tcschr(env,';');
42 while ( y != NULL ) {
43 *y = 0;
44 if ( SearchPath(x,file,NULL,MAX_PATH,path,&FilePart) > 0 ) {
45 return;
46 }
47 x = y+1;
48 y = _tcschr(env,';');
49 }
50 return;
51}
52
53/*********************************************************************
54 * _searchenv_s (MSVCRT.@)
55 */
56int _tsearchenv_s(const _TCHAR* file, const _TCHAR* env, _TCHAR *buf, size_t count)
57{
58 _TCHAR *envVal, *penv;
59 _TCHAR curPath[MAX_PATH];
60
63 {
64 *_errno() = EINVAL;
65 return EINVAL;
66 }
67
68 *buf = '\0';
69
70 /* Try CWD first */
72 {
75 return 0;
76 }
77
78 /* Search given environment variable */
79 envVal = _tgetenv(env);
80 if (!envVal)
81 {
83 return ENOENT;
84 }
85
86 penv = envVal;
87
88 do
89 {
90 _TCHAR *end = penv;
91
92 while(*end && *end != ';') end++; /* Find end of next path */
93 if (penv == end || !*penv)
94 {
96 return ENOENT;
97 }
98 memcpy(curPath, penv, (end - penv) * sizeof(_TCHAR));
99 if (curPath[end - penv] != '/' && curPath[end - penv] != '\\')
100 {
101 curPath[end - penv] = '\\';
102 curPath[end - penv + 1] = '\0';
103 }
104 else
105 curPath[end - penv] = '\0';
106
107 _tcscat(curPath, file);
109 {
110 if (_tcslen(curPath) + 1 > count)
111 {
112 MSVCRT_INVALID_PMT("buf[count] is too small", ERANGE);
113 return ERANGE;
114 }
115 _tcscpy(buf, curPath);
116 return 0;
117 }
118 penv = *end ? end + 1 : end;
119 } while(1);
120
121}
#define ENOENT
Definition: acclib.h:79
#define EINVAL
Definition: acclib.h:90
#define ERANGE
Definition: acclib.h:92
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:170
#define NULL
Definition: types.h:112
#define MAX_PATH
Definition: compat.h:34
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLuint GLuint end
Definition: gl.h:1545
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define _tcscat
Definition: tchar.h:622
#define _tcscpy
Definition: tchar.h:623
#define _tsearchenv
Definition: tchar.h:685
char _TCHAR
Definition: tchar.h:1392
#define _tgetenv
Definition: tchar.h:680
#define _tcschr
Definition: tchar.h:1406
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define MSVCRT_INVALID_PMT(x)
Definition: mbstowcs_s.c:25
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
const char * var
Definition: shader.c:5666
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:79
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:17
errno_t __cdecl _set_errno(_In_ int _Value)
int _tsearchenv_s(const _TCHAR *file, const _TCHAR *env, _TCHAR *buf, size_t count)
Definition: senv.c:56
#define MK_STR(s)
Definition: senv.c:22
#define TRACE(s)
Definition: solgame.cpp:4
Definition: fci.c:127
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define GetFileAttributes
Definition: winbase.h:3815
#define SearchPath
Definition: winbase.h:3900
#define GetFullPathName
Definition: winbase.h:3821
#define _tcslen
Definition: xmlstorage.h:198