Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygensenv.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS system libraries 00004 * FILE: lib/crt/?????? 00005 * PURPOSE: Unknown 00006 * PROGRAMER: Unknown 00007 * UPDATE HISTORY: 00008 * 25/11/05: Added license header 00009 */ 00010 00011 #include <precomp.h> 00012 #include <stdlib.h> 00013 #include <string.h> 00014 #include <tchar.h> 00015 00016 #ifdef _UNICODE 00017 #define sT "S" 00018 #else 00019 #define sT "s" 00020 #endif 00021 00022 #define MK_STR(s) #s 00023 00024 /* 00025 * @implemented 00026 */ 00027 void _tsearchenv(const _TCHAR* file,const _TCHAR* var,_TCHAR* path) 00028 { 00029 _TCHAR* env = _tgetenv(var); 00030 _TCHAR* x; 00031 _TCHAR* y; 00032 _TCHAR* FilePart; 00033 00034 TRACE(MK_STR(_tsearchenv)"()\n"); 00035 00036 x = _tcschr(env,'='); 00037 if ( x != NULL ) { 00038 *x = 0; 00039 x++; 00040 } 00041 y = _tcschr(env,';'); 00042 while ( y != NULL ) { 00043 *y = 0; 00044 if ( SearchPath(x,file,NULL,MAX_PATH,path,&FilePart) > 0 ) { 00045 return; 00046 } 00047 x = y+1; 00048 y = _tcschr(env,';'); 00049 } 00050 return; 00051 } 00052 00053 /********************************************************************* 00054 * _searchenv_s (MSVCRT.@) 00055 */ 00056 int _tsearchenv_s(const _TCHAR* file, const _TCHAR* env, _TCHAR *buf, size_t count) 00057 { 00058 _TCHAR *envVal, *penv; 00059 _TCHAR curPath[MAX_PATH]; 00060 00061 if (!MSVCRT_CHECK_PMT(file != NULL) || !MSVCRT_CHECK_PMT(buf != NULL) || 00062 !MSVCRT_CHECK_PMT(count > 0)) 00063 { 00064 *_errno() = EINVAL; 00065 return EINVAL; 00066 } 00067 00068 *buf = '\0'; 00069 00070 /* Try CWD first */ 00071 if (GetFileAttributes( file ) != INVALID_FILE_ATTRIBUTES) 00072 { 00073 GetFullPathName( file, MAX_PATH, buf, NULL ); 00074 _dosmaperr(GetLastError()); 00075 return 0; 00076 } 00077 00078 /* Search given environment variable */ 00079 envVal = _tgetenv(env); 00080 if (!envVal) 00081 { 00082 _set_errno(ENOENT); 00083 return ENOENT; 00084 } 00085 00086 penv = envVal; 00087 00088 do 00089 { 00090 _TCHAR *end = penv; 00091 00092 while(*end && *end != ';') end++; /* Find end of next path */ 00093 if (penv == end || !*penv) 00094 { 00095 _set_errno(ENOENT); 00096 return ENOENT; 00097 } 00098 memcpy(curPath, penv, (end - penv) * sizeof(_TCHAR)); 00099 if (curPath[end - penv] != '/' && curPath[end - penv] != '\\') 00100 { 00101 curPath[end - penv] = '\\'; 00102 curPath[end - penv + 1] = '\0'; 00103 } 00104 else 00105 curPath[end - penv] = '\0'; 00106 00107 _tcscat(curPath, file); 00108 if (GetFileAttributes( curPath ) != INVALID_FILE_ATTRIBUTES) 00109 { 00110 if (_tcslen(curPath) + 1 > count) 00111 { 00112 MSVCRT_INVALID_PMT("buf[count] is too small"); 00113 *_errno() = ERANGE; 00114 return ERANGE; 00115 } 00116 _tcscpy(buf, curPath); 00117 return 0; 00118 } 00119 penv = *end ? end + 1 : end; 00120 } while(1); 00121 00122 } Generated on Thu May 24 2012 04:37:03 for ReactOS by
1.7.6.1
|