Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 393
Pietro Avatar asked Oct 27 '11 14:10

Pietro


1 Answers

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

like image 143
ninjalj Avatar answered Sep 29 '22 12:09

ninjalj