From: VMware, Inc <> Date: Mon, 20 Dec 2010 22:10:54 +0000 (-0800) Subject: Changes in shared code that don't affect open-vm-tools functionality. X-Git-Tag: 2010.12.19-339835~24 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f20573db3bdde6bae19c8fb2b4c0d04b9177e0f1;p=thirdparty%2Fopen-vm-tools.git Changes in shared code that don't affect open-vm-tools functionality. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/include/util.h b/open-vm-tools/lib/include/util.h index fd6c8c75d..d2b1cf61d 100644 --- a/open-vm-tools/lib/include/util.h +++ b/open-vm-tools/lib/include/util.h @@ -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, diff --git a/open-vm-tools/lib/include/vm_version.h b/open-vm-tools/lib/include/vm_version.h index 59af0ecd1..0a52098ef 100644 --- a/open-vm-tools/lib/include/vm_version.h +++ b/open-vm-tools/lib/include/vm_version.h @@ -219,6 +219,7 @@ #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" @@ -276,7 +277,7 @@ #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 @@ -291,7 +292,7 @@ * 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" diff --git a/open-vm-tools/lib/user/util.c b/open-vm-tools/lib/user/util.c index efdde02ea..b682265d9 100644 --- a/open-vm-tools/lib/user/util.c +++ b/open-vm-tools/lib/user/util.c @@ -36,6 +36,7 @@ # include # include # include "coreDump.h" +# include "getoptWin32.h" #endif #include @@ -48,6 +49,7 @@ #if !defined(_WIN32) && !defined(N_PLAT_NLM) # include +# include # include # include #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; +} + + + /* *-----------------------------------------------------------------------------