From: Oliver Kurth Date: Mon, 23 Oct 2017 21:21:21 +0000 (-0700) Subject: strutil.c: Add a case-insensitive version of StrUtil_EndsWith. X-Git-Tag: stable-10.3.0~251 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39d8a762211ed0d599cc9834f4eaf15c9fa41dfa;p=thirdparty%2Fopen-vm-tools.git strutil.c: Add a case-insensitive version of StrUtil_EndsWith. Common header file change; 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 e7585eef1..8a4be3d1a 100644 --- a/open-vm-tools/lib/include/strutil.h +++ b/open-vm-tools/lib/include/strutil.h @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 1998-2016 VMware, Inc. All rights reserved. + * Copyright (C) 1998-2017 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 @@ -61,6 +61,7 @@ size_t StrUtil_GetLongestLineLength(const char *buf, size_t bufLength); Bool StrUtil_StartsWith(const char *s, const char *prefix); Bool StrUtil_CaselessStartsWith(const char *s, const char *prefix); Bool StrUtil_EndsWith(const char *s, const char *suffix); +Bool StrUtil_CaselessEndsWith(const char *s, const char *suffix); Bool StrUtil_IsASCII(const char *s); Bool StrUtil_VDynBufPrintf(struct DynBuf *b, const char *fmt, va_list args); diff --git a/open-vm-tools/lib/include/vm_product_versions.h b/open-vm-tools/lib/include/vm_product_versions.h index c66edea45..3ba3f6ae2 100644 --- a/open-vm-tools/lib/include/vm_product_versions.h +++ b/open-vm-tools/lib/include/vm_product_versions.h @@ -162,7 +162,7 @@ #define FLEX_CLIENT_VERSION_NUMBER "8.0.0" #define FLEX_CLIENT_VERSION "e.x.p" -#define GANTRY_VERSION "e.x.p" +#define GANTRY_VERSION "1.0.0" /* * In the *-main branches, FUSION_VERSION should always be set to "e.x.p". diff --git a/open-vm-tools/lib/misc/strutil.c b/open-vm-tools/lib/misc/strutil.c index 27f230bd1..425d76bc0 100644 --- a/open-vm-tools/lib/misc/strutil.c +++ b/open-vm-tools/lib/misc/strutil.c @@ -914,8 +914,8 @@ StrUtil_EndsWith(const char *s, // IN size_t slen; size_t suffixlen; - ASSERT(s); - ASSERT(suffix); + ASSERT(s != NULL); + ASSERT(suffix != NULL); slen = strlen(s); suffixlen = strlen(suffix); @@ -928,6 +928,45 @@ StrUtil_EndsWith(const char *s, // IN } +/* + *----------------------------------------------------------------------------- + * + * StrUtil_CaselessEndsWith -- + * + * A case-insensitive version of StrUtil_EndsWith. + * + * Results: + * TRUE if string 'suffix' is found at the end of string 's' + * FALSE otherwise. + * + * Side effects: + * None. + * + *----------------------------------------------------------------------------- + */ + +Bool +StrUtil_CaselessEndsWith(const char *s, // IN + const char *suffix) // IN +{ + size_t slen; + size_t suffixlen; + + ASSERT(s != NULL); + ASSERT(suffix != NULL); + ASSERT(StrUtil_IsASCII(suffix)); + + slen = strlen(s); + suffixlen = strlen(suffix); + + if (suffixlen > slen) { + return FALSE; + } + + return Str_Strcasecmp(s + (slen - suffixlen), suffix) == 0; +} + + /* *----------------------------------------------------------------------------- *