unbelievably, cygwin doesn't have strcasestr(3)

This commit is contained in:
tg 2006-11-12 13:15:27 +00:00
parent 5267e51098
commit 2c1ffced08
3 changed files with 72 additions and 2 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh
# $MirOS: src/bin/mksh/Build.sh,v 1.78 2006/11/12 13:09:09 tg Exp $
# $MirOS: src/bin/mksh/Build.sh,v 1.79 2006/11/12 13:15:26 tg Exp $
#-
# Environment: CC, CFLAGS, CPPFLAGS, LDFLAGS, LIBS, NROFF
@ -257,6 +257,11 @@ ac_test setgroups setresugid 0 <<-'EOF'
int main(void) { gid_t gid = 0; return (setgroups(0, &gid)); }
EOF
ac_test strcasestr <<-'EOF'
#include <string.h>
int main(int ac, char *av[]) { strcasestr(av[0], av[1]); return (ac); }
EOF
ac_test strlcpy <<-'EOF'
#include <string.h>
int main(int ac, char *av[]) { strlcpy(av[0], av[1], 1); return (ac); }
@ -264,6 +269,7 @@ EOF
$e ... done.
addsrcs HAVE_SETMODE setmode.c
addsrcs HAVE_STRCASESTR strcasestr.c
addsrcs HAVE_STRLCPY strlfun.c
(v "cd '$srcdir' && exec $CC $CFLAGS -I'$curdir' $CPPFLAGS" \

5
sh.h
View File

@ -8,7 +8,7 @@
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
/* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.81 2006/11/12 10:44:42 tg Exp $"
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.82 2006/11/12 13:15:26 tg Exp $"
#define MKSH_VERSION "R29 2006/11/12"
#if HAVE_SYS_PARAM_H
@ -124,6 +124,9 @@
mode_t getmode(const void *, mode_t);
void *setmode(const char *);
#endif
#if !HAVE_STRCASESTR
char *strcasestr(const char *, const char *);
#endif
#if !HAVE_STRLCPY
size_t strlcpy(char *, const char *, size_t);
#endif

61
strcasestr.c Normal file
View File

@ -0,0 +1,61 @@
/* $OpenBSD: strcasestr.c,v 1.2 2005/08/08 08:05:37 espie Exp $ */
/* $NetBSD: strcasestr.c,v 1.2 2005/02/09 21:35:47 kleink Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/strcasestr.c,v 1.1 2006/11/12 13:15:27 tg Exp $");
/*
* Find the first occurrence of find in s, ignore case.
*/
char *
strcasestr(const char *s, const char *find)
{
char c, sc;
size_t len;
if ((c = *find++) != 0) {
c = ksh_tolower((unsigned char)c);
len = strlen(find);
do {
do {
if ((sc = *s++) == 0)
return (NULL);
} while ((char)ksh_tolower((unsigned char)sc) != c);
} while (strncasecmp(s, find, len) != 0);
s--;
}
return ((char *)s);
}