]> git.cworth.org Git - apitrace/commitdiff
Make file_exists as os::Path method.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 3 Nov 2011 13:19:48 +0000 (13:19 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 3 Nov 2011 13:19:48 +0000 (13:19 +0000)
cli/cli_trace.cpp
common/os_path.hpp
common/os_posix.cpp
common/os_win32.cpp

index 19739fd7440f8f3325b4d572e344bf757f01d9ee..df78d55fc575c1919746af24d4e6bb5ccd07d9c6 100644 (file)
@@ -51,7 +51,6 @@ usage(void)
 /* We only support "apitrace trace" on POSIX-like systems (not WIN32) */
 #ifndef _WIN32
 
-#include <sys/stat.h>
 
 #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 " <<
index 5058651d8231b7ec0a286fc0859574827dded961..ffb4fd22e5a1e3a40e39e41617f7b9a7adf523cd 100644 (file)
@@ -237,6 +237,8 @@ public:
 
         return path;
     }
+
+    bool exists(void) const;
 };
 
 
index 21a7e3653e2787de4f0b75ce49280bbb9db93618..586ad84ed5ced202736957d3c28b645bdc16f9af 100644 (file)
@@ -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, ...)
 {
index f33e175aac4916cc4baa296c219ab2b622c55a0a..74d911cadc6e294049408db6ea3cafc88e5cf151 100644 (file)
@@ -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, ...)
 {