X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Fos_posix.cpp;h=7ddd89530f4883fda0efc85fdac69e4e4df67c4d;hb=2cfa02c89ce8779e328aecdcc4eeecce6c9a2dbf;hp=3eebbd862d4a78448b062a11ba10ce1232d8fcb8;hpb=43ac1bff7374a572d3bb0a8341ab3d167e3ac07d;p=apitrace diff --git a/common/os_posix.cpp b/common/os_posix.cpp index 3eebbd8..7ddd895 100644 --- a/common/os_posix.cpp +++ b/common/os_posix.cpp @@ -44,6 +44,10 @@ #include #endif +#ifdef ANDROID +#include +#endif + #ifndef PATH_MAX #warning PATH_MAX undefined #define PATH_MAX 4096 @@ -107,6 +111,12 @@ getCurrentDir(void) return path; } +bool +createDirectory(const String &path) +{ + return mkdir(path, 0777) == 0; +} + bool String::exists(void) const { @@ -118,9 +128,6 @@ String::exists(void) const return false; } - if (!S_ISREG(st.st_mode)) - return false; - return true; } @@ -130,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 @@ -139,8 +150,17 @@ int execute(char * const * args) return -1; } int status = -1; + int ret; waitpid(pid, &status, 0); - return status; + if (WIFEXITED(status)) { + ret = WEXITSTATUS(status); + } else if (WIFSIGNALED(status)) { + // match shell return code + ret = WTERMSIG(status) + 128; + } else { + ret = 128; + } + return ret; } } @@ -153,7 +173,20 @@ log(const char *format, ...) va_list ap; va_start(ap, format); fflush(stdout); - vfprintf(stderr, format, ap); +#ifdef ANDROID + __android_log_vprint(ANDROID_LOG_DEBUG, "apitrace", format, ap); +#else + 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; } @@ -165,7 +198,7 @@ long long timeFrequency = 0LL; void abort(void) { - exit(0); + _exit(1); }