]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Changes in shared code that don't affect open-vm-tools functionality.
authorVMware, Inc <>
Mon, 20 Dec 2010 22:10:54 +0000 (14:10 -0800)
committerMarcelo Vanzin <mvanzin@vmware.com>
Mon, 20 Dec 2010 22:10:54 +0000 (14:10 -0800)
Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/include/util.h
open-vm-tools/lib/include/vm_version.h
open-vm-tools/lib/user/util.c

index fd6c8c75dfbae2c7b177e176aee9307cbbe78149..d2b1cf61dedfe77effedf627738f842e69850a98 100644 (file)
@@ -128,6 +128,20 @@ void Util_BacktraceToBuffer(uintptr_t *basePtr,
 
 int Util_CompareDotted(const char *s1, const char *s2);
 
+/*
+ * This enum defines how Util_GetOpt should handle non-option arguments:
+ *
+ * UTIL_NONOPT_PERMUTE: Permute argv so that all non-options are at the end.
+ * UTIL_NONOPT_STOP:    Stop when first non-option argument is seen.
+ * UTIL_NONOPT_ALL:     Return each non-option argument as if it were
+ *                      an option with character code 1.
+ */
+typedef enum { UTIL_NONOPT_PERMUTE, UTIL_NONOPT_STOP, UTIL_NONOPT_ALL } Util_NonOptMode;
+struct option;
+int Util_GetOpt(int argc, char * const *argv, const struct option *opts,
+                Util_NonOptMode mode);
+
+
 #if defined(VMX86_STATS)
 Bool Util_QueryCStResidency(uint32 *numCpus, uint32 *numCStates,
                             uint64 **transitns, uint64 **residency,
index 59af0ecd1bd51e8c80031cb41bda1d7a22b83ce3..0a52098ef4c7c387e23e7699631d2f37743d8c9e 100644 (file)
 #define VCB_FILE_VERSION 4,0,0,0
 #define VIM_VERSION "5.0.0"
 #define VPX_VERSION "5.0.0"
+#define SVA_VERSION "1.0.0"
 #define WBC_VERSION "5.0.0"
 #define SDK_VERSION "4.1.0"
 #define FOUNDRY_VERSION "1.10.0"
 
 #define USB_ARBITRATOR_VERSION_MAJOR 8
 #define USB_ARBITRATOR_VERSION_MINOR 2
-#define USB_ARBITRATOR_VERSION_Z     2
+#define USB_ARBITRATOR_VERSION_Z     4
 #define USB_ARBITRATOR_VERSION_BASE  USB_ARBITRATOR_VERSION_MAJOR.\
                                      USB_ARBITRATOR_VERSION_MINOR
 
  * USB Arbitrator Component version. This version is used by the linux
  * installer. See USB_ARBITRATOR_COMPONENT_VERSION_NUMBER in mk/defs-onetime.mk
  */
-#define USB_ARBITRATOR_COMPONENT_VERSION_NUMBER "8.2.2"
+#define USB_ARBITRATOR_COMPONENT_VERSION_NUMBER "8.2.4"
 
 #ifdef VMX86_VPX
 #define VIM_API_TYPE "VirtualCenter"
index efdde02eac838b67d3779ce2c8262697e7e4187c..b682265d9f41769aae20e8bd2c3e0e6e9796f9dd 100644 (file)
@@ -36,6 +36,7 @@
 # include <io.h>
 # include <process.h>
 # include "coreDump.h"
+# include "getoptWin32.h"
 #endif
 
 #include <fcntl.h>
@@ -48,6 +49,7 @@
 
 #if !defined(_WIN32) && !defined(N_PLAT_NLM)
 #  include <unistd.h>
+#  include <getopt.h>
 #  include <pwd.h>
 #  include <dlfcn.h>
 #endif
@@ -935,6 +937,142 @@ Util_CompareDotted(const char *s1, const char *s2)
 }
 
 
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * Util_GetOpt --
+ *
+ *      A wrapper around getopt_long that avoids needing separate long and
+ *      short option lists.
+ *
+ *      To use this, the array of option structs must:
+ *      * Store the short option name in the 'val' member.
+ *      * Set the 'name' member to NULL if the option has a short name but no
+ *        long name.
+ *      * For options that have only a long name, 'val' should be set to a
+ *        unique value greater than UCHAR_MAX.
+ *      * Terminate the array with a sentinel value that zero-initializes both
+ *        'name' and 'val'.
+ *
+ * Results:
+ *      See getopt_long.
+ *
+ * Side effects:
+ *      None
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+int
+Util_GetOpt(int argc,                  // IN
+            char * const *argv,        // IN
+            const struct option *opts, // IN
+            Util_NonOptMode mode)      // IN
+{
+   int ret = -1;
+
+   struct option *longOpts = NULL;
+   char *shortOptString = NULL;
+
+   /*
+    * In the worst case, each character needs "::" to indicate that it takes
+    * an optional argument.
+    */
+   const size_t maxCharsPerShortOption = 3;
+   const size_t modePrefixSize = 1;
+
+   size_t n = 0;
+   size_t shortOptStringSize;
+
+   while (!(opts[n].name == NULL && opts[n].val == 0)) {
+      if (UNLIKELY(n == SIZE_MAX)) {
+         /*
+          * Avoid integer overflow.  If you have this many options, you're
+          * doing something wrong.
+          */
+         ASSERT(FALSE);
+         goto exit;
+      }
+      n++;
+   }
+
+   if (UNLIKELY(n > SIZE_MAX / sizeof *longOpts - 1)) {
+      /* Avoid integer overflow. */
+      ASSERT(FALSE);
+      goto exit;
+   }
+   longOpts = malloc((n + 1) * sizeof *longOpts);
+   if (longOpts == NULL) {
+      goto exit;
+   }
+
+   if (UNLIKELY(n > (SIZE_MAX - modePrefixSize - 1 /* NUL */) /
+                maxCharsPerShortOption)) {
+      /* Avoid integer overflow. */
+      ASSERT(FALSE);
+      goto exit;
+   }
+   shortOptStringSize = n * maxCharsPerShortOption + modePrefixSize + 1 /* NUL */;
+   shortOptString = malloc(shortOptStringSize);
+   if (shortOptString == NULL) {
+      goto exit;
+   } else {
+      struct option empty = { 0 };
+
+      size_t i;
+      struct option *longOptOut = longOpts;
+      char *shortOptOut = shortOptString;
+
+      switch (mode) {
+         case UTIL_NONOPT_STOP:
+            *shortOptOut++ = '+';
+            break;
+         case UTIL_NONOPT_ALL:
+            *shortOptOut++ = '-';
+            break;
+         default:
+            break;
+      }
+
+      for (i = 0; i < n; i++) {
+         int val = opts[i].val;
+
+         if (opts[i].name != NULL) {
+            *longOptOut++ = opts[i];
+         }
+
+         if (val > 0 && val <= UCHAR_MAX) {
+            int argSpec = opts[i].has_arg;
+
+            *shortOptOut++ = (char) val;
+
+            if (argSpec != no_argument) {
+               *shortOptOut++ = ':';
+
+               if (argSpec == optional_argument) {
+                  *shortOptOut++ = ':';
+               }
+            }
+         }
+      }
+
+      ASSERT(longOptOut - longOpts <= n);
+      *longOptOut = empty;
+
+      ASSERT(shortOptOut - shortOptString < shortOptStringSize);
+      *shortOptOut = '\0';
+   }
+
+   ret = getopt_long(argc, argv, shortOptString, longOpts, NULL);
+
+exit:
+   free(longOpts);
+   free(shortOptString);
+   return ret;
+}
+
+
+
 
 /*
  *-----------------------------------------------------------------------------