]> git.cworth.org Git - apitrace/blobdiff - common/os_posix.cpp
cli: Fix typo in earlier commit.
[apitrace] / common / os_posix.cpp
index 7d39d8ada5e0ffafc0f730bcdd3e913744f734d2..7ddd89530f4883fda0efc85fdac69e4e4df67c4d 100644 (file)
@@ -111,6 +111,12 @@ getCurrentDir(void)
     return path;
 }
 
+bool
+createDirectory(const String &path)
+{
+    return mkdir(path, 0777) == 0;
+}
+
 bool
 String::exists(void) const
 {
@@ -122,9 +128,6 @@ String::exists(void) const
         return false;
     }
 
-    if (!S_ISREG(st.st_mode))
-        return false;
-
     return true;
 }
 
@@ -134,7 +137,11 @@ int execute(char * const * args)
     if (pid == 0) {
         // child
         execvp(args[0], args);
-        fprintf(stderr, "error: failed to execute %s\n", args[0]);
+        fprintf(stderr, "error: failed to execute:");
+        for (unsigned i = 0; args[i]; ++i) {
+            fprintf(stderr, " %s", args[i]);
+        }
+        fprintf(stderr, "\n");
         exit(-1);
     } else {
         // parent
@@ -169,7 +176,16 @@ log(const char *format, ...)
 #ifdef ANDROID
     __android_log_vprint(ANDROID_LOG_DEBUG, "apitrace", format, ap);
 #else
-    vfprintf(stderr, format, ap);
+    static FILE *log = NULL;
+    if (!log) {
+        // Duplicate stderr file descriptor, to prevent applications from
+        // redirecting our debug messages to somewhere else.
+        //
+        // Another alternative would be to log to /dev/tty when available.
+        log = fdopen(dup(STDERR_FILENO), "at");
+    }
+    vfprintf(log, format, ap);
+    fflush(log);
 #endif
     va_end(ap);
     logging = false;
@@ -182,7 +198,7 @@ long long timeFrequency = 0LL;
 void
 abort(void)
 {
-    exit(0);
+    _exit(1);
 }