Skip to content

Commit

Permalink
OS X compilation / Hieu
Browse files Browse the repository at this point in the history
  • Loading branch information
kpu committed Apr 10, 2016
1 parent 40d379b commit 1a325b1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
14 changes: 10 additions & 4 deletions util/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,17 @@ std::string DefaultTempDirectory() {
// POSIX says to try these environment variables, in this order:
const char *const vars[] = {"TMPDIR", "TMP", "TEMPDIR", "TEMP", 0};
for (int i=0; vars[i]; ++i) {
#if defined(_GNU_SOURCE) && __GLIBC_PREREQ(2,17)
const char *val = secure_getenv(vars[i]);
#else
const char *val = getenv(vars[i]);
char *val =
#if defined(_GNU_SOURCE)
#if __GLIBC_PREREQ(2,17)
secure_getenv
#else // __GLIBC_PREREQ
getenv
#endif // __GLIBC_PREREQ
#else // _GNU_SOURCE
getenv
#endif
(vars[i]);
// Environment variable is set and nonempty. Use it.
if (val && *val) return val;
}
Expand Down
5 changes: 5 additions & 0 deletions util/usage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ double WallTime() {
double CPUTime() {
#if defined(_WIN32) || defined(_WIN64)
return 0.0;
#elif defined(__MACH__) || defined(__FreeBSD__) || defined(__APPLE__)
struct rusage usage;
if (getrusage(RUSAGE_SELF, &usage))
return 0.0;
return DoubleSec(usage.ru_utime) + DoubleSec(usage.ru_stime);
#else
struct timespec usage;
UTIL_THROW_IF(clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &usage), ErrnoException, "clock_gettime failed?!");
Expand Down

0 comments on commit 1a325b1

Please sign in to comment.