Skip to content

Commit

Permalink
string: Implement strcasestr for Windows.
Browse files Browse the repository at this point in the history
strcasestr is not defined for Windows, so implement a version
that could be used on Windows. This is needed for an upcoming
patch.

Signed-off-by: Darrell Ball <dlu998@gmail.com>
Co-authored-by: Ben Pfaff <blp@ovn.org>
Signed-off-by: Ben Pfaff <blp@ovn.org>
  • Loading branch information
darball1 and blp committed Aug 7, 2017
1 parent 2585418 commit 1ba9f0e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
22 changes: 20 additions & 2 deletions lib/string.c
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2011 Nicira, Inc.
* Copyright (c) 2009, 2011, 2017 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,9 +15,11 @@
*/

#include <config.h>

#include <ctype.h>
#include <string.h>

#include "util.h"

#ifndef HAVE_STRNLEN
size_t
strnlen(const char *s, size_t maxlen)
Expand All @@ -26,3 +28,19 @@ strnlen(const char *s, size_t maxlen)
return end ? end - s : maxlen;
}
#endif

#ifdef _WIN32
char *strcasestr(const char *str, const char *substr)
{
do {
for (size_t i = 0; ; i++) {
if (!substr[i]) {
return CONST_CAST(char *, str);
} else if (tolower(substr[i]) != tolower(str[i])) {
break;
}
}
} while (*str++);
return NULL;
}
#endif
3 changes: 2 additions & 1 deletion lib/string.h.in
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2011, 2013 Nicira, Inc.
* Copyright (c) 2009, 2011, 2013, 2017 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,6 +36,7 @@
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define strerror_r(errnum, buf, buflen) strerror_s(buf, buflen, errnum)
char *strcasestr(const char *, const char *);
#endif

#ifndef HAVE_STRNLEN
Expand Down

0 comments on commit 1ba9f0e

Please sign in to comment.