/*++ Function : PAL_GetPALDirectoryW Returns the fully qualified path name where the PALL DLL was loaded from. On failure it returns FALSE and sets the proper LastError code. --*/ BOOL PAL_GetPALDirectoryW(PathWCharString& lpDirectoryName) { LPCWSTR lpFullPathAndName = NULL; LPCWSTR lpEndPoint = NULL; BOOL bRet = FALSE; PERF_ENTRY(PAL_GetPALDirectoryW); MODSTRUCT *module = LOADGetPalLibrary(); if (!module) { SetLastError(ERROR_INTERNAL_ERROR); goto EXIT; } lpFullPathAndName = module->lib_name; if (lpFullPathAndName == NULL) { SetLastError(ERROR_INTERNAL_ERROR); goto EXIT; } lpEndPoint = PAL_wcsrchr( lpFullPathAndName, '/' ); if ( lpEndPoint ) { /* The path that we return is required to have the trailing slash on the end.*/ lpEndPoint++; if(!lpDirectoryName.Set(lpFullPathAndName,lpEndPoint - lpFullPathAndName)) { ASSERT( "The buffer was not large enough.\n" ); SetLastError( ERROR_INSUFFICIENT_BUFFER ); goto EXIT; } bRet = TRUE; } else { ASSERT( "Unable to determine the path.\n" ); /* Error path, should not be executed. */ SetLastError( ERROR_INTERNAL_ERROR ); } EXIT: PERF_EXIT(PAL_GetPALDirectoryW); return bRet; }
/*++ Function : PAL_GetPALDirectoryW Returns the fully qualified path name where the PALL DLL was loaded from. On failure it returns FALSE and sets the proper LastError code. See rotor_pal.doc for more details. --*/ BOOL PALAPI PAL_GetPALDirectoryW( OUT LPWSTR lpDirectoryName, IN UINT cchDirectoryName ) { LPWSTR lpFullPathAndName = NULL; LPWSTR lpEndPoint = NULL; BOOL bRet = FALSE; PERF_ENTRY(PAL_GetPALDirectoryW); ENTRY( "PAL_GetPALDirectoryW( %p, %d )\n", lpDirectoryName, cchDirectoryName ); MODSTRUCT *module = LOADGetPalLibrary(); if (!module) { SetLastError(ERROR_INTERNAL_ERROR); goto EXIT; } lpFullPathAndName = module->lib_name; if (lpFullPathAndName == NULL) { SetLastError(ERROR_INTERNAL_ERROR); goto EXIT; } lpEndPoint = PAL_wcsrchr( lpFullPathAndName, '/' ); if ( lpEndPoint ) { /* The path that we return is required to have the trailing slash on the end.*/ lpEndPoint++; } if ( lpFullPathAndName && lpEndPoint && *lpEndPoint != '\0' ) { while ( cchDirectoryName - 1 && lpFullPathAndName != lpEndPoint ) { *lpDirectoryName = *lpFullPathAndName; lpFullPathAndName++; lpDirectoryName++; cchDirectoryName--; } if ( lpFullPathAndName == lpEndPoint ) { *lpDirectoryName = '\0'; bRet = TRUE; goto EXIT; } else { ASSERT( "The buffer was not large enough.\n" ); SetLastError( ERROR_INSUFFICIENT_BUFFER ); goto EXIT; } } else { ASSERT( "Unable to determine the path.\n" ); } /* Error path, should not be executed. */ SetLastError( ERROR_INTERNAL_ERROR ); EXIT: LOGEXIT( "PAL_GetPALDirectoryW returns BOOL %d.\n", bRet); PERF_EXIT(PAL_GetPALDirectoryW); return bRet; }