ReactOS 0.4.15-dev-7842-g558ab78
senv.c File Reference
#include <precomp.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
Include dependency graph for senv.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define sT   "s"
 
#define MK_STR(s)   #s
 

Functions

void _tsearchenv (const _TCHAR *file, const _TCHAR *var, _TCHAR *path)
 
int _tsearchenv_s (const _TCHAR *file, const _TCHAR *env, _TCHAR *buf, size_t count)
 

Macro Definition Documentation

◆ MK_STR

#define MK_STR (   s)    #s

Definition at line 22 of file senv.c.

◆ sT

#define sT   "s"

Definition at line 19 of file senv.c.

Function Documentation

◆ _tsearchenv()

void _tsearchenv ( const _TCHAR file,
const _TCHAR var,
_TCHAR path 
)

Definition at line 27 of file senv.c.

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}
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
#define _tsearchenv
Definition: tchar.h:685
char _TCHAR
Definition: tchar.h:1392
#define _tgetenv
Definition: tchar.h:680
#define _tcschr
Definition: tchar.h:1406
const char * var
Definition: shader.c:5666
#define MK_STR(s)
Definition: senv.c:22
#define TRACE(s)
Definition: solgame.cpp:4
Definition: fci.c:127
#define SearchPath
Definition: winbase.h:3835

◆ _tsearchenv_s()

int _tsearchenv_s ( const _TCHAR file,
const _TCHAR env,
_TCHAR buf,
size_t  count 
)

Definition at line 56 of file senv.c.

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
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 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
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
errno_t __cdecl _set_errno(_In_ int _Value)
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define GetFileAttributes
Definition: winbase.h:3750
#define GetFullPathName
Definition: winbase.h:3756
#define _tcslen
Definition: xmlstorage.h:198