void leyrat::Callback_KeyLog(const char *ip, char*keylog) { Log("[R][%s] Uploaded KeyLog!\n", ip); CreateDirectoryA(ip, 0); time_t rawtime; tm* timeinfo; time (&rawtime); timeinfo = localtime (&rawtime); char sdate[50]; strftime(sdate, 50, "%F", timeinfo); std::string sfilename = ip; sfilename.append("/"); sfilename.append("keylog_"); sfilename.append(sdate); sfilename.append(".txt"); Log("[R][%s] Writing file to: %s\n", ip, sfilename.c_str()); FILE* f = fopen(sfilename.c_str(), "a+b"); if(!f) { f = fopen(sfilename.c_str(), "wb"); } if(!f) return; fwrite(keylog, sizeof(char), strlen(keylog), f); fclose(f); }
void AssetsUpdateLayer::createDownloadedDir() { m_pathToSave = CCFileUtils::sharedFileUtils()->getWritablePath(); m_pathToSave += "loaddir/"; CCLOG("writable path[%s]", m_pathToSave.c_str()); getAssetsManager()->setStoragePath(m_pathToSave.c_str()); #if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) DIR *pDir = NULL; pDir = opendir (m_pathToSave.c_str()); if (! pDir) { mkdir(m_pathToSave.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); } #else if ((GetFileAttributesA(m_pathToSave.c_str())) == INVALID_FILE_ATTRIBUTES) { CreateDirectoryA(m_pathToSave.c_str(), 0); } #endif }
bool FilesDownload::downloadList() { string base = "http://" + host + "/" + path; // On parcours la liste for (size_t i = 0; i < filesToDownload.size(); i++) { string file = filesToDownload[i]; size_t pos; string link; while( (pos = file.find("/")) != string::npos ) { link += file.substr(0, pos); if (!dirExists(link)) CreateDirectoryA(link.c_str(), NULL); link += "/"; file.erase(0, pos + 1); } link += file; // On télécharge le fichier if (!Download::download(base + link, link)) { printf("Erreur download: %s", link.c_str()); return false; } } return true; }
void SessionServer::InitializeFileLogger() { time_t curTime = time(NULL); tm curTM; localtime_s(&curTM, &curTime); if (!m_logWriter) { std::string filePath = s_defaultLogBaseLocation; filePath += "SharingServiceLogs"; filePath += "\\"; BOOL dirResult = CreateDirectoryA(filePath.c_str(), NULL); if (dirResult || GetLastError() == ERROR_ALREADY_EXISTS) { // Either we succeeded in creating the directory or it already exists. std::string fileName = "SharingService_"; fileName += std::to_string(curTM.tm_year + 1900); fileName += std::to_string(curTM.tm_mon + 1); fileName += std::to_string(curTM.tm_mday); fileName += ".log"; std::string fullPath = filePath + GetLogFileName(curTM); m_logWriter = new FileLogWriter(); m_logWriter->AddTargetFile(fullPath); } } m_logger = new Logger(); m_logger->SetWriter(m_logWriter); std::string curTimeString = GetCurrentDateTimeString(curTM); LogInfo(" ** Logging Session Began at %s", curTimeString.c_str()); }
/*********************************************************************** * MakeSureDirectoryPathExists (DBGHELP.@) */ BOOL WINAPI MakeSureDirectoryPathExists(PCSTR DirPath) { char path[MAX_PATH]; const char *p = DirPath; int n; if (p[0] && p[1] == ':') p += 2; while (*p == '\\') p++; /* skip drive root */ while ((p = strchr(p, '\\')) != NULL) { n = p - DirPath + 1; memcpy(path, DirPath, n); path[n] = '\0'; if( !CreateDirectoryA(path, NULL) && (GetLastError() != ERROR_ALREADY_EXISTS)) return FALSE; p++; } if (GetLastError() == ERROR_ALREADY_EXISTS) SetLastError(ERROR_SUCCESS); return TRUE; }
static void test_LaunchINFSection(void) { HRESULT hr; char cmdline[MAX_PATH]; static char file[] = "test.inf,DefaultInstall,4,0"; /* The 'No UI' flag seems to have no effect whatsoever on Windows. * So only do this test in interactive mode. */ if (winetest_interactive) { /* try an invalid cmdline */ hr = pLaunchINFSection(NULL, NULL, NULL, 0); ok(hr == 1, "Expected 1, got %d\n", hr); } CreateDirectoryA("one", NULL); create_inf_file("one\\test.inf"); /* try a full path to the INF */ lstrcpy(cmdline, CURR_DIR); lstrcat(cmdline, "\\"); lstrcat(cmdline, "one\\test.inf,DefaultInstall,,4"); hr = pLaunchINFSection(NULL, NULL, cmdline, 0); ok(hr == 0, "Expected 0, got %d\n", hr); DeleteFileA("one\\test.inf"); RemoveDirectoryA("one"); create_inf_file("test.inf"); /* try just the INF filename */ hr = pLaunchINFSection(NULL, NULL, file, 0); ok(hr == 0, "Expected 0, got %d\n", hr); DeleteFileA("test.inf"); }
bool GameDeploymentUtil::createDirectory( const std::string& dir ) { Array< std::string > pathElements; StringUtils::tokenize( dir, "/\\", pathElements ); std::string currentPath = pathElements[0]; uint count = pathElements.size(); for( uint i = 1; i < count; ++i ) { currentPath += "\\" + pathElements[i]; bool result = CreateDirectoryA( currentPath.c_str(), NULL ); if ( !result ) { DWORD errCode = GetLastError(); if ( errCode != ERROR_ALREADY_EXISTS ) { // the directory couldn't be created for some reason return false; } } } return true; }
bool createDirectory(const cv::String& path) { CV_INSTRUMENT_REGION(); #if defined WIN32 || defined _WIN32 || defined WINCE #ifdef WINRT wchar_t wpath[MAX_PATH]; size_t copied = mbstowcs(wpath, path.c_str(), MAX_PATH); CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1)); int result = CreateDirectoryA(wpath, NULL) ? 0 : -1; #else int result = _mkdir(path.c_str()); #endif #elif defined __linux__ || defined __APPLE__ || defined __HAIKU__ || defined __FreeBSD__ int result = mkdir(path.c_str(), 0777); #else int result = -1; #endif if (result == -1) { return isDirectory(path); } return true; }
void VDCreateDirectory(const wchar_t *path) { // can't create dir with trailing slash VDStringW::size_type l(wcslen(path)); if (l) { const wchar_t c = path[l-1]; if (c == L'/' || c == L'\\') { VDCreateDirectory(VDStringW(path, l-1).c_str()); return; } } BOOL succeeded; if (!(GetVersion() & 0x80000000)) { succeeded = CreateDirectoryW(path, NULL); } else { succeeded = CreateDirectoryA(VDTextWToA(path).c_str(), NULL); } if (!succeeded) throw MyWin32Error("Cannot create directory: %%s", GetLastError()); }
std::string cab_extract(std::string cabfilepath) { string tmpdir = FileUtils::createTempFileName("JSMOOTHDIR"); CreateDirectoryA(tmpdir.c_str(), 0); printf("Created %s\n", tmpdir.c_str()); if (!SetupIterateCabinet(cabfilepath.c_str(), 0, (PSP_FILE_CALLBACK)CabinetCallback, (void *)tmpdir.c_str())) { // DEBUG("Error extract cabinet) // FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | // FORMAT_MESSAGE_FROM_SYSTEM | // FORMAT_MESSAGE_IGNORE_INSERTS, NULL, // GetLastError(), MAKELANGID(LANG_NEUTRAL, // SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); // MessageBox( NULL,(LPTSTR) lpMsgBuf, // "SetupIterateCabinet() Error :", // MB_OK | MB_ICONEXCLAMATION | MB_TOPMOST); printf("Error extracting the cab %s\n", cabfilepath.c_str()); } return tmpdir; }
bool createDir(std::string dirName) { if(!fileExists(dirName.c_str(), true)) return CreateDirectoryA(dirName.c_str(), 0)!=0; return true; }
bool createDirectory(const String &path) { return CreateDirectoryA(path, NULL); }
static void test_AddDelBackupEntry(void) { BOOL ret; HRESULT res; CHAR path[MAX_PATH]; CHAR windir[MAX_PATH]; lstrcpyA(path, CURR_DIR); lstrcatA(path, "\\backup\\basename.INI"); /* native AddDelBackupEntry crashes if lpcszBaseName is NULL */ /* try a NULL file list */ res = pAddDelBackupEntry(NULL, "backup", "basename", AADBE_ADD_ENTRY); ok(res == S_OK, "Expected S_OK, got %d\n", res); ok(!DeleteFileA(path), "Expected path to not exist\n"); lstrcpyA(path, CURR_DIR); lstrcatA(path, "\\backup\\.INI"); /* try an empty base name */ res = pAddDelBackupEntry("one\0two\0three\0", "backup", "", AADBE_ADD_ENTRY); ok(res == S_OK, "Expected S_OK, got %d\n", res); ok(!DeleteFileA(path), "Expected path to not exist\n"); lstrcpyA(path, CURR_DIR); lstrcatA(path, "\\basename.INI"); /* try an invalid flag */ res = pAddDelBackupEntry("one\0two\0three\0", NULL, "basename", 0); ok(res == S_OK, "Expected S_OK, got %d\n", res); ok(!DeleteFileA(path), "Expected path to not exist\n"); lstrcpyA(path, "c:\\basename.INI"); /* create the INF file */ res = pAddDelBackupEntry("one\0two\0three\0", "c:\\", "basename", AADBE_ADD_ENTRY); ok(res == S_OK, "Expected S_OK, got %d\n", res); if (GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES) { ok(check_ini_file_attr(path), "Expected ini file to be hidden\n"); ok(DeleteFileA(path), "Expected path to exist\n"); } else win_skip("Test file could not be created\n"); lstrcpyA(path, CURR_DIR); lstrcatA(path, "\\backup\\basename.INI"); /* try to create the INI file in a nonexistent directory */ RemoveDirectoryA("backup"); res = pAddDelBackupEntry("one\0two\0three\0", "backup", "basename", AADBE_ADD_ENTRY); ok(res == S_OK, "Expected S_OK, got %d\n", res); ok(!check_ini_file_attr(path), "Expected ini file to not be hidden\n"); ok(!DeleteFileA(path), "Expected path to not exist\n"); /* try an existent, relative backup directory */ CreateDirectoryA("backup", NULL); res = pAddDelBackupEntry("one\0two\0three\0", "backup", "basename", AADBE_ADD_ENTRY); ok(res == S_OK, "Expected S_OK, got %d\n", res); ok(check_ini_file_attr(path), "Expected ini file to be hidden\n"); ok(DeleteFileA(path), "Expected path to exist\n"); RemoveDirectoryA("backup"); GetWindowsDirectoryA(windir, sizeof(windir)); sprintf(path, "%s\\basename.INI", windir); /* try a NULL backup dir, INI is created in the windows directory */ res = pAddDelBackupEntry("one\0two\0three\0", NULL, "basename", AADBE_ADD_ENTRY); ok(res == S_OK, "Expected S_OK, got %d\n", res); /* remove the entries with AADBE_DEL_ENTRY */ SetFileAttributesA(path, FILE_ATTRIBUTE_NORMAL); res = pAddDelBackupEntry("one\0three\0", NULL, "basename", AADBE_DEL_ENTRY); SetFileAttributesA(path, FILE_ATTRIBUTE_NORMAL); ok(res == S_OK, "Expected S_OK, got %d\n", res); ret = DeleteFileA(path); ok(ret == TRUE || broken(ret == FALSE), /* win98 */ "Expected path to exist\n"); }
static void test_ExtractFiles(void) { HRESULT hr; char destFolder[MAX_PATH]; lstrcpyA(destFolder, CURR_DIR); lstrcatA(destFolder, "\\"); lstrcatA(destFolder, "dest"); /* try NULL cab file */ hr = pExtractFiles(NULL, destFolder, 0, NULL, NULL, 0); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr); ok(RemoveDirectoryA("dest"), "Expected dest to exist\n"); /* try NULL destination */ hr = pExtractFiles("extract.cab", NULL, 0, NULL, NULL, 0); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr); ok(!RemoveDirectoryA("dest"), "Expected dest to not exist\n"); /* extract all files in the cab to nonexistent destination directory */ hr = pExtractFiles("extract.cab", destFolder, 0, NULL, NULL, 0); ok(hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) || hr == E_FAIL, /* win95 */ "Expected %08x or %08x, got %08x\n", E_FAIL, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), hr); ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n"); ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n"); ok(!RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to not exist\n"); ok(!RemoveDirectoryA("dest"), "Expected dest to not exist\n"); /* extract all files in the cab to the destination directory */ CreateDirectoryA("dest", NULL); hr = pExtractFiles("extract.cab", destFolder, 0, NULL, NULL, 0); ok(hr == S_OK, "Expected S_OK, got %d\n", hr); ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n"); ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n"); ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n"); ok(DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to exist\n"); ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n"); /* extract all files to a relative destination directory */ hr = pExtractFiles("extract.cab", "dest", 0, NULL, NULL, 0); ok(hr == S_OK, "Expected S_OK, got %d\n", hr); ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n"); ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n"); ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n"); ok(DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to exist\n"); ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n"); /* only extract two of the files from the cab */ hr = pExtractFiles("extract.cab", "dest", 0, "a.txt:testdir\\c.txt", NULL, 0); ok(hr == S_OK, "Expected S_OK, got %d\n", hr); ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n"); ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n"); ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n"); ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n"); ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n"); /* use valid chars before and after file list */ hr = pExtractFiles("extract.cab", "dest", 0, " :\t: a.txt:testdir\\c.txt \t:", NULL, 0); ok(hr == S_OK, "Expected S_OK, got %d\n", hr); ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n"); ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n"); ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n"); ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n"); ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n"); /* use invalid chars before and after file list */ hr = pExtractFiles("extract.cab", "dest", 0, " +-\\ a.txt:testdir\\c.txt a_:", NULL, 0); ok(hr == E_FAIL, "Expected E_FAIL, got %d\n", hr); ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n"); ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n"); ok(!RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to not exist\n"); /* try an empty file list */ hr = pExtractFiles("extract.cab", "dest", 0, "", NULL, 0); ok(hr == E_FAIL, "Expected E_FAIL, got %d\n", hr); ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n"); ok(!RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to not exist\n"); /* try a nonexistent file in the file list */ hr = pExtractFiles("extract.cab", "dest", 0, "a.txt:idontexist:testdir\\c.txt", NULL, 0); ok(hr == E_FAIL, "Expected E_FAIL, got %d\n", hr); ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n"); ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n"); ok(!RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to not exist\n"); }
HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD nMaxInstances, DWORD nOutBufferSize, DWORD nInBufferSize, DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES lpSecurityAttributes) { int status; HANDLE hNamedPipe; char* lpPipePath; unsigned long flags; struct sockaddr_un s; WINPR_NAMED_PIPE* pNamedPipe; if (!lpName) return INVALID_HANDLE_VALUE; pNamedPipe = (WINPR_NAMED_PIPE*) malloc(sizeof(WINPR_NAMED_PIPE)); hNamedPipe = (HANDLE) pNamedPipe; WINPR_HANDLE_SET_TYPE(pNamedPipe, HANDLE_TYPE_NAMED_PIPE); pNamedPipe->name = _strdup(lpName); pNamedPipe->dwOpenMode = dwOpenMode; pNamedPipe->dwPipeMode = dwPipeMode; pNamedPipe->nMaxInstances = nMaxInstances; pNamedPipe->nOutBufferSize = nOutBufferSize; pNamedPipe->nInBufferSize = nInBufferSize; pNamedPipe->nDefaultTimeOut = nDefaultTimeOut; pNamedPipe->dwFlagsAndAttributes = dwOpenMode; pNamedPipe->lpFileName = GetNamedPipeNameWithoutPrefixA(lpName); pNamedPipe->lpFilePath = GetNamedPipeUnixDomainSocketFilePathA(lpName); lpPipePath = GetNamedPipeUnixDomainSocketBaseFilePathA(); if (!PathFileExistsA(lpPipePath)) CreateDirectoryA(lpPipePath, 0); free(lpPipePath); pNamedPipe->clientfd = -1; pNamedPipe->serverfd = socket(PF_LOCAL, SOCK_STREAM, 0); if (0) { flags = fcntl(pNamedPipe->serverfd, F_GETFL); flags = flags | O_NONBLOCK; fcntl(pNamedPipe->serverfd, F_SETFL, flags); } ZeroMemory(&s, sizeof(struct sockaddr_un)); s.sun_family = AF_UNIX; strcpy(s.sun_path, pNamedPipe->lpFilePath); unlink(s.sun_path); status = bind(pNamedPipe->serverfd, (struct sockaddr*) &s, sizeof(struct sockaddr_un)); if (status == 0) { status = listen(pNamedPipe->serverfd, 2); if (status == 0) { UnixChangeFileMode(pNamedPipe->lpFilePath, 0xFFFF); } } return hNamedPipe; }
//--------------------------------------------------------------------- bool FileSystemLayer::createDirectory(const Ogre::String& path) { return CreateDirectoryA(path.c_str(), NULL) != 0 || GetLastError() == ERROR_ALREADY_EXISTS; }
static sal_Bool GetSpecialFolder(rtl_uString **strPath, int nFolder) { sal_Bool bRet = sal_False; HINSTANCE hLibrary; sal_Char PathA[_MAX_PATH]; sal_Unicode PathW[_MAX_PATH]; if ((hLibrary = LoadLibrary("shell32.dll")) != NULL) { BOOL (WINAPI *pSHGetSpecialFolderPathA)(HWND, LPSTR, int, BOOL); BOOL (WINAPI *pSHGetSpecialFolderPathW)(HWND, LPWSTR, int, BOOL); pSHGetSpecialFolderPathA = (BOOL (WINAPI *)(HWND, LPSTR, int, BOOL))GetProcAddress(hLibrary, "SHGetSpecialFolderPathA"); pSHGetSpecialFolderPathW = (BOOL (WINAPI *)(HWND, LPWSTR, int, BOOL))GetProcAddress(hLibrary, "SHGetSpecialFolderPathW"); if (pSHGetSpecialFolderPathA) { if (pSHGetSpecialFolderPathA(GetActiveWindow(), PathA, nFolder, TRUE)) { rtl_string2UString( strPath, PathA, (sal_Int32) strlen(PathA), osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS); OSL_ASSERT(*strPath != NULL); bRet = sal_True; } } else if (pSHGetSpecialFolderPathW) { if (pSHGetSpecialFolderPathW(GetActiveWindow(), PathW, nFolder, TRUE)) { rtl_uString_newFromStr( strPath, PathW); bRet = sal_True; } } else { HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *) = (HRESULT (WINAPI *)(HWND, int, LPITEMIDLIST *))GetProcAddress(hLibrary, "SHGetSpecialFolderLocation"); BOOL (WINAPI *pSHGetPathFromIDListA)(LPCITEMIDLIST, LPSTR) = (BOOL (WINAPI *)(LPCITEMIDLIST, LPSTR))GetProcAddress(hLibrary, "SHGetPathFromIDListA"); BOOL (WINAPI *pSHGetPathFromIDListW)(LPCITEMIDLIST, LPWSTR) = (BOOL (WINAPI *)(LPCITEMIDLIST, LPWSTR))GetProcAddress(hLibrary, "SHGetPathFromIDListW"); HRESULT (WINAPI *pSHGetMalloc)(LPMALLOC *) = (HRESULT (WINAPI *)(LPMALLOC *))GetProcAddress(hLibrary, "SHGetMalloc"); if (pSHGetSpecialFolderLocation && (pSHGetPathFromIDListA || pSHGetPathFromIDListW ) && pSHGetMalloc ) { LPITEMIDLIST pidl; LPMALLOC pMalloc; HRESULT hr; hr = pSHGetSpecialFolderLocation(GetActiveWindow(), nFolder, &pidl); /* Get SHGetSpecialFolderLocation fails if directory does not exists. */ /* If it fails we try to create the directory and redo the call */ if (! SUCCEEDED(hr)) { HKEY hRegKey; if (RegOpenKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", &hRegKey) == ERROR_SUCCESS) { LONG lRet; DWORD lSize = SAL_N_ELEMENTS(PathA); DWORD Type = REG_SZ; switch (nFolder) { case CSIDL_APPDATA: lRet = RegQueryValueEx(hRegKey, "AppData", NULL, &Type, (LPBYTE)PathA, &lSize); break; case CSIDL_PERSONAL: lRet = RegQueryValueEx(hRegKey, "Personal", NULL, &Type, (LPBYTE)PathA, &lSize); break; default: lRet = -1l; } if ((lRet == ERROR_SUCCESS) && (Type == REG_SZ)) { if (_access(PathA, 0) < 0) CreateDirectory(PathA, NULL); hr = pSHGetSpecialFolderLocation(GetActiveWindow(), nFolder, &pidl); } RegCloseKey(hRegKey); } } if (SUCCEEDED(hr)) { if (pSHGetPathFromIDListW && pSHGetPathFromIDListW(pidl, PathW)) { /* if directory does not exist, create it */ if (_waccess(PathW, 0) < 0) CreateDirectoryW(PathW, NULL); rtl_uString_newFromStr( strPath, PathW); bRet = sal_True; } else if (pSHGetPathFromIDListA && pSHGetPathFromIDListA(pidl, PathA)) { /* if directory does not exist, create it */ if (_access(PathA, 0) < 0) CreateDirectoryA(PathA, NULL); rtl_string2UString( strPath, PathA, (sal_Int32) strlen(PathA), osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS); OSL_ASSERT(*strPath != NULL); bRet = sal_True; } } if (SUCCEEDED(pSHGetMalloc(&pMalloc))) { pMalloc->lpVtbl->Free(pMalloc, pidl); pMalloc->lpVtbl->Release(pMalloc); } } } } FreeLibrary(hLibrary); return bRet; }
/* Find first valid drive letter that is neither newdir[0] nor curDrive */ drives = GetLogicalDrives() & ~(1<<(newdir[0]-'A')); if( *curDrive != NOT_A_VALID_DRIVE) drives &= ~(1<<(*curDrive-'A')); if( drives) for( *otherDrive='A'; (drives & 1) == 0; drives>>=1, (*otherDrive)++); else trace( "Could not find alternative drive, some tests will not be conducted.\n"); /* Do some CreateDirectoryA tests */ /* It would be nice to do test the SECURITY_ATTRIBUTES, but I don't really understand how they work. More formal tests should be done along with CreateFile tests */ ok((id=GetTempFileNameA(tmppath,"path",0,newdir)),"GetTempFileNameA failed\n"); ok(CreateDirectoryA(newdir,NULL)==0, "CreateDirectoryA succeeded even though a file of the same name exists\n"); ok(DeleteFileA(newdir),"Couldn't delete the temporary file we just created\n"); ok(CreateDirectoryA(newdir,NULL),"CreateDirectoryA failed\n"); /* Create some files to test other functions. Note, we will test CreateFileA at some later point */ sprintf(tmpstr,"%s\\%s",newdir,SHORTDIR); ok(CreateDirectoryA(tmpstr,NULL),"CreateDirectoryA failed\n"); sprintf(tmpstr,"%s\\%s",newdir,LONGDIR); ok(CreateDirectoryA(tmpstr,NULL),"CreateDirectoryA failed\n"); bRes = CreateDirectoryA("c:",NULL); ok(!bRes && (GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == ERROR_ALREADY_EXISTS), "CreateDirectoryA(\"c:\" should have failed (%ld)\n", GetLastError()); bRes = CreateDirectoryA("c:\\",NULL);
bool FileUtils::createDirectory(const std::string& path) { CCASSERT(!path.empty(), "Invalid path"); if (isDirectoryExist(path)) return true; // Split the path size_t start = 0; size_t found = path.find_first_of("/\\", start); std::string subpath; std::vector<std::string> dirs; if (found != std::string::npos) { while (true) { subpath = path.substr(start, found - start + 1); if (!subpath.empty()) dirs.push_back(subpath); start = found+1; found = path.find_first_of("/\\", start); if (found == std::string::npos) { if (start < path.length()) { dirs.push_back(path.substr(start)); } break; } } } #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) WIN32_FILE_ATTRIBUTE_DATA wfad; std::wstring wpath(path.begin(), path.end()); if (!(GetFileAttributesEx(wpath.c_str(), GetFileExInfoStandard, &wfad))) { subpath = ""; for(unsigned int i = 0 ; i < dirs.size() ; ++i) { subpath += dirs[i]; if (i > 0 && !isDirectoryExist(subpath)) { std::wstring wsubpath(subpath.begin(), subpath.end()); BOOL ret = CreateDirectory(wsubpath.c_str(), NULL); if (!ret && ERROR_ALREADY_EXISTS != GetLastError()) { return false; } } } } return true; #elif (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) if ((GetFileAttributesA(path.c_str())) == INVALID_FILE_ATTRIBUTES) { subpath = ""; for (int i = 0; i < dirs.size(); ++i) { subpath += dirs[i]; if (!isDirectoryExist(subpath)) { BOOL ret = CreateDirectoryA(subpath.c_str(), NULL); if (!ret && ERROR_ALREADY_EXISTS != GetLastError()) { return false; } } } } return true; #else DIR *dir = NULL; // Create path recursively subpath = ""; for (int i = 0; i < dirs.size(); ++i) { subpath += dirs[i]; dir = opendir(subpath.c_str()); if (!dir) { // directory doesn't exist, should create a new one int ret = mkdir(subpath.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); if (ret != 0 && (errno != EEXIST)) { // current directory can not be created, sub directories can not be created too // should return return false; } } else { // directory exists, should close opened dir closedir(dir); } } return true; #endif }
static void delnode_test(void) { HRESULT hr; HANDLE hn; CHAR currDir[MAX_PATH]; int currDirLen; /* Native DelNode apparently does not support relative paths, so we use absolute paths for testing */ currDirLen = GetCurrentDirectoryA(sizeof(currDir) / sizeof(CHAR), currDir); assert(currDirLen > 0 && currDirLen < sizeof(currDir) / sizeof(CHAR)); if(currDir[currDirLen - 1] == '\\') currDir[--currDirLen] = 0; /* Simple tests; these should fail. */ hr = pDelNode(NULL, 0); ok (hr == E_FAIL, "DelNode called with NULL pathname should return E_FAIL\n"); hr = pDelNode("", 0); ok (hr == E_FAIL, "DelNode called with empty pathname should return E_FAIL\n"); /* Test deletion of a file. */ hn = CreateFile("DelNodeTestFile1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); assert(hn != INVALID_HANDLE_VALUE); CloseHandle(hn); hr = pDelNode(lstrcat(currDir, "\\DelNodeTestFile1"), 0); ok (hr == S_OK, "DelNode failed deleting a single file\n"); currDir[currDirLen] = '\0'; /* Test deletion of an empty directory. */ CreateDirectoryA("DelNodeTestDir", NULL); hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0); ok (hr == S_OK, "DelNode failed deleting an empty directory\n"); currDir[currDirLen] = '\0'; /* Test deletion of a directory containing one file. */ CreateDirectoryA("DelNodeTestDir", NULL); hn = CreateFile("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); assert(hn != INVALID_HANDLE_VALUE); CloseHandle(hn); hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0); ok (hr == S_OK, "DelNode failed deleting a directory containing one file\n"); currDir[currDirLen] = '\0'; /* Test deletion of a directory containing multiple files. */ CreateDirectoryA("DelNodeTestDir", NULL); hn = CreateFile("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); assert(hn != INVALID_HANDLE_VALUE); CloseHandle(hn); hn = CreateFile("DelNodeTestDir\\DelNodeTestFile2", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); assert(hn != INVALID_HANDLE_VALUE); CloseHandle(hn); hn = CreateFile("DelNodeTestDir\\DelNodeTestFile3", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); assert(hn != INVALID_HANDLE_VALUE); CloseHandle(hn); hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0); ok (hr == S_OK, "DelNode failed deleting a directory containing multiple files\n"); currDir[currDirLen] = '\0'; }
T_bool blpp_fs_CreateDirectoryBypassA(PCT_str lpPathName,LPSECURITY_ATTRIBUTES lpSecurityAttributes) { filePathLinkA link(lpPathName); return CreateDirectoryA(link.getLink().c_str(),lpSecurityAttributes); }
/* * vislib::sys::Path::MakeDirectory */ void vislib::sys::Path::MakeDirectory(const StringA& path) { Stack<StringA> missingParts; StringA firstBuilt; StringA curPath = Resolve(path); while (!File::Exists(curPath)) { StringA::Size pos = curPath.FindLast(SEPARATOR_A); if (pos != StringA::INVALID_POS) { missingParts.Push(curPath.Substring(pos + 1)); if (missingParts.Peek()->IsEmpty()) { // Remove empty directories as the incremental directory // creation later on will fail for these. missingParts.Pop(); } curPath.Truncate(pos); } else { // Problem: No Separators left, but directory still does not exist. #ifdef _WIN32 throw vislib::sys::SystemException(ERROR_INVALID_NAME, __FILE__, __LINE__); #else /* _WIN32 */ throw vislib::sys::SystemException(EINVAL, __FILE__, __LINE__); #endif /* _WIN32 */ } } // curPath exists if (!File::IsDirectory(curPath)) { // the latest existing directory is not a directory (may be a file?) #ifdef _WIN32 throw vislib::sys::SystemException(ERROR_DIRECTORY, __FILE__, __LINE__); #else /* _WIN32 */ throw vislib::sys::SystemException(EEXIST, __FILE__, __LINE__); #endif /* _WIN32 */ } while (!missingParts.IsEmpty()) { curPath += SEPARATOR_A; curPath += missingParts.Pop(); #ifdef _WIN32 if (CreateDirectoryA(curPath, NULL) != 0) { #else /* _WIN32 */ if (mkdir(curPath, S_IRWXG | S_IRWXO | S_IRWXU) == 0) { // TODO: Check #endif /* _WIN32 */ // success, so go on. if (firstBuilt.IsEmpty()) { firstBuilt = curPath; } } else { DWORD errorCode = GetLastError(); try { // failure, so try to remove already created paths and throw exception. DeleteDirectory(firstBuilt, true); } catch(...) { } throw vislib::sys::SystemException(errorCode, __FILE__, __LINE__); } } // we are done! } /* * vislib::sys::Path::MakeDirectory */ void vislib::sys::Path::MakeDirectory(const StringW& path) { #ifdef _WIN32 Stack<StringW> missingParts; StringW firstBuilt; StringW curPath = Resolve(path); while (!File::Exists(curPath)) { StringW::Size pos = curPath.FindLast(SEPARATOR_W); if (pos != StringW::INVALID_POS) { missingParts.Push(curPath.Substring(pos + 1)); if (missingParts.Peek()->IsEmpty()) { // Remove empty directories as the incremental directory // creation later on will fail for these. missingParts.Pop(); } curPath.Truncate(pos); } else { // Problem: No Separators left, but directory still does not exist. throw vislib::sys::SystemException(ERROR_INVALID_NAME, __FILE__, __LINE__); } } // curPath exists if (!File::IsDirectory(curPath)) { // the latest existing directory is not a directory (may be a file?) throw vislib::sys::SystemException(ERROR_DIRECTORY, __FILE__, __LINE__); } while (!missingParts.IsEmpty()) { curPath += SEPARATOR_W; curPath += missingParts.Pop(); if (CreateDirectoryW(curPath, NULL) != 0) { // success, so go on. if (firstBuilt.IsEmpty()) { firstBuilt = curPath; } } else { DWORD errorCode = GetLastError(); try { // failure, so try to remove already created paths and throw exception. DeleteDirectory(firstBuilt, true); } catch(...) { } throw vislib::sys::SystemException(errorCode, __FILE__, __LINE__); } } // we are done! #else /* _WIN32 */ // linux is stupid MakeDirectory(W2A(path)); #endif /* _WIN32 */ }
/*********************************************************************** * CreateDirectory (KERNEL.144) */ BOOL16 WINAPI CreateDirectory16( LPCSTR path, LPVOID dummy ) { return CreateDirectoryA( path, NULL ); }
static void test_inffilelist(void) { static const char inffile2[] = "test2.inf"; static const WCHAR inffile2W[] = {'t','e','s','t','2','.','i','n','f',0}; static const char invalid_inf[] = "invalid.inf"; static const WCHAR invalid_infW[] = {'i','n','v','a','l','i','d','.','i','n','f',0}; static const char *inf = "[Version]\n" "Signature=\"$Chicago$\""; static const char *inf2 = "[Version]\n" "Signature=\"$CHICAGO$\""; static const char *infNT = "[Version]\n" "Signature=\"$WINDOWS NT$\""; WCHAR *p, *ptr; char dirA[MAX_PATH]; WCHAR dir[MAX_PATH] = { 0 }; WCHAR buffer[MAX_PATH] = { 0 }; DWORD expected, outsize; BOOL ret; if(!pSetupGetInfFileListW) { win_skip("SetupGetInfFileListW not present\n"); return; } /* NULL means %windir%\\inf * get the value as reference */ expected = 0; SetLastError(0xdeadbeef); ret = pSetupGetInfFileListW(NULL, INF_STYLE_WIN4, NULL, 0, &expected); if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) { win_skip("SetupGetInfFileListW not implemented\n"); return; } ok(ret, "expected SetupGetInfFileListW to succeed! Error: %d\n", GetLastError()); ok(expected > 0, "expected required buffersize to be at least 1\n"); /* check if an empty string doesn't behaves like NULL */ outsize = 0; SetLastError(0xdeadbeef); ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize); ok(!ret, "expected SetupGetInfFileListW to fail!\n"); /* create a private directory, the temp directory may contain some * inf files left over from old installations */ if (!GetTempFileNameA(CURR_DIR, "inftest", 1, dirA)) { win_skip("GetTempFileNameA failed with error %d\n", GetLastError()); return; } if (!CreateDirectoryA(dirA, NULL )) { win_skip("CreateDirectoryA(%s) failed with error %d\n", dirA, GetLastError()); return; } if (!SetCurrentDirectoryA(dirA)) { win_skip("SetCurrentDirectoryA failed with error %d\n", GetLastError()); RemoveDirectoryA(dirA); return; } MultiByteToWideChar(CP_ACP, 0, dirA, -1, dir, MAX_PATH); /* check a not existing directory */ ptr = dir + lstrlenW(dir); MultiByteToWideChar(CP_ACP, 0, "\\not_existent", -1, ptr, MAX_PATH - lstrlenW(dir)); outsize = 0xffffffff; SetLastError(0xdeadbeef); ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize); ok(ret, "expected SetupGetInfFileListW to succeed!\n"); ok(outsize == 1, "expected required buffersize to be 1, got %d\n", outsize); ok(ERROR_PATH_NOT_FOUND == GetLastError(), "expected error ERROR_PATH_NOT_FOUND, got %d\n", GetLastError()); create_inf_file(inffile, inf); create_inf_file(inffile2, inf); create_inf_file(invalid_inf, "This content does not match the inf file format"); /* pass a filename instead of a directory */ *ptr = '\\'; MultiByteToWideChar(CP_ACP, 0, invalid_inf, -1, ptr+1, MAX_PATH - lstrlenW(dir)); outsize = 0xffffffff; SetLastError(0xdeadbeef); ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize); ok(!ret, "expected SetupGetInfFileListW to fail!\n"); ok(ERROR_DIRECTORY == GetLastError(), "expected error ERROR_DIRECTORY, got %d\n", GetLastError()); /* make the filename look like directory */ dir[1 + lstrlenW(dir)] = 0; dir[lstrlenW(dir)] = '\\'; SetLastError(0xdeadbeef); ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize); ok(!ret, "expected SetupGetInfFileListW to fail!\n"); ok(ERROR_DIRECTORY == GetLastError(), "expected error ERROR_DIRECTORY, got %d\n", GetLastError()); /* now check the buffer content of a vaild call */ *ptr = 0; expected = 3 + strlen(inffile) + strlen(inffile2); ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, buffer, MAX_PATH, &outsize); ok(ret, "expected SetupGetInfFileListW to succeed!\n"); ok(expected == outsize, "expected required buffersize to be %d, got %d\n", expected, outsize); for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1) ok(!lstrcmpW(p,inffile2W) || !lstrcmpW(p,inffileW), "unexpected filename %s\n",wine_dbgstr_w(p)); /* upper case value */ create_inf_file(inffile2, inf2); ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, buffer, MAX_PATH, &outsize); ok(ret, "expected SetupGetInfFileListW to succeed!\n"); ok(expected == outsize, "expected required buffersize to be %d, got %d\n", expected, outsize); for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1) ok(!lstrcmpW(p,inffile2W) || !lstrcmpW(p,inffileW), "unexpected filename %s\n",wine_dbgstr_w(p)); /* signature Windows NT is also inf style win4 */ create_inf_file(inffile2, infNT); expected = 3 + strlen(inffile) + strlen(inffile2); ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, buffer, MAX_PATH, &outsize); ok(ret, "expected SetupGetInfFileListW to succeed!\n"); ok(expected == outsize, "expected required buffersize to be %d, got %d\n", expected, outsize); for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1) ok(!lstrcmpW(p,inffile2W) || !lstrcmpW(p,inffileW), "unexpected filename %s\n",wine_dbgstr_w(p)); /* old style */ expected = 2 + strlen(invalid_inf); ret = pSetupGetInfFileListW(dir, INF_STYLE_OLDNT, buffer, MAX_PATH, &outsize); ok(ret, "expected SetupGetInfFileListW to succeed!\n"); ok(expected == outsize, "expected required buffersize to be %d, got %d\n", expected, outsize); for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1) ok(!lstrcmpW(p,invalid_infW), "unexpected filename %s\n",wine_dbgstr_w(p)); /* mixed style */ expected = 4 + strlen(inffile) + strlen(inffile2) + strlen(invalid_inf); ret = pSetupGetInfFileListW(dir, INF_STYLE_OLDNT | INF_STYLE_WIN4, buffer, MAX_PATH, &outsize); ok(ret, "expected SetupGetInfFileListW to succeed!\n"); ok(expected == outsize, "expected required buffersize to be %d, got %d\n", expected, outsize); for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1) ok(!lstrcmpW(p,inffile2W) || !lstrcmpW(p,inffileW) || !lstrcmpW(p,invalid_infW), "unexpected filename %s\n",wine_dbgstr_w(p)); DeleteFileA(inffile); DeleteFileA(inffile2); DeleteFileA(invalid_inf); SetCurrentDirectoryA(CURR_DIR); RemoveDirectoryA(dirA); }
HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD nMaxInstances, DWORD nOutBufferSize, DWORD nInBufferSize, DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES lpSecurityAttributes) { int index; HANDLE hNamedPipe = INVALID_HANDLE_VALUE; char* lpPipePath; struct sockaddr_un s; WINPR_NAMED_PIPE* pNamedPipe = NULL; int serverfd = -1; NamedPipeServerSocketEntry* baseSocket = NULL; if (!lpName) return INVALID_HANDLE_VALUE; InitWinPRPipeModule(); pNamedPipe = (WINPR_NAMED_PIPE*) calloc(1, sizeof(WINPR_NAMED_PIPE)); if (!pNamedPipe) return INVALID_HANDLE_VALUE; WINPR_HANDLE_SET_TYPE(pNamedPipe, HANDLE_TYPE_NAMED_PIPE); if (!(pNamedPipe->name = _strdup(lpName))) goto out; if (!(pNamedPipe->lpFileName = GetNamedPipeNameWithoutPrefixA(lpName))) goto out; if (!(pNamedPipe->lpFilePath = GetNamedPipeUnixDomainSocketFilePathA(lpName))) goto out; pNamedPipe->dwOpenMode = dwOpenMode; pNamedPipe->dwPipeMode = dwPipeMode; pNamedPipe->nMaxInstances = nMaxInstances; pNamedPipe->nOutBufferSize = nOutBufferSize; pNamedPipe->nInBufferSize = nInBufferSize; pNamedPipe->nDefaultTimeOut = nDefaultTimeOut; pNamedPipe->dwFlagsAndAttributes = dwOpenMode; pNamedPipe->clientfd = -1; pNamedPipe->ServerMode = TRUE; ArrayList_Lock(g_NamedPipeServerSockets); for (index = 0; index < ArrayList_Count(g_NamedPipeServerSockets); index++) { baseSocket = (NamedPipeServerSocketEntry*) ArrayList_GetItem( g_NamedPipeServerSockets, index); if (!strcmp(baseSocket->name, lpName)) { serverfd = baseSocket->serverfd; //WLog_DBG(TAG, "using shared socked resource for pipe %p (%s)", pNamedPipe, lpName); break; } } /* If this is the first instance of the named pipe... */ if (serverfd == -1) { /* Create the UNIX domain socket and start listening. */ if (!(lpPipePath = GetNamedPipeUnixDomainSocketBaseFilePathA())) goto out; if (!PathFileExistsA(lpPipePath)) { CreateDirectoryA(lpPipePath, 0); UnixChangeFileMode(lpPipePath, 0xFFFF); } free(lpPipePath); if (PathFileExistsA(pNamedPipe->lpFilePath)) { DeleteFileA(pNamedPipe->lpFilePath); } if ((serverfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { WLog_ERR(TAG, "CreateNamedPipeA: socket error, %s", strerror(errno)); goto out; } ZeroMemory(&s, sizeof(struct sockaddr_un)); s.sun_family = AF_UNIX; strcpy(s.sun_path, pNamedPipe->lpFilePath); if (bind(serverfd, (struct sockaddr*) &s, sizeof(struct sockaddr_un)) == -1) { WLog_ERR(TAG, "CreateNamedPipeA: bind error, %s", strerror(errno)); goto out; } if (listen(serverfd, 2) == -1) { WLog_ERR(TAG, "CreateNamedPipeA: listen error, %s", strerror(errno)); goto out; } UnixChangeFileMode(pNamedPipe->lpFilePath, 0xFFFF); if (!(baseSocket = (NamedPipeServerSocketEntry*) malloc(sizeof(NamedPipeServerSocketEntry)))) goto out; if (!(baseSocket->name = _strdup(lpName))) { free(baseSocket); goto out; } baseSocket->serverfd = serverfd; baseSocket->references = 0; ArrayList_Add(g_NamedPipeServerSockets, baseSocket); //WLog_DBG(TAG, "created shared socked resource for pipe %p (%s). base serverfd = %d", pNamedPipe, lpName, serverfd); } pNamedPipe->serverfd = dup(baseSocket->serverfd); //WLog_DBG(TAG, "using serverfd %d (duplicated from %d)", pNamedPipe->serverfd, baseSocket->serverfd); pNamedPipe->pfnUnrefNamedPipe = winpr_unref_named_pipe; baseSocket->references++; if (dwOpenMode & FILE_FLAG_OVERLAPPED) { #if 0 int flags = fcntl(pNamedPipe->serverfd, F_GETFL); if (flags != -1) fcntl(pNamedPipe->serverfd, F_SETFL, flags | O_NONBLOCK); #endif } hNamedPipe = (HANDLE) pNamedPipe; out: if (hNamedPipe == INVALID_HANDLE_VALUE) { if (pNamedPipe) { free((void*)pNamedPipe->name); free((void*)pNamedPipe->lpFileName); free((void*)pNamedPipe->lpFilePath); free(pNamedPipe); } if (serverfd != -1) close(serverfd); } ArrayList_Unlock(g_NamedPipeServerSockets); return hNamedPipe; }
int Fitness::getStats(int currExperimentNumber, int levelNum, bool parentTest) { if (experimentNumber != currExperimentNumber)//if the stored experiment number is not equal to the experiment number that can been passed in. { experimentNumber = currExperimentNumber; concat.str(""); concat << "..\\..\\GenerationStats\\Experiment-" << experimentNumber; directoryName = concat.str(); if (!CreateDirectoryA(directoryName.c_str(), NULL)) { if (ERROR_PATH_NOT_FOUND == GetLastError()) { cout << "Unable to Create Experiment Directory, Please Check Filepath - from spelunky_1_1 folder it should be ..\\..\\GenerationStats\\Experiment-X." << endl; } else { if (ERROR_ALREADY_EXISTS == GetLastError()) //if folder already exists. { bool done = 0; while (!done) { concat.str(""); experimentNumber++; concat << "..\\..\\GenerationStats\\Experiment-" << experimentNumber; directoryName = concat.str(); if (CreateDirectoryA(directoryName.c_str(), NULL)) { done = 1; } else if (ERROR_PATH_NOT_FOUND == GetLastError()) { cout << "Unable to Create Experiment Directory, Please Check Filepath - from spelunky_1_1 folder it should be ..\\..\\GenerationStats\\Experiment-X." << endl; } } } } } } if (!parentTest) { //Calculate standard deviation for (int i = 0; i < avgFitness.size(); i++) { populationAverage = populationAverage + avgFitness.at(i); if (avgFitness.at(i) > highestScore) { highestScore = avgFitness.at(i); } } populationAverage = populationAverage / avgFitness.size(); // This gives us the mean fitness score. for (int j = 0; j < avgFitness.size(); j++) { standardDeviation = standardDeviation + pow(avgFitness.at(j) - populationAverage, 2); } standardDeviation = standardDeviation / avgFitness.size(); //This gets us the average distance from the mean squared. standardDeviation = sqrt(standardDeviation); //This gives us the standard deviation //Send standard deviation information to file for import into Excel spreadsheet. concat.str(""); concat << "..\\..\\GenerationStats\\Experiment-" << experimentNumber << "\\GenerationsData-Level-" << levelNum << ".txt"; directoryName = concat.str(); fileStream.open(directoryName.c_str(), ofstream::app); if (fileStream.is_open()) { concat.str(""); concat << populationAverage << "," << standardDeviation << "," << highestScore; fileStream << concat.str() << endl; } else { cout << "Unable to write Generation Statistics data to file." << endl; } fileStream.close(); standardDeviation = 0; populationAverage = 0; highestScore = 0; } else { concat.str(""); concat << "..\\..\\GenerationStats\\Experiment-" << experimentNumber << "\\ParentsData-Level-" << levelNum << ".txt"; directoryName = concat.str(); fileStream.open(directoryName.c_str(), ofstream::app); if (fileStream.is_open()) { for (int k = 0; k < avgFitness.size(); k++) { concat.str(""); concat << avgFitness.at(k); fileStream << concat.str() << endl; } } else { cout << "Unable to write Parent data to file." << endl; } fileStream.close(); } return experimentNumber; }
static void test_CreateDirectoryA(void) { char tmpdir[MAX_PATH]; WCHAR curdir[MAX_PATH]; BOOL ret; ret = CreateDirectoryA(NULL, NULL); ok(ret == FALSE && (GetLastError() == ERROR_PATH_NOT_FOUND || GetLastError() == ERROR_INVALID_PARAMETER), "CreateDirectoryA(NULL): ret=%d err=%d\n", ret, GetLastError()); ret = CreateDirectoryA("", NULL); ok(ret == FALSE && (GetLastError() == ERROR_BAD_PATHNAME || GetLastError() == ERROR_PATH_NOT_FOUND), "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError()); ret = GetSystemDirectoryA(tmpdir, MAX_PATH); ok(ret < MAX_PATH, "System directory should fit into MAX_PATH\n"); GetCurrentDirectoryW(MAX_PATH, curdir); ret = SetCurrentDirectoryA(tmpdir); ok(ret == TRUE, "could not chdir to the System directory\n"); ret = CreateDirectoryA(".", NULL); ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS, "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError()); ret = CreateDirectoryA("..", NULL); ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS, "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError()); GetTempPathA(MAX_PATH, tmpdir); tmpdir[3] = 0; /* truncate the path */ ret = CreateDirectoryA(tmpdir, NULL); ok(ret == FALSE && (GetLastError() == ERROR_ALREADY_EXISTS || GetLastError() == ERROR_ACCESS_DENIED), "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError()); GetTempPathA(MAX_PATH, tmpdir); lstrcatA(tmpdir, "Please Remove Me"); ret = CreateDirectoryA(tmpdir, NULL); ok(ret == TRUE, "CreateDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError()); ret = CreateDirectoryA(tmpdir, NULL); ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS, "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError()); ret = RemoveDirectoryA(tmpdir); ok(ret == TRUE, "RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError()); lstrcatA(tmpdir, "?"); ret = CreateDirectoryA(tmpdir, NULL); ok(ret == FALSE && (GetLastError() == ERROR_INVALID_NAME || GetLastError() == ERROR_PATH_NOT_FOUND), "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError()); RemoveDirectoryA(tmpdir); tmpdir[lstrlenA(tmpdir) - 1] = '*'; ret = CreateDirectoryA(tmpdir, NULL); ok(ret == FALSE && (GetLastError() == ERROR_INVALID_NAME || GetLastError() == ERROR_PATH_NOT_FOUND), "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError()); RemoveDirectoryA(tmpdir); GetTempPathA(MAX_PATH, tmpdir); lstrcatA(tmpdir, "Please Remove Me/Please Remove Me"); ret = CreateDirectoryA(tmpdir, NULL); ok(ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND, "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError()); RemoveDirectoryA(tmpdir); /* Test behavior with a trailing dot. * The directory should be created without the dot. */ GetTempPathA(MAX_PATH, tmpdir); lstrcatA(tmpdir, "Please Remove Me."); ret = CreateDirectoryA(tmpdir, NULL); ok(ret == TRUE, "CreateDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError()); lstrcatA(tmpdir, "/Please Remove Me"); ret = CreateDirectoryA(tmpdir, NULL); ok(ret == TRUE, "CreateDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError()); ret = RemoveDirectoryA(tmpdir); ok(ret == TRUE, "RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError()); GetTempPathA(MAX_PATH, tmpdir); lstrcatA(tmpdir, "Please Remove Me"); ret = RemoveDirectoryA(tmpdir); ok(ret == TRUE, "RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError()); /* Test behavior with two trailing dots. * The directory should be created without the trailing dots. */ GetTempPathA(MAX_PATH, tmpdir); lstrcatA(tmpdir, "Please Remove Me.."); ret = CreateDirectoryA(tmpdir, NULL); ok(ret == TRUE, "CreateDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError()); lstrcatA(tmpdir, "/Please Remove Me"); ret = CreateDirectoryA(tmpdir, NULL); ok(ret == TRUE || /* On Win98 */ (ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND), /* On NT! */ "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError()); if (ret == TRUE) { ret = RemoveDirectoryA(tmpdir); ok(ret == TRUE, "RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError()); } GetTempPathA(MAX_PATH, tmpdir); lstrcatA(tmpdir, "Please Remove Me"); ret = RemoveDirectoryA(tmpdir); ok(ret == TRUE, "RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError()); /* Test behavior with a trailing space. * The directory should be created without the trailing space. */ GetTempPathA(MAX_PATH, tmpdir); lstrcatA(tmpdir, "Please Remove Me "); ret = CreateDirectoryA(tmpdir, NULL); ok(ret == TRUE, "CreateDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError()); lstrcatA(tmpdir, "/Please Remove Me"); ret = CreateDirectoryA(tmpdir, NULL); ok(ret == TRUE || /* On Win98 */ (ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND), /* On NT! */ "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError()); if (ret == TRUE) { ret = RemoveDirectoryA(tmpdir); ok(ret == TRUE, "RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError()); } GetTempPathA(MAX_PATH, tmpdir); lstrcatA(tmpdir, "Please Remove Me"); ret = RemoveDirectoryA(tmpdir); ok(ret == TRUE, "RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError()); /* Test behavior with a trailing space. * The directory should be created without the trailing spaces. */ GetTempPathA(MAX_PATH, tmpdir); lstrcatA(tmpdir, "Please Remove Me "); ret = CreateDirectoryA(tmpdir, NULL); ok(ret == TRUE, "CreateDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError()); lstrcatA(tmpdir, "/Please Remove Me"); ret = CreateDirectoryA(tmpdir, NULL); ok(ret == TRUE || /* On Win98 */ (ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND), /* On NT! */ "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError()); if (ret == TRUE) { ret = RemoveDirectoryA(tmpdir); ok(ret == TRUE, "RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError()); } GetTempPathA(MAX_PATH, tmpdir); lstrcatA(tmpdir, "Please Remove Me"); ret = RemoveDirectoryA(tmpdir); ok(ret == TRUE, "RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError()); SetCurrentDirectoryW(curdir); }
WORD TZF_Timestamp (wchar_t* const out) { SYSTEMTIME stLogTime; #if 0 // Check for Windows 8 / Server 2012 static bool __hasSystemTimePrecise = (LOBYTE (LOWORD (GetVersion ())) == 6 && HIBYTE (LOWORD (GetVersion ())) >= 2) || LOBYTE (LOWORD (GetVersion () > 6)); // More accurate timestamp is available on Windows 6.2+ if (__hasSystemTimePrecise) { FILETIME ftLogTime; GetSystemTimePreciseAsFileTime (&ftLogTime); FileTimeToSystemTime (&ftLogTime, &stLogTime); } else { #else GetLocalTime (&stLogTime); #endif //} wchar_t date [64] = { L'\0' }; wchar_t time [64] = { L'\0' }; GetDateFormat (LOCALE_INVARIANT,DATE_SHORTDATE, &stLogTime,NULL,date,64); GetTimeFormat (LOCALE_INVARIANT,TIME_NOTIMEMARKER,&stLogTime,NULL,time,64); out [0] = L'\0'; lstrcatW (out, date); lstrcatW (out, L" "); lstrcatW (out, time); lstrcatW (out, L"."); return stLogTime.wMilliseconds; } tzf_logger_t dll_log; void tzf_logger_t::close (void) { if (fLog != NULL) { fflush (fLog); fclose (fLog); } initialized = false; silent = true; DeleteCriticalSection (&log_mutex); } bool tzf_logger_t::init (const char* const szFileName, const char* const szMode) { if (initialized) return true; // // Split the path, so we can create the log directory if necessary // if (strstr (szFileName, "\\")) { char* szSplitPath = strdup (szFileName); // Replace all instances of '/' with '\' size_t len = strlen (szSplitPath); for (size_t i = 0; i < len; i++) { if (szSplitPath [i] == '/') szSplitPath [i] = '\\'; } char* szSplitter = strrchr (szSplitPath, '\\'); *szSplitter = '\0'; char path [MAX_PATH] = { '\0' }; char* subpath = strtok (szSplitPath, "\\"); // For each subdirectory, create it... while (subpath != nullptr) { strcat (path, subpath); CreateDirectoryA (path, NULL); strcat (path, "\\"); subpath = strtok (NULL, "\\"); } free (szSplitPath); } fLog = fopen (szFileName, szMode); BOOL bRet = InitializeCriticalSectionAndSpinCount (&log_mutex, 2500); if ((! bRet) || (fLog == NULL)) { silent = true; return false; } initialized = true; return initialized; } void tzf_logger_t::LogEx (bool _Timestamp, _In_z_ _Printf_format_string_ wchar_t const* const _Format, ...) { va_list _ArgList; if (! initialized) return; EnterCriticalSection (&log_mutex); if ((! fLog) || silent) { LeaveCriticalSection (&log_mutex); return; } if (_Timestamp) { wchar_t wszLogTime [128]; WORD ms = TZF_Timestamp (wszLogTime); fwprintf (fLog, L"%s%03u: ", wszLogTime, ms); } va_start (_ArgList, _Format); { vfwprintf (fLog, _Format, _ArgList); } va_end (_ArgList); fflush (fLog); LeaveCriticalSection (&log_mutex); }
Config::Config() { CreateDirectoryA(charenc("csgo//"), 0); CreateDirectoryA(charenc("csgo//cfg//"), 0); CreateDirectoryA(charenc("csgo//cfg//cheetos//"), 0); }
static char * run_tests (char *logname) { int nr_of_files = 0, nr_of_tests = 0, i; char *tempdir, *shorttempdir; int logfile; char *strres, *eol, *nextline; DWORD strsize; SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); if (!logname) { logname = tempnam (0, "res"); if (!logname) report (R_FATAL, "Can't name logfile."); } report (R_OUT, logname); logfile = open (logname, O_WRONLY | O_CREAT | O_EXCL | O_APPEND, 0666); if (-1 == logfile) { if (EEXIST == errno) report (R_FATAL, "File %s already exists.", logname); else report (R_FATAL, "Could not open logfile: %d", errno); } if (-1 == dup2 (logfile, 1)) report (R_FATAL, "Can't redirect stdout: %d", errno); close (logfile); tempdir = tempnam (0, "wct"); if (!tempdir) report (R_FATAL, "Can't name temporary dir (check %%TEMP%%)."); shorttempdir = strdup (tempdir); if (shorttempdir) { /* try stable path for ZoneAlarm */ strstr (shorttempdir, "wct")[3] = 0; if (CreateDirectoryA (shorttempdir, NULL)) { free (tempdir); tempdir = shorttempdir; } else free (shorttempdir); } if (tempdir != shorttempdir && !CreateDirectoryA (tempdir, NULL)) report (R_FATAL, "Could not create directory: %s", tempdir); report (R_DIR, tempdir); xprintf ("Version 3\n"); strres = extract_rcdata (WINE_BUILD, STRINGRES, &strsize); xprintf ("Tests from build "); if (strres) xprintf ("%.*s", strsize, strres); else xprintf ("-\n"); strres = extract_rcdata (TESTS_URL, STRINGRES, &strsize); xprintf ("Archive: "); if (strres) xprintf ("%.*s", strsize, strres); else xprintf ("-\n"); xprintf ("Tag: %s\n", tag); xprintf ("Build info:\n"); strres = extract_rcdata (BUILD_INFO, STRINGRES, &strsize); while (strres) { eol = memchr (strres, '\n', strsize); if (!eol) { nextline = NULL; eol = strres + strsize; } else { strsize -= eol - strres + 1; nextline = strsize?eol+1:NULL; if (eol > strres && *(eol-1) == '\r') eol--; } xprintf (" %.*s\n", eol-strres, strres); strres = nextline; } xprintf ("Operating system version:\n"); print_version (); xprintf ("Test output:\n" ); report (R_STATUS, "Counting tests"); if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES), EnumTestFileProc, (LPARAM)&nr_of_files)) report (R_FATAL, "Can't enumerate test files: %d", GetLastError ()); wine_tests = xmalloc (nr_of_files * sizeof wine_tests[0]); report (R_STATUS, "Extracting tests"); report (R_PROGRESS, 0, nr_of_files); for (i = 0; i < nr_of_files; i++) { get_subtests (tempdir, wine_tests+i, i); nr_of_tests += wine_tests[i].subtest_count; } report (R_DELTA, 0, "Extracting: Done"); report (R_STATUS, "Running tests"); report (R_PROGRESS, 1, nr_of_tests); for (i = 0; i < nr_of_files; i++) { struct wine_test *test = wine_tests + i; int j; for (j = 0; j < test->subtest_count; j++) { report (R_STEP, "Running: %s:%s", test->name, test->subtests[j]); run_test (test, test->subtests[j]); } } report (R_DELTA, 0, "Running: Done"); report (R_STATUS, "Cleaning up"); close (1); remove_dir (tempdir); free (tempdir); free (wine_tests); return logname; }