Re: How to know OS Version
Re: How to know OS Version
- Subject: Re: How to know OS Version
- From: Ben Trumbull <email@hidden>
- Date: Mon, 19 Nov 2007 19:43:37 -0500
In addition to previous suggestions (Carbon API, AppKit #define, etc),
it's also possible to use the sysctl() function to get just about any
piece of information about the current hardware and software
environment (cores, active cores, speed, memory, really darn near
anything). Those other methods are easier to use (and NSProcessInfo
has some nice new API on Leopard), but this function seems under
appreciated, so I recommend you look at the man page. I determined
the kernel OS revision #s experimentally.
#include <stdio.h>
#include <sys/sysctl.h>
int main (int argc, const char * argv[]) {
int preLeopardOS = 1;
int sels[2] = { CTL_KERN , KERN_OSRELEASE };
char buffer[128];
size_t bufsize = sizeof(buffer);
if (0 == sysctl(sels, 2, buffer, &bufsize, NULL, 0)) {
preLeopardOS = (strcmp(buffer, "9") < 0); // kern.osrevision = 8.8.1
on Tiger, 9.x on Leopard
}
printf("Hello, %s\n", (preLeopardOS) ? "Tiger" : "Leopard");
return 0;
}
One issue is that this will tell you the OS that is running, but NOT
the linkage of your application. For example, if you build against
the 10.4 SDK, and run on Leopard, the framework will try to give you
10.4 behavior, even though the OS is Leopard. This behavior could be
desirable, or not, depending on what you need.
- Ben
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden