Re: How to know OS Version
Re: How to know OS Version
- Subject: Re: How to know OS Version
- From: "E. Wing" <email@hidden>
- Date: Tue, 20 Nov 2007 01:30:45 -0800
I would be careful about using sysctl to determine the OS X version
number. I could be wrong so please correct me if I am, but I believe
it is possible to upgrade the Darwin independently of OS X since
Darwin is open source. (I've heard of situations where people needed
certain functionality from the kernel that was not yet shipped by
Apple, so upgrading Darwin was the recommended solution.)
As far as I know, sysctl only can tell you the kernel version, not the
OS X version sitting on top of it.
-Eric
On 11/19/07, Ben Trumbull <email@hidden> wrote:
> 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
>
_______________________________________________
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