diff options
Diffstat (limited to 'runtime/utils.h')
-rw-r--r-- | runtime/utils.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/runtime/utils.h b/runtime/utils.h index 5b9e963919..153749eff4 100644 --- a/runtime/utils.h +++ b/runtime/utils.h @@ -99,6 +99,18 @@ static inline bool NeedsEscaping(uint16_t ch) { return (ch < ' ' || ch > '~'); } +template <typename T> T SafeAbs(T value) { + // std::abs has undefined behavior on min limits. + DCHECK_NE(value, std::numeric_limits<T>::min()); + return std::abs(value); +} + +template <typename T> T AbsOrMin(T value) { + return (value == std::numeric_limits<T>::min()) + ? value + : std::abs(value); +} + std::string PrintableChar(uint16_t ch); // Returns an ASCII string corresponding to the given UTF-8 string. @@ -276,6 +288,9 @@ std::string GetSystemImageFilename(const char* location, InstructionSet isa); // Wrapper on fork/execv to run a command in a subprocess. bool Exec(std::vector<std::string>& arg_vector, std::string* error_msg); +// Returns true if the file exists. +bool FileExists(const std::string& filename); + class VoidFunctor { public: template <typename A> @@ -367,6 +382,12 @@ T GetRandomNumber(T min, T max) { return dist(rng); } +// Return the file size in bytes or -1 if the file does not exists. +int64_t GetFileSizeBytes(const std::string& filename); + +// Sleep forever and never come back. +NO_RETURN void SleepForever(); + } // namespace art #endif // ART_RUNTIME_UTILS_H_ |