diff mbox series

msvc: Directly use MS version (_stricmp) of strcasecmp

Message ID ad85731f-2c47-f455-c9d3-d47a5fj1e29@cs-ware.de (mailing list archive)
State New, archived
Headers show
Series msvc: Directly use MS version (_stricmp) of strcasecmp | expand

Commit Message

Sven Strickroth Nov. 18, 2018, 9:02 p.m. UTC
This also removes an implicit conversion from size_t (unsigned) to int (signed).

_stricmp as well as _strnicmp are both available since VS2012.

Signed-off-by: Sven Strickroth <email@cs-ware.de>
---
 compat/msvc.h | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

--
2.19.1.windows.1

Comments

Jeff King Nov. 18, 2018, 9:58 p.m. UTC | #1
On Sun, Nov 18, 2018 at 10:02:02PM +0100, Sven Strickroth wrote:

> This also removes an implicit conversion from size_t (unsigned) to int (signed).
> 
> _stricmp as well as _strnicmp are both available since VS2012.

Once upon a time we had problems with taking a function pointer of
strcasecmp (to use as a comparator with string_list), so I wondered if
that might be part of why it's defined the way it is.

But the current definition is already inline:

> -
> -static __inline int strcasecmp (const char *s1, const char *s2)
> -{
> -       int size1 = strlen(s1);
> -       int sisz2 = strlen(s2);
> -       return _strnicmp(s1, s2, sisz2 > size1 ? sisz2 : size1);
> -}
> +#define strcasecmp   _stricmp

And it seems we worked around this in de2f95ebed (mailmap: work around
implementations with pure inline strcasecmp, 2013-09-12). So I don't
think there is any blocker there.

(Though of course I have no idea on other portability questions around
_stricmp(); I'll leave that for Windows folks).

-Peff
Junio C Hamano Nov. 19, 2018, 2:02 a.m. UTC | #2
Jeff King <peff@peff.net> writes:

> And it seems we worked around this in de2f95ebed (mailmap: work around
> implementations with pure inline strcasecmp, 2013-09-12). So I don't
> think there is any blocker there.
>
> (Though of course I have no idea on other portability questions around
> _stricmp(); I'll leave that for Windows folks).

Likewise.  As to the placement for the replacement #define, the
patch puts it where the inline version was, but I would think it
would work better if it were in the block of #defines, immediately
next to #define strncasecmp above.
.
diff mbox series

Patch

diff --git a/compat/msvc.h b/compat/msvc.h
index 580bb55bf4..ea6527f8b6 100644
--- a/compat/msvc.h
+++ b/compat/msvc.h
@@ -14,13 +14,7 @@ 
 #define ftruncate    _chsize
 #define strtoull     _strtoui64
 #define strtoll      _strtoi64
-
-static __inline int strcasecmp (const char *s1, const char *s2)
-{
-       int size1 = strlen(s1);
-       int sisz2 = strlen(s2);
-       return _strnicmp(s1, s2, sisz2 > size1 ? sisz2 : size1);
-}
+#define strcasecmp   _stricmp

 #undef ERROR