Hi, I was wondering how you could detect what platform a program is running on, I have an application and need it to go to a certain folder depending on whether it is on a Linux or Mac machine.
Thanks!
Hi, I was wondering how you could detect what platform a program is running on, I have an application and need it to go to a certain folder depending on whether it is on a Linux or Mac machine.
Thanks!
If you know you're Unix, running 'uname' will tell you quite a bit about the system. if you need to know more. Of course, that's relying on an external executable.
There should be environmental variables you can check, but I'm not sure which ones.
You will probably need to compile the program specifically for Mac or Linux, so you can use some sort of preprocessor directive. This list of macros may be helpful.
The uname() system call will tell you about the version of the OS
It may break in the future, but for now, you can play on a large number of filesystem differences between both.
If you combine several of these path-checking tricks into a function, you can insulate yourself against any one of the tricks failing independently of the others.
You can check for folder existence by using stat.
struct stat st;
if(stat("/proc",&st) == 0) {
printf(" /proc is present: this may be Linux\n");
}