wchar_t * getCurrentDir() { // current directory 를 구한다. wchar_t *buf = NULL; uint32_t buflen = 0; buflen = GetCurrentDirectoryW(buflen, buf); // 디렉토리 문자열의 길이를 모르니 0이나 -1을 넣으면 return해줌 if (0 == buflen) { print("err, GetCurrentDirectoryW() failed. gle = 0x%08x", GetLastError()); return false; } buf = (PWSTR)malloc(sizeof(WCHAR) * buflen); if (0 == GetCurrentDirectoryW(buflen, buf)) { print("err, GetCurrentDirectoryW() failed. gle = 0x%08x", GetLastError()); free(buf); return false; } return buf; }
gs2d::str_type::string GetCurrentDirectoryPath() { gs2d::str_type::char_t currentDirectoryBuffer[65536]; #ifdef GS2D_STR_TYPE_WCHAR GetCurrentDirectoryW(65535, currentDirectoryBuffer); #else GetCurrentDirectoryA(65535, currentDirectoryBuffer); #endif return AddLastSlash(currentDirectoryBuffer); }
tb_size_t tb_directory_curt(tb_char_t* path, tb_size_t maxn) { // check tb_assert_and_check_return_val(path && maxn > 4, 0); // the current directory tb_wchar_t curt[TB_PATH_MAXN] = {0}; GetCurrentDirectoryW(TB_PATH_MAXN, curt); // wtoa return tb_wtoa(path, curt, maxn); }
void ExitAndRestart() { // This preserves arguments (for example, config file) and working directory. wchar_t moduleFilename[MAX_PATH]; wchar_t workingDirectory[MAX_PATH]; GetCurrentDirectoryW(MAX_PATH, workingDirectory); const wchar_t *cmdline = RemoveExecutableFromCommandLine(GetCommandLineW()); GetModuleFileName(GetModuleHandle(NULL), moduleFilename, MAX_PATH); ShellExecute(NULL, NULL, moduleFilename, cmdline, workingDirectory, SW_SHOW); ExitProcess(0); }
/* * Arguments: [path (string)] * Returns: [boolean | pathname (string)] */ static int sys_curdir (lua_State *L) { const char *path = lua_tostring(L, 1); if (path) { int res; #ifndef _WIN32 res = chdir(path); #else { void *os_path = utf8_to_filename(path); if (!os_path) return sys_seterror(L, ERROR_NOT_ENOUGH_MEMORY); res = is_WinNT ? !SetCurrentDirectoryW(os_path) : !SetCurrentDirectoryA(os_path); free(os_path); } #endif if (!res) { lua_pushboolean(L, 1); return 1; } } else { #ifndef _WIN32 char dir[MAX_PATHNAME]; if (getcwd(dir, MAX_PATHNAME)) { lua_pushstring(L, dir); return 1; } #else WCHAR os_dir[MAX_PATHNAME]; const int n = is_WinNT ? GetCurrentDirectoryW(MAX_PATHNAME, os_dir) : GetCurrentDirectoryA(MAX_PATHNAME, (char *) os_dir); if (n != 0 && n < MAX_PATHNAME) { void *dir = filename_to_utf8(os_dir); if (!dir) return sys_seterror(L, ERROR_NOT_ENOUGH_MEMORY); lua_pushstring(L, dir); free(dir); return 1; } #endif } return sys_seterror(L, 0); }
/*********************************************************************** * start_dosbox */ static void start_dosbox( const char *appname, const char *args ) { static const WCHAR cfgW[] = {'c','f','g',0}; const char *config_dir = wine_get_config_dir(); WCHAR path[MAX_PATH], config[MAX_PATH]; HANDLE file; char *p, *buffer; int i; int ret = 1; DWORD written, drives = GetLogicalDrives(); char *dosbox = find_dosbox(); if (!dosbox) return; if (tolower(appname[0]) == 'z') { WINE_MESSAGE( "winevdm: Cannot start DOS application %s\n", appname ); WINE_MESSAGE( " because DOSBox doesn't support running from the Z: drive.\n" ); ExitProcess(1); } if (!GetTempPathW( MAX_PATH, path )) return; if (!GetTempFileNameW( path, cfgW, 0, config )) return; if (!GetCurrentDirectoryW( MAX_PATH, path )) return; file = CreateFileW( config, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 ); if (file == INVALID_HANDLE_VALUE) return; buffer = HeapAlloc( GetProcessHeap(), 0, sizeof("[autoexec]") + 25 * (strlen(config_dir) + sizeof("mount c /dosdevices/c:")) + 4 * strlenW( path ) + 6 + strlen( appname ) + strlen( args ) + 20 ); p = buffer; p += sprintf( p, "[autoexec]\n" ); for (i = 0; i < 25; i++) if (drives & (1 << i)) p += sprintf( p, "mount %c %s/dosdevices/%c:\n", 'a' + i, config_dir, 'a' + i ); p += sprintf( p, "%c:\ncd ", path[0] ); p += WideCharToMultiByte( CP_UNIXCP, 0, path + 2, -1, p, 4 * strlenW(path), NULL, NULL ) - 1; p += sprintf( p, "\n%s %s\n", appname, args ); p += sprintf( p, "exit\n" ); if (WriteFile( file, buffer, strlen(buffer), &written, NULL ) && written == strlen(buffer)) { const char *args[4]; char *config_file = wine_get_unix_file_name( config ); args[0] = dosbox; args[1] = "-conf"; args[2] = config_file; args[3] = NULL; ret = spawnvp( _P_WAIT, args[0], args ); } CloseHandle( file ); DeleteFileW( config ); HeapFree( GetProcessHeap(), 0, buffer ); ExitProcess( ret ); }
MistString Path::GetApplicationPath() { #ifdef MIST_OS_WINDOWS wchar_t buffer[MAX_PATH]; GetCurrentDirectoryW(MAX_PATH, buffer); return MistString(buffer)+L"/"; #elif defined(MIST_OS_FAMILY_APPLE) return mist_apple_application_path() + L"/"; #endif return L"./"; }
bool set_working_directory(string dname) { tstring tstr_dname = widen(dname); replace(tstr_dname.begin(), tstr_dname.end(), '/', '\\'); if (SetCurrentDirectoryW(tstr_dname.c_str()) != 0) { WCHAR wstr_buffer[MAX_PATH + 1]; if (GetCurrentDirectoryW(MAX_PATH + 1, wstr_buffer) != 0) { working_directory = add_slash(shorten(wstr_buffer)); return true; } } return false; }
/* ** Get the current working directory. ** ** On windows, the name is converted from unicode to UTF8 and all '\\' ** characters are converted to '/'. No conversions are needed on ** unix. */ void win32_getcwd(char *zBuf, int nBuf){ int i; char *zUtf8; wchar_t *zWide = fossil_malloc( sizeof(wchar_t)*nBuf ); if( GetCurrentDirectoryW(nBuf, zWide)==0 ){ fossil_fatal("cannot find current working directory."); } zUtf8 = fossil_filename_to_utf8(zWide); fossil_free(zWide); for(i=0; zUtf8[i]; i++) if( zUtf8[i]=='\\' ) zUtf8[i] = '/'; strncpy(zBuf, zUtf8, nBuf); fossil_filename_free(zUtf8); }
Directory::Directory() : mPath(L""), mName(L""), mAttributes(0) { wchar_t Path[MAX_PATH] = {L'\0'}; GetCurrentDirectoryW(MAX_PATH, Path); mAttributes = GetFileAttributesW(Path); mPath = Path; mName = Path; };
/** * @brief retrieve currnt directory * caller must free returned memroy pointer. * @param * @see * @remarks * @code * @endcode * @return **/ wchar_t* get_current_directory(void) { wchar_t *buf = NULL; uint32_t buflen = 0; buflen = GetCurrentDirectoryW(buflen, buf); if (0 == buflen) { print("err ] GetCurrentDirectoryW() failed. gle = 0x%08x", GetLastError()); return NULL; } buf = (PWSTR)malloc(sizeof(WCHAR)* buflen); if (0 == GetCurrentDirectoryW(buflen, buf)) { print("err ] GetCurrentDirectoryW() failed. gle = 0x%08x", GetLastError()); free(buf); return NULL; } return buf; }
QString Application::CurrentWorkingDirectory() { #ifdef _WINDOWS WCHAR str[MAX_PATH+1] = {}; GetCurrentDirectoryW(MAX_PATH, str); QString qstr = WStringToQString(str); #else QString qstr = QDir::currentPath(); #endif if (!qstr.endsWith(QDir::separator())) qstr += QDir::separator(); return qstr; }
BOOL ReadFromFile() { IFileOpenDialog *pDlg; COMDLG_FILTERSPEC FileTypes[] = { { L"PS2 MemoryCard files", L"*.ps2" }, { L"All files", L"*.*" } }; HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDlg)); WCHAR cPath[MAX_PATH] = L""; GetCurrentDirectoryW(sizeof(cPath) / sizeof(cPath[0]), cPath); IShellItem *psiFolder, *psiParent; SHCreateItemFromParsingName(cPath, NULL, IID_PPV_ARGS(&psiFolder)); psiFolder->GetParent(&psiParent); //初期フォルダの指定 pDlg->SetFolder(psiFolder); //フィルターの指定 pDlg->SetFileTypes(_countof(FileTypes), FileTypes); //ダイアログ表示 hr = pDlg->Show(NULL); //ファイル名 LPOLESTR pwsz = NULL; if (SUCCEEDED(hr)) { IShellItem *pItem; hr = pDlg->GetResult(&pItem); if (SUCCEEDED(hr)) { hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pwsz); if (SUCCEEDED(hr)) { HANDLE hFile; hFile = CreateFile(pwsz, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile) { DWORD BytesRead; BOOL b = ReadFile(hFile, &(byteMemDat.Byte), sizeof(byteMemDat), &BytesRead, NULL); if (BytesRead) { CloseHandle(hFile); } } } } } UpdateDataList(&byteMemDat); return TRUE; }
/** * Loads the plugin into memory using NSPR's shared-library loading * mechanism. Handles platform differences in loading shared libraries. */ nsresult nsPluginFile::LoadPlugin(PRLibrary **outLibrary) { nsCOMPtr<nsILocalFile> plugin = do_QueryInterface(mPlugin); if (!plugin) return NS_ERROR_NULL_POINTER; PRBool protectCurrentDirectory = PR_TRUE; nsAutoString pluginFolderPath; plugin->GetPath(pluginFolderPath); PRInt32 idx = pluginFolderPath.RFindChar('\\'); if (kNotFound == idx) return NS_ERROR_FILE_INVALID_PATH; if (Substring(pluginFolderPath, idx).LowerCaseEqualsLiteral("\\np32dsw.dll")) { protectCurrentDirectory = PR_FALSE; } pluginFolderPath.SetLength(idx); BOOL restoreOrigDir = FALSE; WCHAR aOrigDir[MAX_PATH + 1]; DWORD dwCheck = GetCurrentDirectoryW(MAX_PATH, aOrigDir); NS_ASSERTION(dwCheck <= MAX_PATH + 1, "Error in Loading plugin"); if (dwCheck <= MAX_PATH + 1) { restoreOrigDir = SetCurrentDirectoryW(pluginFolderPath.get()); NS_ASSERTION(restoreOrigDir, "Error in Loading plugin"); } if (protectCurrentDirectory) { mozilla::NS_SetDllDirectory(NULL); } nsresult rv = plugin->Load(outLibrary); if (NS_FAILED(rv)) *outLibrary = NULL; if (protectCurrentDirectory) { mozilla::NS_SetDllDirectory(L""); } if (restoreOrigDir) { BOOL bCheck = SetCurrentDirectoryW(aOrigDir); NS_ASSERTION(bCheck, "Error in Loading plugin"); } return rv; }
SString SharedUtil::GetSystemCurrentDirectory ( void ) { #ifdef WIN32 wchar_t szResult [ 1024 ] = L""; GetCurrentDirectoryW ( NUMELMS ( szResult ), szResult ); if ( IsShortPathName( szResult ) ) return GetSystemLongPathName( ToUTF8( szResult ) ); return ToUTF8( szResult ); #else char szBuffer[ MAX_PATH ]; getcwd ( szBuffer, MAX_PATH - 1 ); return szBuffer; #endif }
StString StProcess::getWorkingFolder() { StString aWorkingFolder; #ifdef _WIN32 // determine buffer length (in characters, including NULL-terminated symbol) DWORD aBuffLen = GetCurrentDirectoryW(0, NULL); stUtfWide_t* aBuff = new stUtfWide_t[size_t(aBuffLen + 1)]; // take current directory GetCurrentDirectoryW(aBuffLen, aBuff); aBuff[aBuffLen - 1] = (aBuff[aBuffLen - 2] == L'\\') ? L'\0' : L'\\'; aBuff[aBuffLen] = L'\0'; aWorkingFolder = StString(aBuff); delete[] aBuff; #else char* aPath = getcwd(NULL, 0); if(aPath == NULL) { // allocation error - should never happens return StString(); } aWorkingFolder = StString(aPath) + SYS_FS_SPLITTER; free(aPath); // free alien buffer #endif return aWorkingFolder; }
static int uv_split_path(const WCHAR* filename, WCHAR** dir, WCHAR** file) { size_t len, i; if (filename == NULL) { if (dir != NULL) *dir = NULL; *file = NULL; return 0; } len = wcslen(filename); i = len; while (i > 0 && filename[--i] != '\\' && filename[i] != '/'); if (i == 0) { if (dir) { *dir = (WCHAR*)uv__malloc((MAX_PATH + 1) * sizeof(WCHAR)); if (!*dir) { uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc"); } if (!GetCurrentDirectoryW(MAX_PATH, *dir)) { uv__free(*dir); *dir = NULL; return -1; } } *file = wcsdup(filename); } else { if (dir) { *dir = (WCHAR*)uv__malloc((i + 2) * sizeof(WCHAR)); if (!*dir) { uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc"); } wcsncpy(*dir, filename, i + 1); (*dir)[i + 1] = L'\0'; } *file = (WCHAR*)uv__malloc((len - i) * sizeof(WCHAR)); if (!*file) { uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc"); } wcsncpy(*file, filename + i + 1, len - i - 1); (*file)[len - i - 1] = L'\0'; } return 0; }
Error DirAccessWindows::change_dir(String p_dir) { GLOBAL_LOCK_FUNCTION p_dir = fix_path(p_dir); wchar_t real_current_dir_name[2048]; GetCurrentDirectoryW(2048, real_current_dir_name); String prev_dir = real_current_dir_name; SetCurrentDirectoryW(current_dir.c_str()); bool worked = (SetCurrentDirectoryW(p_dir.c_str()) != 0); String base = _get_root_path(); if (base != "") { GetCurrentDirectoryW(2048, real_current_dir_name); String new_dir; new_dir = String(real_current_dir_name).replace("\\", "/"); if (!new_dir.begins_with(base)) { worked = false; } } if (worked) { GetCurrentDirectoryW(2048, real_current_dir_name); current_dir = real_current_dir_name; // TODO, utf8 parser current_dir = current_dir.replace("\\", "/"); } //else { SetCurrentDirectoryW(prev_dir.c_str()); //} return worked ? OK : ERR_INVALID_PARAMETER; }
BOOL DIALOG_FileSaveAs(VOID) { OPENFILENAMEW saveas; WCHAR szPath[MAX_PATH]; WCHAR szDir[MAX_PATH]; static const WCHAR szDefaultExt[] = { 't','x','t',0 }; static const WCHAR txt_files[] = { '*','.','t','x','t',0 }; ZeroMemory(&saveas, sizeof(saveas)); GetCurrentDirectoryW(ARRAY_SIZE(szDir), szDir); lstrcpyW(szPath, txt_files); saveas.lStructSize = sizeof(OPENFILENAMEW); saveas.hwndOwner = Globals.hMainWnd; saveas.hInstance = Globals.hInstance; saveas.lpstrFilter = Globals.szFilter; saveas.lpstrFile = szPath; saveas.nMaxFile = ARRAY_SIZE(szPath); saveas.lpstrInitialDir = szDir; saveas.Flags = OFN_ENABLETEMPLATE | OFN_ENABLEHOOK | OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_ENABLESIZING; saveas.lpfnHook = OfnHookProc; saveas.lpTemplateName = MAKEINTRESOURCEW(IDD_OFN_TEMPLATE); saveas.lpstrDefExt = szDefaultExt; /* Preset encoding to what file was opened/saved last with. */ Globals.encOfnCombo = Globals.encFile; Globals.bOfnIsOpenDialog = FALSE; retry: if (!GetSaveFileNameW(&saveas)) return FALSE; switch (DoSaveFile(szPath, Globals.encOfnCombo)) { case SAVED_OK: SetFileNameAndEncoding(szPath, Globals.encOfnCombo); UpdateWindowCaption(); return TRUE; case SHOW_SAVEAS_DIALOG: goto retry; default: return FALSE; } }
tb_size_t tb_directory_current(tb_char_t* path, tb_size_t maxn) { // check tb_assert_and_check_return_val(path && maxn > 4, 0); // the current directory tb_wchar_t current[TB_PATH_MAXN] = {0}; GetCurrentDirectoryW(TB_PATH_MAXN, current); // wtoa tb_size_t size = tb_wtoa(path, current, maxn); // ok? return size != -1? size : 0; }
static VOID TestGetCurrentDirectoryW(VOID) { WCHAR Buffer[MAX_PATH]; DWORD Length; BOOL Ret; BOOLEAN Okay; Ret = SetCurrentDirectoryW(L"C:\\"); ok(Ret == TRUE, "SetCurrentDirectory failed with %lu\n", GetLastError()); Length = GetCurrentDirectoryW(0, NULL); ok(Length == sizeof("C:\\"), "Length = %lu\n", Length); RtlFillMemory(Buffer, sizeof(Buffer), 0x55); Length = GetCurrentDirectoryW(sizeof(Buffer) / sizeof(WCHAR), Buffer); ok(Length == sizeof("C:\\") - 1, "Length = %lu\n", Length); Okay = CheckStringBufferW(Buffer, sizeof(Buffer), L"C:\\", 0x55); ok(Okay, "CheckStringBufferW failed\n"); RtlFillMemory(Buffer, sizeof(Buffer), 0x55); Length = GetCurrentDirectoryW(0, Buffer); ok(Length == sizeof("C:\\"), "Length = %lu\n", Length); Okay = CheckBuffer(Buffer, sizeof(Buffer), 0x55); ok(Okay, "CheckBuffer failed\n"); RtlFillMemory(Buffer, sizeof(Buffer), 0x55); Length = GetCurrentDirectoryW(1, Buffer); ok(Length == sizeof("C:\\"), "Length = %lu\n", Length); Okay = CheckBuffer(Buffer, sizeof(Buffer), 0x55); ok(Okay, "CheckBuffer failed\n"); RtlFillMemory(Buffer, sizeof(Buffer), 0x55); Length = GetCurrentDirectoryW(2, Buffer); ok(Length == sizeof("C:\\"), "Length = %lu\n", Length); Okay = CheckBuffer(Buffer, sizeof(Buffer), 0x55); ok(Okay, "CheckBuffer failed\n"); RtlFillMemory(Buffer, sizeof(Buffer), 0x55); Length = GetCurrentDirectoryW(3, Buffer); ok(Length == sizeof("C:\\"), "Length = %lu\n", Length); Okay = CheckBuffer(Buffer, sizeof(Buffer), 0x55); ok(Okay, "CheckBuffer failed\n"); RtlFillMemory(Buffer, sizeof(Buffer), 0x55); Length = GetCurrentDirectoryW(4, Buffer); ok(Length == sizeof("C:\\") - 1, "Length = %lu\n", Length); Okay = CheckStringBufferW(Buffer, sizeof(Buffer), L"C:\\", 0x55); ok(Okay, "CheckStringBufferW failed\n"); }
int FileUtils::RunAndWait(std::string &path, std::vector<std::string> &args) { std::string cmdLine = "\"" + path + "\""; for (size_t i = 0; i < args.size(); i++) { cmdLine += " \"" + args.at(i) + "\""; } #ifdef DEBUG std::cout << "running: " << cmdLine << std::endl; #endif STARTUPINFO startupInfo; ZeroMemory(&startupInfo, sizeof(STARTUPINFO)); PROCESS_INFORMATION processInfo; ZeroMemory(&processInfo, sizeof(PROCESS_INFORMATION)); startupInfo.cb = sizeof(STARTUPINFO); // Get the current working directory wchar_t cwd[MAX_PATH]; DWORD size = GetCurrentDirectoryW(MAX_PATH, (wchar_t*) cwd); std::wstring wideCmdLine = UTILS_NS::UTF8ToWide(cmdLine); DWORD rc = -1; if (CreateProcessW( NULL, // No module name (use command line) (wchar_t*) wideCmdLine.c_str(), // Command line NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE 0, // No creation flags NULL, // Use parent's environment block (wchar_t*) cwd, // Use parent's starting directory &startupInfo, // Pointer to STARTUPINFO structure &processInfo)) // Pointer to PROCESS_INFORMATION structure { // Wait until child process exits. WaitForSingleObject(processInfo.hProcess, INFINITE); // set the exit code GetExitCodeProcess(processInfo.hProcess, &rc); // Close process and thread handles. CloseHandle(processInfo.hProcess); CloseHandle(processInfo.hThread); } return rc; }
void Debug::PrepareSnapshotDirectory(std::wstring &buffer) { wchar_t path[MAX_PATH]; SYSTEMTIME time; GetLocalTime(&time); GetCurrentDirectoryW(MAX_PATH, path); buffer = path; buffer += L"\\debug"; CreateDirectoryW(buffer.c_str(), nullptr); wchar_t subpath[64]; swprintf(subpath, 64, L"\\snapshot-%04u%02u%02u-%02u%02u%02u", time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond); buffer += subpath; CreateDirectoryW(buffer.c_str(), nullptr); }
static void test_createfolder(void) { HRESULT hr; WCHAR pathW[MAX_PATH]; BSTR path; IFolder *folder; /* create existing directory */ GetCurrentDirectoryW(sizeof(pathW)/sizeof(WCHAR), pathW); path = SysAllocString(pathW); folder = (void*)0xdeabeef; hr = IFileSystem3_CreateFolder(fs3, path, &folder); ok(hr == CTL_E_FILEALREADYEXISTS, "got 0x%08x\n", hr); ok(folder == NULL, "got %p\n", folder); SysFreeString(path); }
tAsyncCall* System_IO_FileInternal_GetCurrentDirectory(PTR pThis_, PTR pParams, PTR pReturnValue) { U32 *pError = ((U32**)pParams)[0]; HEAP_PTR curDir; #ifdef WIN32 unsigned short dir[256]; GetCurrentDirectoryW(256, dir); curDir = SystemString_FromCharPtrUTF16(dir); #else unsigned char dir[256]; getcwd(dir, 256); curDir = SystemString_FromCharPtrASCII(dir); #endif *pError = 0; *(HEAP_PTR*)pReturnValue = curDir; return NULL; }
std::wstring getAbsoluteCurrentDirectory() { #if defined(USES_WINDOWS8_DESKTOP) || defined(USES_WINDOWS_OPENGL) wchar_t path[MAX_PATH]; GetCurrentDirectoryW(MAX_PATH, path); return std::wstring(path); #elif defined(USES_WINDOWS8_METRO) Assert(false); return L""; #elif defined(USES_LINUX) Assert(false); return L""; #else #error #endif }
DWORD GetCurrentDirectoryUTF8(DWORD nBufferLength, LPTSTR lpBuffer) { if (lpBuffer && nBufferLength > 1 AND_IS_NOT_WIN9X) { WCHAR wbuf[WDL_UTF8_MAXFNLEN]; wbuf[0]=0; GetCurrentDirectoryW(WDL_UTF8_MAXFNLEN,wbuf); if (wbuf[0]) { int rv=WideCharToMultiByte(CP_UTF8,0,wbuf,-1,lpBuffer,nBufferLength,NULL,NULL); if (rv) return rv; } } return GetCurrentDirectoryA(nBufferLength,lpBuffer); }
void SendCommandLineToFirstInstance() { wchar_t curDir[_MAX_PATH]; GetCurrentDirectoryW(_MAX_PATH - 1, curDir); std::wstring command(curDir); command += _T("\n"); command += GetCommandLineW(); void *view = MapViewOfFile(hFileMapping, FILE_MAP_ALL_ACCESS, 0, 0, 0); if (view) { memcpy(view, command.c_str(), (command.size() + 1) * sizeof(wchar_t)); UnmapViewOfFile(view); } SetEvent(hEvent); }
result_t process_base::chdir(const char *directory) { wstring str = utf8to16String(directory); wchar utf16_buffer[MAX_PATH]; DWORD utf16_len; wchar drive_letter; if (!SetCurrentDirectoryW(str.c_str())) return CHECK_ERROR(LastError()); utf16_len = GetCurrentDirectoryW(MAX_PATH, utf16_buffer); if (utf16_len == 0) return CHECK_ERROR(LastError()); if (utf16_buffer[utf16_len - 1] == L'\\' && !(utf16_len == 3 && utf16_buffer[1] == L':')) { utf16_len--; utf16_buffer[utf16_len] = L'\0'; } if (utf16_len < 2 || utf16_buffer[1] != L':') drive_letter = 0; else if (utf16_buffer[0] >= L'A' && utf16_buffer[0] <= L'Z') drive_letter = utf16_buffer[0]; else if (utf16_buffer[0] >= L'a' && utf16_buffer[0] <= L'z') drive_letter = utf16_buffer[0] - L'a' + L'A'; else drive_letter = 0; if (drive_letter != 0) { wchar env_var[4]; env_var[0] = L'='; env_var[1] = drive_letter; env_var[2] = L':'; env_var[3] = L'\0'; if (!SetEnvironmentVariableW(env_var, utf16_buffer)) return CHECK_ERROR(LastError()); } return 0; }
int fs_getwd(char **dir) { int rc = ERROR_SUCCESS; wchar_t dir_w[FS_MAX_PATH]; if (GetCurrentDirectoryW(FS_MAX_PATH, dir_w) == 0) { rc = GetLastError(); goto out; } *dir = wchar_to_utf8(dir_w); if (*dir == NULL) { rc = GetLastError(); } out: return rc; }