Hi,

Attached is a patch that implement strcasestr() in GNUlib.

Regards,

-- 
Yoann Vandoorselaere <[EMAIL PROTECTED]>
diff -urNp gnulib.orig/lib/strcasestr.c gnulib/lib/strcasestr.c
--- gnulib.orig/lib/strcasestr.c	1970-01-01 01:00:00.000000000 +0100
+++ gnulib/lib/strcasestr.c	2005-08-13 20:17:10.000000000 +0200
@@ -0,0 +1,57 @@
+/* Copyright (C) 2005 Free Software Foundation, Inc.
+   Written by Yoann Vandoorselaere <[EMAIL PROTECTED]>
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by the
+   Free Software Foundation; either version 2, or (at your option) any
+   later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+
+/* Needed for strncasecmp */
+#include "strcase.h"
+
+
+char *
+strcasestr (const char *haystack, const char *needle)
+{
+  int ret;
+  size_t len = strlen (needle);
+
+  /*
+   * Hack to convert from const without warning.
+   */
+  union
+  {
+    const char *ro;
+    char *rw;
+  } conv;
+  conv.ro = haystack;
+
+  while (*conv.ro)
+    {
+
+      ret = strncasecmp (conv.ro, needle, len);
+      if (ret == 0)
+	return conv.rw;
+
+      conv.ro++;
+    }
+
+  return NULL;
+}
diff -urNp gnulib.orig/lib/strcasestr.h gnulib/lib/strcasestr.h
--- gnulib.orig/lib/strcasestr.h	1970-01-01 01:00:00.000000000 +0100
+++ gnulib/lib/strcasestr.h	2005-08-13 20:17:10.000000000 +0200
@@ -0,0 +1,36 @@
+/* Copyright (C) 2005 Free Software Foundation, Inc.
+   Written by Yoann Vandoorselaere <[EMAIL PROTECTED]>.
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#if HAVE_STRCASESTR
+
+/* Get strcasestr() declaration.  */
+#include <string.h>
+
+#else
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Case-Insensitive find of the first occurrence of NEEDLE in HAYSTACK. */
+extern char *strcasestr(const char *haystack, const char *needle);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff -urNp gnulib.orig/m4/strcasestr.m4 gnulib/m4/strcasestr.m4
--- gnulib.orig/m4/strcasestr.m4	1970-01-01 01:00:00.000000000 +0100
+++ gnulib/m4/strcasestr.m4	2005-08-13 20:16:59.000000000 +0200
@@ -0,0 +1,17 @@
+# strcasestr.m4 serial 1
+dnl Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_STRCASESTR],
+[
+  dnl Persuade glibc <string.h> to declare strcasestr().
+  AC_REQUIRE([AC_GNU_SOURCE])
+
+  AC_REPLACE_FUNCS(strcasestr)
+  gl_PREREQ_STRCASESTR
+])
+
+# Prerequisites of lib/strcasestr.c.
+AC_DEFUN([gl_PREREQ_STRCASESTR], [:])
diff -urNp gnulib.orig/modules/strcasestr gnulib/modules/strcasestr
--- gnulib.orig/modules/strcasestr	1970-01-01 01:00:00.000000000 +0100
+++ gnulib/modules/strcasestr	2005-08-13 20:17:19.000000000 +0200
@@ -0,0 +1,26 @@
+Description:
+strcasestr() function: case-insensitive search for a substring in a string.
+
+Files:
+lib/strcasestr.h
+lib/strcasestr.c
+m4/strcasestr.m4
+
+Depends-on:
+strcase
+
+configure.ac:
+gl_FUNC_STRCASESTR
+
+Makefile.am:
+lib_SOURCES += strcasestr.h
+
+Include:
+"strcasestr.h"
+
+License:
+LGPL
+
+Maintainer:
+Yoann Vandoorselaere
+
_______________________________________________
bug-gnulib mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-gnulib

Reply via email to