X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Fos_posix.cpp;h=0d93b31bcafa6e56604fa639a7656d20128835ca;hb=940cdb8b143455fe2fc002ffd50f5e2ffcaf1260;hp=e6af7383f35b6a78b4efad1fcf1339bb8a3f5531;hpb=d4914919cff7675d3c24ca115af5b040390a8f99;p=apitrace diff --git a/common/os_posix.cpp b/common/os_posix.cpp index e6af738..0d93b31 100644 --- a/common/os_posix.cpp +++ b/common/os_posix.cpp @@ -30,7 +30,6 @@ #include #include -#include #include #include #include @@ -45,6 +44,10 @@ #include #endif +#ifdef ANDROID +#include +#endif + #ifndef PATH_MAX #warning PATH_MAX undefined #define PATH_MAX 4096 @@ -131,7 +134,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 @@ -140,8 +147,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; } } @@ -154,18 +170,18 @@ log(const char *format, ...) va_list ap; va_start(ap, format); fflush(stdout); +#ifdef ANDROID + __android_log_vprint(ANDROID_LOG_DEBUG, "apitrace", format, ap); +#else vfprintf(stderr, format, ap); +#endif va_end(ap); logging = false; } -long long -getTime(void) -{ - struct timeval tv; - gettimeofday(&tv, NULL); - return tv.tv_usec + tv.tv_sec*1000000LL; -} +#if defined(__APPLE__) +long long timeFrequency = 0LL; +#endif void abort(void)