]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Add constants for macOS os major versions.
authorOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:32 +0000 (11:23 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:32 +0000 (11:23 -0700)
MacOS versions can get a bit confusing because there are two parallel
versioning schemes. There is the marketing version (e.g. 10.6, 10.7.5, etc.)
which is what everybody uses when discussing the OS but is very hard to get
at via code, and there is the kernel version (e.g. 10.0.0, 11.4.2) which
is what is returned by POSIX syscalls like uname. The confusion sets in
because in comments we tend to use the marketing version, but then the
code actually checks for the kernel version.

This change adds constants for the marketing version for comparisons with
HostInfo_OSVersion(0) (the major version), which makes checking for
10.6 vs 10.7 vs 10.8 etc. much more readable.

open-vm-tools/lib/file/fileIOPosix.c
open-vm-tools/lib/include/hostinfo.h

index d85812af074c15a218c3e09f5024980629f37ab1..73f7888fc02d19da75d4e46414cda5ff1de9fad9 100644 (file)
@@ -958,10 +958,9 @@ FileIOCreateRetry(FileIODescriptor *file,   // OUT:
 
       if (!(access & FILEIO_OPEN_SYNC)) {
          /*
-          * F_NODIRECT was added in Mac OS 10.7.0 "Lion" which has Darwin
-          * kernel 11.0.0.
+          * F_NODIRECT was added in Mac OS 10.7.0 "Lion".
           */
-         if (Hostinfo_OSVersion(0) >= 11) {
+         if (Hostinfo_OSVersion(0) >= HOSTINFO_OS_VERSION_MACOS_10_7) {
             error = fcntl(fd, F_NODIRECT, 1);
             if (error == -1) {
                ret = FileIOErrno2Result(errno);
index abba8e3bb7ea18ea786988fe4b9d928831b7deb1..67b09058c24188a353d35e6ff6a124de5606bde3 100644 (file)
@@ -79,6 +79,22 @@ Hostinfo_SystemTimerMS(void)
    return Hostinfo_SystemTimerNS() / 1000000ULL;
 }
 
+/*
+ * Apple's kernel major versions are the same as their marketed
+ * minor versions + 4. (E.g. Marketed 10.8.0 == Kernel 12.0.0)
+ * These constants simplify this and make code easier to read / understand.
+ */
+enum {
+   HOSTINFO_OS_VERSION_MACOS_10_5  = 9,
+   HOSTINFO_OS_VERSION_MACOS_10_6  = 10,
+   HOSTINFO_OS_VERSION_MACOS_10_7  = 11,
+   HOSTINFO_OS_VERSION_MACOS_10_8  = 12,
+   HOSTINFO_OS_VERSION_MACOS_10_9  = 13,
+   HOSTINFO_OS_VERSION_MACOS_10_10 = 14,
+   HOSTINFO_OS_VERSION_MACOS_10_11 = 15,
+   HOSTINFO_OS_VERSION_MACOS_10_12 = 16,
+};
+
 int Hostinfo_OSVersion(unsigned int i);
 int Hostinfo_GetSystemBitness(void);
 const char *Hostinfo_OSVersionString(void);