I have created a module for this.
$ clib install abranhe/os.c
// | |
// Which os? | |
// https://repl.it/@abranhe/which-os | |
// | |
#include <iostream> | |
std::string getOsName() | |
{ | |
#ifdef _WIN32 | |
return "Windows 32-bit"; | |
#elif _WIN64 | |
return "Windows 64-bit"; | |
#elif __unix || __unix__ | |
return "Unix"; | |
#elif __APPLE__ || __MACH__ | |
return "Mac OSX"; | |
#elif __linux__ | |
return "Linux"; | |
#elif __FreeBSD__ | |
return "FreeBSD"; | |
#else | |
return "Other"; | |
#endif | |
} | |
int main() { | |
std::cout << "OS: " << getOsName() << std::endl; | |
} |