From: John Wolfe Date: Tue, 27 Jul 2021 17:37:24 +0000 (-0700) Subject: Changes to common source files not applicable to open-vm-tools. X-Git-Tag: stable-12.0.0~144 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61e3c68f029af528e61de5b22b215ef689870be2;p=thirdparty%2Fopen-vm-tools.git Changes to common source files not applicable to open-vm-tools. --- diff --git a/open-vm-tools/lib/include/strutil.h b/open-vm-tools/lib/include/strutil.h index 5022a6d74..43ee5519b 100644 --- a/open-vm-tools/lib/include/strutil.h +++ b/open-vm-tools/lib/include/strutil.h @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 1998-2018 VMware, Inc. All rights reserved. + * Copyright (C) 1998-2018, 2021 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -37,6 +37,10 @@ struct DynBuf; char *StrUtil_GetNextToken(unsigned int *index, const char *str, const char *delimiters); +#if defined(_WIN32) +wchar_t *StrUtil_GetNextTokenW(unsigned int *index, const wchar_t *str, + const wchar_t *delimiters); +#endif Bool StrUtil_GetNextIntToken(int32 *out, unsigned int *index, const char *str, const char *delimiters); Bool StrUtil_GetNextUintToken(uint32 *out, unsigned int *index, const char *str, diff --git a/open-vm-tools/lib/misc/strutil.c b/open-vm-tools/lib/misc/strutil.c index 5eb659a80..6152b811c 100644 --- a/open-vm-tools/lib/misc/strutil.c +++ b/open-vm-tools/lib/misc/strutil.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 1998-2019 VMware, Inc. All rights reserved. + * Copyright (C) 1998-2019, 2021 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -26,7 +26,9 @@ #include #include #include -#if !defined(_WIN32) +#if defined(_WIN32) +#include +#else #include /* For strncasecmp */ #include #endif @@ -133,6 +135,75 @@ StrUtil_GetNextToken(unsigned int *index, // IN/OUT: Index to start at } +#if defined(_WIN32) +/* + ****************************************************************************** + * StrUtil_GetNextTokenW -- + * + * Get the next token from a UTF-16 string after a given index w/o + * modifying the original string. This routine is based on the + * StrUtil_GetNextToken() function but convert it from ASCII to Unicode + * version. + * + * Results: + * An allocated, NULL-terminated string containing the token. 'index' + * is updated to point after the returned token + * NULL if no tokens are left + * + * Side effects: + * None + * + ****************************************************************************** + */ + +wchar_t * +StrUtil_GetNextTokenW(unsigned int *index, // IN/OUT: Index to start at + const wchar_t *str, // IN : String to parse + const wchar_t *delimiters) // IN : Separating tokens +{ + unsigned int startIndex; + unsigned int length; + wchar_t *token; + + ASSERT(index != NULL); + ASSERT(str != NULL); + ASSERT(delimiters != NULL); + ASSERT(*index <= wcslen(str)); + +#define NOT_DELIMITER (wcschr(delimiters, str[*index]) == NULL) + + /* Skip leading delimiters. */ + for (;; (*index)++) { + if (str[*index] == L'\0') { + return NULL; + } + + if (NOT_DELIMITER) { + break; + } + } + startIndex = *index; + + /* + * Walk the string until we reach the end of it, or we find a + * delimiter. + */ + for ((*index)++; str[*index] != L'\0' && NOT_DELIMITER; (*index)++) { + } + +#undef NOT_DELIMITER + + length = *index - startIndex; + ASSERT(length); + token = Util_SafeMalloc(sizeof *token * (length + 1)); + wmemcpy(token, str + startIndex, length); + token[length] = L'\0'; + + return token; +} +#endif + + /* *----------------------------------------------------------------------------- *