本文整理汇总了C++中PathCharString::CloseBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ PathCharString::CloseBuffer方法的具体用法?C++ PathCharString::CloseBuffer怎么用?C++ PathCharString::CloseBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PathCharString
的用法示例。
在下文中一共展示了PathCharString::CloseBuffer方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
/*++
Function:
GetCurrentDirectoryA
--*/
DWORD
GetCurrentDirectoryA(PathCharString& lpBuffer)
{
DWORD dwDirLen = 0;
DWORD dwLastError = 0;
char *current_dir;
PERF_ENTRY(GetCurrentDirectoryA);
ENTRY("GetCurrentDirectoryA(lpBuffer=%p)\n", lpBuffer.GetString());
current_dir = lpBuffer.OpenStringBuffer(MAX_PATH);
/* NULL first arg means getcwd will allocate the string */
current_dir = PAL__getcwd( current_dir, MAX_PATH);
if (current_dir != NULL )
{
dwDirLen = strlen( current_dir );
lpBuffer.CloseBuffer(dwDirLen);
goto done;
}
else if ( errno == ERANGE )
{
lpBuffer.CloseBuffer(0);
current_dir = PAL__getcwd( NULL, 0);
}
if ( !current_dir )
{
WARN("Getcwd failed with errno=%d [%s]\n", errno, strerror(errno));
dwLastError = DIRGetLastErrorFromErrno();
dwDirLen = 0;
goto done;
}
dwDirLen = strlen( current_dir );
lpBuffer.Set(current_dir, dwDirLen);
PAL_free(current_dir);
done:
if ( dwLastError )
{
SetLastError(dwLastError);
}
LOGEXIT("GetCurrentDirectoryA returns DWORD %u\n", dwDirLen);
PERF_EXIT(GetCurrentDirectoryA);
return dwDirLen;
}
示例2: WideCharToMultiByte
BOOL
PAL_GetPALDirectoryA(PathCharString& lpDirectoryName)
{
BOOL bRet;
PathWCharString directory;
PERF_ENTRY(PAL_GetPALDirectoryA);
bRet = PAL_GetPALDirectoryW(directory);
if (bRet)
{
int length = WideCharToMultiByte(CP_ACP, 0, directory.GetString(), -1, NULL, 0, NULL, 0);
LPSTR DirectoryName = lpDirectoryName.OpenStringBuffer(length);
if (NULL == DirectoryName)
{
SetLastError( ERROR_INSUFFICIENT_BUFFER );
bRet = FALSE;
}
length = WideCharToMultiByte(CP_ACP, 0, directory.GetString(), -1, DirectoryName, length, NULL, 0);
if (0 == length)
{
bRet = FALSE;
length++;
}
lpDirectoryName.CloseBuffer(length - 1);
}
PERF_EXIT(PAL_GetPALDirectoryA);
return bRet;
}
示例3: strlen
/*++
Function :
PAL_BindResources - bind the resource domain to the path where the coreclr resides
Returns TRUE if it succeeded, FALSE if it failed due to OOM
--*/
BOOL
PALAPI
PAL_BindResources(IN LPCSTR lpDomain)
{
#if HAVE_LIBINTL_H
_ASSERTE(g_szCoreCLRPath != NULL);
char * coreCLRDirectoryPath;
PathCharString coreCLRDirectoryPathPS;
int len = strlen(g_szCoreCLRPath);
coreCLRDirectoryPath = coreCLRDirectoryPathPS.OpenStringBuffer(len);
if (NULL == coreCLRDirectoryPath)
{
return FALSE;
}
DWORD size = FILEGetDirectoryFromFullPathA(g_szCoreCLRPath, len, coreCLRDirectoryPath);
coreCLRDirectoryPathPS.CloseBuffer(size);
LPCSTR boundPath = bindtextdomain(lpDomain, coreCLRDirectoryPath);
return boundPath != NULL;
#else // HAVE_LIBINTL_H
// UNIXTODO: Implement for Unixes without libintl if necessary
return TRUE;
#endif // HAVE_LIBINTL_H
}
示例4: strlen
/*++
Function :
PAL_BindResources - bind the resource domain to the path where the coreclr resides
Returns TRUE if it succeeded, FALSE if it failed due to OOM
--*/
BOOL
PALAPI
PAL_BindResources(IN LPCSTR lpDomain)
{
#ifndef __APPLE__
_ASSERTE(g_szCoreCLRPath != NULL);
char * coreCLRDirectoryPath;
PathCharString coreCLRDirectoryPathPS;
int len = strlen(g_szCoreCLRPath);
coreCLRDirectoryPath = coreCLRDirectoryPathPS.OpenStringBuffer(len);
if (NULL == coreCLRDirectoryPath)
{
return FALSE;
}
DWORD size = FILEGetDirectoryFromFullPathA(g_szCoreCLRPath, len, coreCLRDirectoryPath);
coreCLRDirectoryPathPS.CloseBuffer(size);
_ASSERTE(size <= MAX_LONGPATH);
LPCSTR boundPath = bindtextdomain(lpDomain, coreCLRDirectoryPath);
return boundPath != NULL;
#else // __APPLE__
// UNIXTODO: Implement for OSX if necessary
return TRUE;
#endif // __APPLE__
}
示例5: ASSERT
/*++
Function:
LoadLibraryExW
See MSDN doc.
--*/
HMODULE
PALAPI
LoadLibraryExW(
IN LPCWSTR lpLibFileName,
IN /*Reserved*/ HANDLE hFile,
IN DWORD dwFlags)
{
if (dwFlags != 0)
{
// UNIXTODO: Implement this!
ASSERT("Needs Implementation!!!");
return nullptr;
}
CHAR * lpstr;
INT name_length;
PathCharString pathstr;
HMODULE hModule = nullptr;
PERF_ENTRY(LoadLibraryExW);
ENTRY("LoadLibraryExW (lpLibFileName=%p (%S)) \n",
lpLibFileName ? lpLibFileName : W16_NULLSTRING,
lpLibFileName ? lpLibFileName : W16_NULLSTRING);
if (!LOADVerifyLibraryPath(lpLibFileName))
{
goto done;
}
lpstr = pathstr.OpenStringBuffer((PAL_wcslen(lpLibFileName)+1) * MaxWCharToAcpLength);
if (nullptr == lpstr)
{
goto done;
}
if (!LOADConvertLibraryPathWideStringToMultibyteString(lpLibFileName, lpstr, &name_length))
{
goto done;
}
/* do the Dos/Unix conversion on our own copy of the name */
FILEDosToUnixPathA(lpstr);
pathstr.CloseBuffer(name_length);
/* let LOADLoadLibrary call SetLastError in case of failure */
hModule = LOADLoadLibrary(lpstr, TRUE);
done:
LOGEXIT("LoadLibraryExW returns HMODULE %p\n", hModule);
PERF_EXIT(LoadLibraryExW);
return hModule;
}
示例6: failure
/*
Function:
PAL_RegisterLibraryDirect
Registers a system handle to a loaded library with the module list.
Returns a PAL handle to the loaded library, or nullptr upon failure (error is set via SetLastError()).
*/
HMODULE
PALAPI
PAL_RegisterLibraryDirect(
IN void *dl_handle,
IN LPCWSTR lpLibFileName)
{
PathCharString pathstr;
CHAR * lpstr = nullptr;
INT name_length;
HMODULE hModule = nullptr;
PERF_ENTRY(RegisterLibraryDirect);
ENTRY("RegisterLibraryDirect (lpLibFileName=%p (%S)) \n",
lpLibFileName ? lpLibFileName : W16_NULLSTRING,
lpLibFileName ? lpLibFileName : W16_NULLSTRING);
if (!LOADVerifyLibraryPath(lpLibFileName))
{
goto done;
}
lpstr = pathstr.OpenStringBuffer((PAL_wcslen(lpLibFileName)+1) * MaxWCharToAcpLength);
if (nullptr == lpstr)
{
goto done;
}
if (!LOADConvertLibraryPathWideStringToMultibyteString(lpLibFileName, lpstr, &name_length))
{
goto done;
}
/* do the Dos/Unix conversion on our own copy of the name */
FILEDosToUnixPathA(lpstr);
pathstr.CloseBuffer(name_length);
/* let LOADRegisterLibraryDirect call SetLastError in case of failure */
LockModuleList();
hModule = LOADRegisterLibraryDirect((void *)dl_handle, lpstr, true /* fDynamic */);
UnlockModuleList();
done:
LOGEXIT("RegisterLibraryDirect returns HMODULE %p\n", hModule);
PERF_EXIT(RegisterLibraryDirect);
return hModule;
}
示例7: munmap
~AutoCleanup()
{
if (m_cancel)
{
return;
}
if (m_mappedBuffer != nullptr)
{
_ASSERTE(m_mappedBufferByteCount != 0);
munmap(m_mappedBuffer, m_mappedBufferByteCount);
}
if (m_acquiredFileLock)
{
_ASSERTE(m_fileDescriptor != -1);
SharedMemoryHelpers::ReleaseFileLock(m_fileDescriptor);
}
if (m_fileDescriptor != -1)
{
SharedMemoryHelpers::CloseFile(m_fileDescriptor);
}
if (m_createdFile)
{
_ASSERTE(m_filePath != nullptr);
unlink(*m_filePath);
}
if (m_sessionDirectoryPathCharCount != 0)
{
_ASSERTE(*m_filePath != nullptr);
m_filePath->CloseBuffer(m_sessionDirectoryPathCharCount);
rmdir(*m_filePath);
}
if (m_acquiredCreationDeletionFileLock)
{
SharedMemoryManager::ReleaseCreationDeletionFileLock();
}
}
示例8: ENTRY
PALAPI
PAL_LoadLibraryDirect(
IN LPCWSTR lpLibFileName)
{
PathCharString pathstr;
CHAR * lpstr = nullptr;
INT name_length;
void *dl_handle = nullptr;
PERF_ENTRY(LoadLibraryDirect);
ENTRY("LoadLibraryDirect (lpLibFileName=%p (%S)) \n",
lpLibFileName ? lpLibFileName : W16_NULLSTRING,
lpLibFileName ? lpLibFileName : W16_NULLSTRING);
if (!LOADVerifyLibraryPath(lpLibFileName))
{
goto done;
}
lpstr = pathstr.OpenStringBuffer((PAL_wcslen(lpLibFileName)+1) * MaxWCharToAcpLength);
if (nullptr == lpstr)
{
goto done;
}
if (!LOADConvertLibraryPathWideStringToMultibyteString(lpLibFileName, lpstr, &name_length))
{
goto done;
}
/* do the Dos/Unix conversion on our own copy of the name */
FILEDosToUnixPathA(lpstr);
pathstr.CloseBuffer(name_length);
dl_handle = LOADLoadLibraryDirect(lpstr);
done:
LOGEXIT("LoadLibraryDirect returns HMODULE %p\n", dl_handle);
PERF_EXIT(LoadLibraryDirect);
return dl_handle;
}
示例9: ENTRY
/*++
Function:
SetCurrentDirectoryW
See MSDN doc.
--*/
BOOL
PALAPI
SetCurrentDirectoryW(
IN LPCWSTR lpPathName)
{
BOOL bRet;
DWORD dwLastError = 0;
PathCharString dirPathString;
int size;
size_t length;
char * dir;
PERF_ENTRY(SetCurrentDirectoryW);
ENTRY("SetCurrentDirectoryW(lpPathName=%p (%S))\n",
lpPathName?lpPathName:W16_NULLSTRING,
lpPathName?lpPathName:W16_NULLSTRING);
/*check if the given path is null. If so
return FALSE*/
if (lpPathName == NULL )
{
ERROR("Invalid path/directory name\n");
dwLastError = ERROR_INVALID_NAME;
bRet = FALSE;
goto done;
}
length = (PAL_wcslen(lpPathName)+1) * 3;
dir = dirPathString.OpenStringBuffer(length);
if (NULL == dir)
{
dwLastError = ERROR_NOT_ENOUGH_MEMORY;
bRet = FALSE;
goto done;
}
size = WideCharToMultiByte( CP_ACP, 0, lpPathName, -1, dir, length,
NULL, NULL );
dirPathString.CloseBuffer(size);
if( size == 0 )
{
dwLastError = GetLastError();
if( dwLastError == ERROR_INSUFFICIENT_BUFFER )
{
WARN("lpPathName is larger than MAX_LONGPATH (%d)!\n", MAX_LONGPATH);
dwLastError = ERROR_FILENAME_EXCED_RANGE;
}
else
{
ASSERT("WideCharToMultiByte failure! error is %d\n", dwLastError);
dwLastError = ERROR_INTERNAL_ERROR;
}
bRet = FALSE;
goto done;
}
bRet = SetCurrentDirectoryA(dir);
done:
if( dwLastError )
{
SetLastError(dwLastError);
}
LOGEXIT("SetCurrentDirectoryW returns BOOL %d\n", bRet);
PERF_EXIT(SetCurrentDirectoryW);
return bRet;
}
示例10: Close
void SharedMemoryProcessDataHeader::Close()
{
_ASSERTE(SharedMemoryManager::IsCreationDeletionProcessLockAcquired());
_ASSERTE(!SharedMemoryManager::IsCreationDeletionFileLockAcquired());
// If the ref count is nonzero, we are shutting down the process abruptly without having closed some shared memory objects.
// There could still be threads running with active references to the shared memory object. So when the ref count is
// nonzero, don't clean up any object or global process-local state.
if (m_refCount == 0)
{
SharedMemoryManager::RemoveProcessDataHeader(this);
}
struct AutoReleaseCreationDeletionFileLock
{
bool m_acquired;
AutoReleaseCreationDeletionFileLock() : m_acquired(false)
{
}
~AutoReleaseCreationDeletionFileLock()
{
if (m_acquired)
{
SharedMemoryManager::ReleaseCreationDeletionFileLock();
}
}
} autoReleaseCreationDeletionFileLock;
// A shared file lock on the shared memory file would be held by any process that has opened the same file. Try to take
// an exclusive lock on the file. Successfully acquiring an exclusive lock indicates that no process has a reference to
// the shared memory file, and this process can delete the file. File locks on the shared memory file are only ever acquired
// or released while holding the creation/deletion locks, so holding the creation/deletion locks while trying an exclusive
// lock on the shared memory file guarantees that another process cannot start using the shared memory file after this
// process has decided to delete the file.
bool releaseSharedData = false;
try
{
SharedMemoryManager::AcquireCreationDeletionFileLock();
autoReleaseCreationDeletionFileLock.m_acquired = true;
SharedMemoryHelpers::ReleaseFileLock(m_fileDescriptor);
if (SharedMemoryHelpers::TryAcquireFileLock(m_fileDescriptor, LOCK_EX | LOCK_NB))
{
SharedMemoryHelpers::ReleaseFileLock(m_fileDescriptor);
releaseSharedData = true;
}
}
catch (SharedMemoryException)
{
// Ignore the error, just don't release shared data
}
if (m_data != nullptr)
{
m_data->Close(m_refCount != 0 /* isAbruptShutdown */, releaseSharedData);
}
if (m_refCount == 0)
{
if (m_data != nullptr)
{
InternalDelete(m_data);
}
if (releaseSharedData)
{
m_sharedDataHeader->~SharedMemorySharedDataHeader();
}
munmap(m_sharedDataHeader, m_sharedDataTotalByteCount);
SharedMemoryHelpers::CloseFile(m_fileDescriptor);
}
if (!releaseSharedData)
{
return;
}
try
{
// Delete the shared memory file, and the session directory if it's not empty
PathCharString path;
SharedMemoryHelpers::VerifyStringOperation(SharedMemoryManager::CopySharedMemoryBasePath(path));
SharedMemoryHelpers::VerifyStringOperation(path.Append('/'));
SharedMemoryHelpers::VerifyStringOperation(m_id.AppendSessionDirectoryName(path));
SharedMemoryHelpers::VerifyStringOperation(path.Append('/'));
SIZE_T sessionDirectoryPathCharCount = path.GetCount();
SharedMemoryHelpers::VerifyStringOperation(path.Append(m_id.GetName(), m_id.GetNameCharCount()));
unlink(path);
path.CloseBuffer(sessionDirectoryPathCharCount);
rmdir(path);
}
catch (SharedMemoryException)
{
// Ignore the error, just don't release shared data
}
}
示例11: ENTRY
//.........这里部分代码省略.........
ASSERT("lpSecurityAttributes is not NULL as it should be\n");
dwLastError = ERROR_INVALID_PARAMETER;
goto done;
}
// Windows returns ERROR_PATH_NOT_FOUND when called with NULL.
// If we don't have this check, strdup(NULL) segfaults.
if (lpPathName == NULL)
{
ERROR("CreateDirectoryA called with NULL pathname!\n");
dwLastError = ERROR_PATH_NOT_FOUND;
goto done;
}
unixPathName = PAL__strdup(lpPathName);
if (unixPathName == NULL )
{
ERROR("PAL__strdup() failed\n");
dwLastError = ERROR_NOT_ENOUGH_MEMORY;
goto done;
}
FILEDosToUnixPathA( unixPathName );
// Remove any trailing slashes at the end because mkdir might not
// handle them appropriately on all platforms.
pathLength = strlen(unixPathName);
i = pathLength;
while(i > 1)
{
if(unixPathName[i - 1] =='/')
{
unixPathName[i - 1]='\0';
i--;
}
else
{
break;
}
}
// Get an absolute path.
if (unixPathName[0] == '/')
{
realPathBuf = unixPathName;
}
else
{
DWORD len = GetCurrentDirectoryA(realPath);
if (len == 0 || !realPath.Reserve(realPath.GetCount() + pathLength + 1 ))
{
dwLastError = DIRGetLastErrorFromErrno();
WARN("Getcwd failed with errno=%d \n", dwLastError);
goto done;
}
realPath.Append("/", 1);
realPath.Append(unixPathName, pathLength);
realPathBuf = realPath.OpenStringBuffer(realPath.GetCount());
}
// Canonicalize the path so we can determine its length.
FILECanonicalizePath(realPathBuf);
if ( mkdir(realPathBuf, mode) != 0 )
{
TRACE("Creation of directory [%s] was unsuccessful, errno = %d.\n",
unixPathName, errno);
switch( errno )
{
case ENOTDIR:
/* FALL THROUGH */
case ENOENT:
FILEGetProperNotFoundError( realPathBuf, &dwLastError );
goto done;
case EEXIST:
dwLastError = ERROR_ALREADY_EXISTS;
break;
default:
dwLastError = ERROR_ACCESS_DENIED;
}
}
else
{
TRACE("Creation of directory [%s] was successful.\n", unixPathName);
bRet = TRUE;
}
realPath.CloseBuffer(0); //The PathCharString usage is done
done:
if( dwLastError )
{
SetLastError( dwLastError );
}
PAL_free( unixPathName );
LOGEXIT("CreateDirectoryA returns BOOL %d\n", bRet);
PERF_EXIT(CreateDirectoryA);
return bRet;
}