Permalink
Browse files

OS X: Fix parsing of 10.x.0 version numbers (fixes #32)

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...
1 parent c703331 commit 7fa815021dfbdd70fc8095adf97ce4dcd8f5bd54 @thp committed Nov 5, 2012
Showing with 11 additions and 3 deletions.
  1. +11 −3 src/platform/psmove_osxsupport.m
@@ -146,16 +146,24 @@
macosx_get_minor_version()
{
char tmp[1024];
- int major, minor, patch;
+ int major, minor, patch = 0;
FILE *fp;
fp = popen("sw_vers -productVersion", "r");
psmove_return_val_if_fail(fp != NULL, -1);
psmove_return_val_if_fail(fgets(tmp, sizeof(tmp), fp) != NULL, -1);
pclose(fp);
- psmove_return_val_if_fail(sscanf(tmp, "%d.%d.%d",
- &major, &minor, &patch) == 3, -1);
+ int assigned = sscanf(tmp, "%d.%d.%d", &major, &minor, &patch);
+
+ /**
+ * 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;
}

0 comments on commit 7fa8150

Please sign in to comment.