本文整理汇总了C++中stringT::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ stringT::clear方法的具体用法?C++ stringT::clear怎么用?C++ stringT::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stringT
的用法示例。
在下文中一共展示了stringT::clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LockFile
bool pws_os::LockFile(const stringT &filename, stringT &locker,
HANDLE &lockFileHandle, int &LockCount)
{
const stringT lock_filename = GetLockFileName(filename);
stringT s_locker;
const stringT user = pws_os::getusername();
const stringT host = pws_os::gethostname();
const stringT pid = pws_os::getprocessid();
// Use Win32 API for locking - supposedly better at
// detecting dead locking processes
if (lockFileHandle != INVALID_HANDLE_VALUE) {
// here if we've open another (or same) dbase previously,
// need to unlock it. A bit inelegant...
// If app was minimized and ClearData() called, we've a small
// potential for a TOCTTOU issue here. Worse case, lock
// will fail.
const stringT cs_me = user + _T("@") + host + _T(":") + pid;
GetLocker(lock_filename, s_locker);
if (cs_me == s_locker) {
LockCount++;
locker.clear();
return true;
} else {
pws_os::UnlockFile(filename, lockFileHandle, LockCount);
}
}
// Since ::CreateFile can't create directories, we need to check it exists
// first and, if not, try and create it.
// This is primarily for the config directory in the local APPDATA directory
// but will also be called for the database lock file - and since the database
// is already there, it is a bit of a redundant check but easier than coding
// for every different situation.
stringT sDrive, sDir, sName, sExt;
pws_os::splitpath(lock_filename, sDrive, sDir, sName, sExt);
stringT sNewDir = sDrive + sDir;
DWORD dwAttrib = GetFileAttributes(sNewDir.c_str());
DWORD dwerr(0);
if (dwAttrib == INVALID_FILE_ATTRIBUTES)
dwerr = GetLastError();
BOOL brc(TRUE);
if (dwerr == ERROR_FILE_NOT_FOUND ||
(dwAttrib != INVALID_FILE_ATTRIBUTES) &&
!(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) {
SECURITY_ATTRIBUTES secatt = {0};
secatt.nLength = sizeof(secatt);
brc = ::CreateDirectory(sNewDir.c_str(), &secatt);
}
// Obviously, if we can't create the directory - don't bother trying to
// create the lock file!
if (brc) {
lockFileHandle = ::CreateFile(lock_filename.c_str(),
GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
CREATE_ALWAYS, // rely on share to fail if exists!
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH |
// (Lockheed Martin) Secure Coding 11-14-2007
SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION,
NULL);
// Make sure it's a file and not a pipe. (Lockheed Martin) Secure Coding 11-14-2007
if (lockFileHandle != INVALID_HANDLE_VALUE) {
if (::GetFileType( lockFileHandle ) != FILE_TYPE_DISK) {
::CloseHandle( lockFileHandle );
lockFileHandle = INVALID_HANDLE_VALUE;
}
}
// End of Change. (Lockheed Martin) Secure Coding 11-14-2007
}
if (lockFileHandle == INVALID_HANDLE_VALUE) {
DWORD error = GetLastError();
switch (error) {
case ERROR_SHARING_VIOLATION: // already open by a live process
GetLocker(lock_filename, s_locker);
locker = s_locker.c_str();
break;
default: {
// Give detailed error message, if possible
LPTSTR lpMsgBuf = NULL;
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf,
0, NULL) != 0) {
locker = lpMsgBuf;
LocalFree(lpMsgBuf);
} else { // should never happen!
LoadAString(locker, IDSC_NOLOCKACCESS); // berrer than nothing
}
}
break;
} // switch (error)
//.........这里部分代码省略.........