1 // Copyright 2019 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef COMMON_SYSTEMUTILS_H_ 16 #define COMMON_SYSTEMUTILS_H_ 17 18 #include "common/Platform.h" 19 20 #include <string> 21 22 const char* GetPathSeparator(); 23 // Returns a pair of the environment variable's value, and a boolean indicating whether the variable 24 // was present. 25 std::pair<std::string, bool> GetEnvironmentVar(const char* variableName); 26 bool SetEnvironmentVar(const char* variableName, const char* value); 27 // Directories are always returned with a trailing path separator. 28 std::string GetExecutableDirectory(); 29 std::string GetModuleDirectory(); 30 31 #ifdef DAWN_PLATFORM_MACOS 32 void GetMacOSVersion(int32_t* majorVersion, int32_t* minorVersion = nullptr); 33 bool IsMacOSVersionAtLeast(uint32_t majorVersion, uint32_t minorVersion = 0); 34 #endif 35 36 class ScopedEnvironmentVar { 37 public: 38 ScopedEnvironmentVar() = default; 39 ScopedEnvironmentVar(const char* variableName, const char* value); 40 ~ScopedEnvironmentVar(); 41 42 ScopedEnvironmentVar(const ScopedEnvironmentVar& rhs) = delete; 43 ScopedEnvironmentVar& operator=(const ScopedEnvironmentVar& rhs) = delete; 44 45 bool Set(const char* variableName, const char* value); 46 47 private: 48 std::string mName; 49 std::pair<std::string, bool> mOriginalValue; 50 bool mIsSet = false; 51 }; 52 53 #endif // COMMON_SYSTEMUTILS_H_ 54