Skip to content

Commit ee11d31

Browse files
author
Bot
committed
GNU_SOURCE
1 parent b9e4cb3 commit ee11d31

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

cinderx/Jit/perf_jitdump.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Copyright (c) Meta Platforms, Inc. and affiliates.
22

3+
#ifndef _GNU_SOURCE
4+
#define _GNU_SOURCE
5+
#endif
36
#include "cinderx/Jit/perf_jitdump.h"
47

58
#include "cinderx/python.h"
@@ -61,16 +64,14 @@ const size_t kJitdumpMmapSize = 1;
6164
// C++-friendly wrapper around strerror_r().
6265
std::string string_error(int errnum) {
6366
char buf[1024];
64-
// This template trick detects the return type of strerror_r at compile time.
65-
// If it returns char*, we're using GNU version. If it returns int, POSIX.
66-
if constexpr (std::is_same_v<decltype(strerror_r(0, buf, 0)), char*>) {
67-
// GNU version: returns char* (possibly pointing to a static string)
68-
return strerror_r(errnum, buf, sizeof(buf));
69-
} else {
70-
// POSIX version: returns int, writes to buffer
71-
strerror_r(errnum, buf, sizeof(buf));
72-
return std::string{buf};
73-
}
67+
// There's two forms of strerror_r(), one that returns a string and one that
68+
// returns an int.
69+
#if __APPLE__
70+
strerror_r(errnum, buf, sizeof(buf));
71+
return std::string{buf};
72+
#else
73+
return strerror_r(errnum, buf, sizeof(buf));
74+
#endif
7475
}
7576

7677
class FileLock {

0 commit comments

Comments
 (0)