Re: System call for OS version info
Re: System call for OS version info
- Subject: Re: System call for OS version info
- From: Terry Lambert <email@hidden>
- Date: Sun, 15 Oct 2006 16:01:16 -0700
FWIW: This isn't really a kernel issue, and doesn't belong oon this
list...
-
Alternately, just write a couple of small utility functions, and call
sw_vers from your program, since it's unlikely you're going to be
calling this 60 times a second or anything:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int
getlinepart(char *line, char *dest)
{
int rv = -1; /* default to error */
char *p;
if ((p = strchr(line, ':')) != NULL) {
p++;
while(*p == ' ')
p++;
while(*p && *p != '\n')
*dest++ = *p++;
if (*p == '\n') {
/* line not truncated */
*dest = 0; /* NUL terminate */
rv = 0; /* success */
}
}
return(rv);
}
int
getverinfo( char *PN, char *PV, char *BV)
{
FILE *fp;
char line[ 128];
int rv = -1; /* default to error */
if ((fp = popen("/usr/bin/sw_vers", "r")) != NULL) {
if (fgets(line, sizeof(line), fp) != NULL) {
if (getlinepart(line, PN))
goto err;
} else goto err;
if (fgets(line, sizeof(line), fp) != NULL) {
if (getlinepart(line, PV))
goto err;
} else goto err;
if (fgets(line, sizeof(line), fp) != NULL) {
if (getlinepart(line, BV))
goto err;
} else goto err;
rv = 0; /* got all three lines */
}
err:
if (fp != NULL)
fclose(fp);
return(rv);
}
int
main(int ac, char *av[])
{
char ProductName[128];
char ProductVersion[128];
char BuildVersion[128];
if (getverinfo(ProductName, ProductVersion, BuildVersion)) {
perror("could not get version information");
exit (1);
}
printf("ProductName: %s\n", ProductName);
printf("ProductVersion: %s\n", ProductVersion);
printf("BuildVersion: %s\n", BuildVersion);
exit(0);
}
-- Terry
On Oct 15, 2006, at 2:09 PM, Tony Scaminaci wrote:
OK, now I see it, thanks.
I looked through your code and noted that the headers include
CoreFoundation which won't compile for 64-bit archs. I'll go ahead
and parse /System/Library/CoreServices/SystemVersion.plist instead.
Thanks everyone for your inputs.
Tony
On Oct 15, 2006, at 1:41 PM, plumber Idraulico wrote:
better look
/*pure darwin
http://plumber.gnu-darwin.org/home/pub/Pictures/system_info_x86.png
/*osx on top
http://plumber.gnu-darwin.org/home/pub/Pictures/system_info.png
I already have the kernel info. I'm looking for MacOS X system/
build info but thanks anyway.
Tony
On Oct 15, 2006, at 1:04 PM, plumber Idraulico wrote:
http://plumber.gnu-darwin.org/home/
SYSTEM_INFO (1)
Reports operating system information and hardware configuration.
take a look on src
-plum
On Oct 15, 2006, at 6:53 PM, Tony Scaminaci wrote:
Is there a low-level function call for obtaining the same OS
info as the unix utility "sw_vers" returns (see below)? I've
been browsing the kernel-level sysctl calls but I don't see
anything promising. Or would it be better to just do a system
invoke of "sw_vers" and parse the arguments for the MacOS
version info? Whatever I end up using must work on all 64-bit
processors.
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.4.8
BuildVersion: 8L127
All info is available in the following files:
/System/Library/CoreServices/ServerVersion.plist (if it exists)
/System/Library/CoreServices/SystemVersion.plist
--
Rui Paulo
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden