Pietro
Pietro

Reputation: 13172

Common macro to identify a UNIX derived system? (Linux, OSX, BSD, ...)

I wonder why on MacOSX the macro __unix__ is not defined.

Isn't MacOSX a BSD UNIX derivative?

If I define the __unix__ macro in my code, could I have some issues?

In general, when checking the current platform, I prefer to do something like:

#ifdef __unix__
...
#endif

instead of:

#if defined(__unix__) || defined(__APPLE__) || defined(__linux__) || defined(BSD) ...
...
#endif

Could the best option be to define my own macro in a single place? E.g.:

#if defined(__unix__) || defined(__APPLE__) || defined(__linux__) || defined(BSD) ...
#define UNIX_
#endif

Upvotes: 6

Views: 1202

Answers (1)

ninjalj
ninjalj

Reputation: 43718

POSIX requires _POSIX_VERSION to be defined in <unistd.h> (also accessible via sysconf(_SC_VERSION)), so try that.

Upvotes: 4

Related Questions