1 // 2 // Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 // system_utils_win.cpp: Implementation of OS-specific functions for Windows 8 9 #include "system_utils.h" 10 11 #include <stdarg.h> 12 #include <windows.h> 13 #include <array> 14 #include <vector> 15 16 namespace angle 17 { 18 19 namespace 20 { 21 GetExecutablePathImpl()22std::string GetExecutablePathImpl() 23 { 24 std::array<char, MAX_PATH> executableFileBuf; 25 DWORD executablePathLen = GetModuleFileNameA(nullptr, executableFileBuf.data(), 26 static_cast<DWORD>(executableFileBuf.size())); 27 return (executablePathLen > 0 ? std::string(executableFileBuf.data()) : ""); 28 } 29 GetExecutableDirectoryImpl()30std::string GetExecutableDirectoryImpl() 31 { 32 std::string executablePath = GetExecutablePath(); 33 size_t lastPathSepLoc = executablePath.find_last_of("\\/"); 34 return (lastPathSepLoc != std::string::npos) ? executablePath.substr(0, lastPathSepLoc) : ""; 35 } 36 37 } // anonymous namespace 38 GetExecutablePath()39const char *GetExecutablePath() 40 { 41 // TODO(jmadill): Make global static string thread-safe. 42 const static std::string &exePath = GetExecutablePathImpl(); 43 return exePath.c_str(); 44 } 45 GetExecutableDirectory()46const char *GetExecutableDirectory() 47 { 48 // TODO(jmadill): Make global static string thread-safe. 49 const static std::string &exeDir = GetExecutableDirectoryImpl(); 50 return exeDir.c_str(); 51 } 52 GetSharedLibraryExtension()53const char *GetSharedLibraryExtension() 54 { 55 return "dll"; 56 } 57 GetCWD()58Optional<std::string> GetCWD() 59 { 60 std::array<char, MAX_PATH> pathBuf; 61 DWORD result = GetCurrentDirectoryA(static_cast<DWORD>(pathBuf.size()), pathBuf.data()); 62 if (result == 0) 63 { 64 return Optional<std::string>::Invalid(); 65 } 66 return std::string(pathBuf.data()); 67 } 68 SetCWD(const char * dirName)69bool SetCWD(const char *dirName) 70 { 71 return (SetCurrentDirectoryA(dirName) == TRUE); 72 } 73 SetEnvironmentVar(const char * variableName,const char * value)74bool SetEnvironmentVar(const char *variableName, const char *value) 75 { 76 return (SetEnvironmentVariableA(variableName, value) == TRUE); 77 } 78 79 } // namespace angle 80