From: José Fonseca Date: Thu, 3 Nov 2011 13:19:48 +0000 (+0000) Subject: Make file_exists as os::Path method. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=67303f65e9085e43e217a4f3e17dfb566ac647bb;p=apitrace Make file_exists as os::Path method. --- diff --git a/cli/cli_trace.cpp b/cli/cli_trace.cpp index 19739fd..df78d55 100644 --- a/cli/cli_trace.cpp +++ b/cli/cli_trace.cpp @@ -51,7 +51,6 @@ usage(void) /* We only support "apitrace trace" on POSIX-like systems (not WIN32) */ #ifndef _WIN32 -#include #ifdef __APPLE__ #define CLI_TRACE_VARIABLE "DYLD_LIBRARY_PATH" @@ -61,22 +60,6 @@ usage(void) #define CLI_TRACE_WRAPPER "glxtrace.so" #endif -static int -file_exists(const char *path) -{ - struct stat st; - int err; - - err = stat(path, &st); - if (err) - return 0; - - if (! S_ISREG(st.st_mode)) - return 0; - - return 1; -} - static os::Path find_wrapper(const char *filename) { @@ -98,14 +81,14 @@ find_wrapper(const char *filename) complete.join(filename); #endif - if (file_exists(complete)) + if (complete.exists()) return complete; /* Second, look in the directory for installed wrappers. */ complete = APITRACE_WRAPPER_INSTALL_DIR; complete.join(filename); - if (file_exists(complete)) + if (complete.exists()) return complete; std::cerr << "error: cannot find " << filename << " (looked in " << diff --git a/common/os_path.hpp b/common/os_path.hpp index 5058651..ffb4fd2 100644 --- a/common/os_path.hpp +++ b/common/os_path.hpp @@ -237,6 +237,8 @@ public: return path; } + + bool exists(void) const; }; diff --git a/common/os_posix.cpp b/common/os_posix.cpp index 21a7e36..586ad84 100644 --- a/common/os_posix.cpp +++ b/common/os_posix.cpp @@ -126,6 +126,23 @@ getCurrentDir(void) return path; } +bool +Path::exists(void) const +{ + struct stat st; + int err; + + err = stat(str(), &st); + if (err) { + return false; + } + + if (!S_ISREG(st.st_mode)) + return false; + + return true; +} + void log(const char *format, ...) { diff --git a/common/os_win32.cpp b/common/os_win32.cpp index f33e175..74d911c 100644 --- a/common/os_win32.cpp +++ b/common/os_win32.cpp @@ -90,6 +90,13 @@ getCurrentDir(void) return path; } +bool +Path::exists(void) const +{ + DWORD attrs = GetFileAttributesA(str()); + return attrs != INVALID_FILE_ATTRIBUTES; +} + void log(const char *format, ...) {