Skip to content

Commit

Permalink
OS X: Fix parsing of 10.x.0 version numbers (fixes #32)
Browse files Browse the repository at this point in the history
For OS X versions with a patch version of 0, the sw_vers command does
not output the patch version (i.e. "10.8" instead of "10.8.0"), so we
fix this by accepting also two parsed numbers instead of only three.
  • Loading branch information
thp committed Nov 5, 2012
1 parent c703331 commit 7fa8150
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/platform/psmove_osxsupport.m
Expand Up @@ -146,16 +146,24 @@
macosx_get_minor_version() macosx_get_minor_version()
{ {
char tmp[1024]; char tmp[1024];
int major, minor, patch; int major, minor, patch = 0;
FILE *fp; FILE *fp;


fp = popen("sw_vers -productVersion", "r"); fp = popen("sw_vers -productVersion", "r");
psmove_return_val_if_fail(fp != NULL, -1); psmove_return_val_if_fail(fp != NULL, -1);
psmove_return_val_if_fail(fgets(tmp, sizeof(tmp), fp) != NULL, -1); psmove_return_val_if_fail(fgets(tmp, sizeof(tmp), fp) != NULL, -1);
pclose(fp); pclose(fp);


psmove_return_val_if_fail(sscanf(tmp, "%d.%d.%d", int assigned = sscanf(tmp, "%d.%d.%d", &major, &minor, &patch);
&major, &minor, &patch) == 3, -1);
/**
* On Mac OS X 10.8.0, the command returns "10.8", so we allow parsing
* only the first two numbers of the triplet, leaving the patch version
* to the default (0) set above.
*
* See: https://github.com/thp/psmoveapi/issue/32
**/
psmove_return_val_if_fail(assigned == 2 || assigned == 3, -1);


return minor; return minor;
} }
Expand Down

0 comments on commit 7fa8150

Please sign in to comment.