-
Notifications
You must be signed in to change notification settings - Fork 1
/
osversion.c
54 lines (46 loc) · 1.22 KB
/
osversion.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// Created by Stefan Schwarz on 12/11/2016.
//
#include <stdio.h>
#include <CoreServices/CoreServices.h>
/**
* GetOSVersionComponent.
* Retrieves the version information component
* @param component the component of interest
* @return
*/
static inline int GetOSVersionComponent(int component)
{
char cmd[64] ;
sprintf(
cmd,
"sw_vers -productVersion | awk -F '.' '{print $%d}'",
component
) ;
FILE* stdoutFile = popen(cmd, "r") ;
int answer = 0 ;
if (stdoutFile)
{
char buff[16] ;
char *stdout = fgets(buff, sizeof(buff), stdoutFile) ;
pclose(stdoutFile) ;
sscanf(stdout, "%d", &answer) ;
}
return answer ;
}
static int GetGestaltOSVersion()
{
SInt32 major=0, minor=0, bugfix=0;
//OSErr err = if (err == noErr)
Gestalt(gestaltSystemVersionMajor, &major);
Gestalt(gestaltSystemVersionMinor, &minor);
Gestalt(gestaltSystemVersionBugFix, &bugfix);
printf("OS Version : %i.%i.%i\n", major, minor, bugfix);
return 0;
}
int main(int argc, char **argv)
{
printf("OS Version : %i.%i.%i\n", GetOSVersionComponent(1), GetOSVersionComponent(2), GetOSVersionComponent(3));
GetGestaltOSVersion();
return 0;
}