Merge pull request #243 from avdgrinten/fix-ansi-build

Fix ANSI-only build after strcasestr() implementation
This commit is contained in:
Alexander van der Grinten 2021-03-24 22:30:36 +01:00 committed by GitHub
commit 91a0ad612a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 15 deletions

View file

@ -1,5 +1,4 @@
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <wchar.h>
#include <ctype.h>
@ -224,18 +223,6 @@ char *strchrnul(const char *s, int c) {
return const_cast<char *>(s + i);
}
char *strcasestr(const char *s, const char *pattern) {
size_t plen = strlen(pattern);
const char *p = s;
while(*p) {
// Need strncasecmp() to avoid checking past the end of a successful match.
if(!strncasecmp(p, pattern, plen))
return const_cast<char *>(p);
++p;
}
return nullptr;
}
double wcstod(const wchar_t *__restrict, wchar_t **__restrict) MLIBC_STUB_BODY
float wcstof(const wchar_t *__restrict, wchar_t **__restrict) MLIBC_STUB_BODY
long double wcstold(const wchar_t *__restrict, wchar_t **__restrict) MLIBC_STUB_BODY

View file

@ -42,7 +42,6 @@ char *strtok(char *__restrict s, const char *__restrict delimiter);
// This is a GNU extension.
char *strchrnul(const char *, int);
char *strcasestr(const char *, const char *);
// [7.24.6] Miscellaneous functions

View file

@ -1,7 +1,7 @@
#include <bits/ensure.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <signal.h>
#include <mlibc/debug.hpp>
@ -101,3 +101,14 @@ char *strsignal(int sig) {
return const_cast<char *>(s);
}
char *strcasestr(const char *s, const char *pattern) {
size_t plen = strlen(pattern);
const char *p = s;
while(*p) {
// Need strncasecmp() to avoid checking past the end of a successful match.
if(!strncasecmp(p, pattern, plen))
return const_cast<char *>(p);
++p;
}
return nullptr;
}

View file

@ -17,6 +17,9 @@ char *strsignal(int sig);
int strcoll_l(const char *s1, const char *s2, locale_t locale);
// GNU extensions.
char *strcasestr(const char *, const char *);
#ifdef __cplusplus
}
#endif