Reputation: 65
I know it isn't simple, I've been researching it for a while, and now I'm almost sure that there's no completely safe way of doing so. But here is it. I looking for a way of knowing which is the Operating System that my application is running on. Up to now, I got this:
#if defined(__WIN64__) || defined(__WIN64) || defined(WIN64)
#define NLF_OS_WINDOWS
#define NLF_OS_64BITS
#elif defined(__WIN32__) || defined(__WIN32) || defined(WIN32)
#define NLF_OS_WINDOWS
#define NLF_OS_32BITS
#elif defined(unix) || defined(__unix__) || defined(__unix)
#define NLF_OS_UNIX
#if defined(__APPLE__)
#define NLF_OS_APPLE
#define NLF_OS_BITS_UNIDENTIFIED
#include <TargetConditionals.h>
#if TARGET_OS_IPHONE && TARGET_IPHONE_SIMULATOR
#define NLF_OS_SIMULATOR
#elif TARGET_OS_IPHONE
#define NLF_OS_IPHONE
#else
#define NLF_OS_OSX
#endif
#elif defined(__linux__) || defined(__linux) || defined(linux)
#define NLF_OS_LINUX
#if defined(i386) || defined(__i386) || defined(__i386__)
#define NLF_OS_32BITS
#elif defined(amd64) || defined(__amd64) || defined(__amd64__)
#define NLF_OS_64BITS
#endif
#elif defined(__FreeBSD__) || defined(__FreeBSD) || defined(FreeBSD)
#define NLF_OS_FREEBSD
#if defined(i386) || defined(__i386) || defined(__i386__)
#define NLF_OS_32BITS
#elif defined(amd64) || defined(__amd64) || defined(__amd64__)
#define NLF_OS_64BITS
#endif
#endif
#else
#define NLF_OS_UNIDENTIFIED
#define NLF_OS_BITS_UNIDENTIFIED
#endif
It has already helped, but it only tells me what is the system when I'm compiling the application. But, since I want to cross-compile what I'm doing, it would be tremendously useful if I could provide to the app a way to know which is the current running system. Get it?
May be I may use the libraries sys/"something" (like sys/types.h and sys/stat.h) to do some ugly stuff, but I barely know any of those things.
PS.: A C++ solution isn't exactly what I want, but at this high I'm on it ^^"
Upvotes: 0
Views: 148
Reputation: 65
Just finally answering this question.
The answer is: you don't need to. I've noticed that. The defines already works just fine. If you're compiling a C code for another platform, the cross compiler will take care of redefining de defines, so your system will always know what system is if you use the preprocessor directives.
But if for, some reason you really need it, you'll have to do ugly stuff. Like use a system("uname -a > my_file"); and then reading my_file content, and then try another command if this one do not works.
Mainly, you don't need it =)
Upvotes: 1