Le vendredi 26 janvier 2007 à 00:03 -0800, Paul Eggert a écrit :
> I'd like to add a 'string' module to gnulib, which does for <string.h>
> what the sys_time module does for <sys/time.h>, namely, sets up a
> substitute string.h that has needed GNU declarations. That way,
> we don't need to worry about the little include files like "strstr.h"
> which make the rest of the code harder to read and maintain.
Attached is a patch for the strcasestr module to use generated string.h.
--
Yoann Vandoorselaere | Responsable R&D / CTO | PreludeIDS Technologies
Tel: +33 (0)8 70 70 21 58 Fax: +33(0)4 78 42 21 58
http://www.prelude-ids.com
Index: lib/string_.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/string_.h,v
retrieving revision 1.1
diff -u -r1.1 string_.h
--- lib/string_.h 26 Jan 2007 22:16:55 -0000 1.1
+++ lib/string_.h 27 Jan 2007 09:52:03 -0000
@@ -137,6 +137,16 @@
char *strstr (char const *__haystack, char const *__needle);
#endif
+/* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
+ comparison.
+ Note: This function may, in multibyte locales, return success even if
+ strlen (haystack) < strlen (needle) ! */
+#if @REPLACE_STRCASESTR
+# undef strcasestr
+# define strcasestr rpl_strcasestr
+extern char *strcasestr (const char *haystack, const char *needle);
+#endif
+
/* Parse S into tokens separated by characters in DELIM.
If S is NULL, the saved pointer in SAVE_PTR is used as
the next starting point. For example:
Index: m4/strcasestr.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/strcasestr.m4,v
retrieving revision 1.2
diff -u -r1.2 strcasestr.m4
--- m4/strcasestr.m4 26 Sep 2005 13:58:51 -0000 1.2
+++ m4/strcasestr.m4 27 Jan 2007 09:52:03 -0000
@@ -1,4 +1,4 @@
-# strcasestr.m4 serial 2
+# strcasestr.m4 serial 3
dnl Copyright (C) 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,
@@ -9,8 +9,8 @@
dnl No known system has a strcasestr() function that works correctly in
dnl multibyte locales. Therefore we use our version always.
AC_LIBOBJ(strcasestr)
- AC_DEFINE(strcasestr, rpl_strcasestr, [Define to rpl_strcasestr always.])
gl_PREREQ_STRCASESTR
+ REPLACE_STRCASESTR=1
])
# Prerequisites of lib/strcasestr.c.
Index: modules/strcasestr
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/strcasestr,v
retrieving revision 1.3
diff -u -r1.3 strcasestr
--- modules/strcasestr 13 Oct 2006 12:40:23 -0000 1.3
+++ modules/strcasestr 27 Jan 2007 09:52:03 -0000
@@ -2,7 +2,6 @@
strcasestr() function: case-insensitive search for a substring in a string.
Files:
-lib/strcasestr.h
lib/strcasestr.c
m4/strcasestr.m4
m4/mbrtowc.m4
@@ -16,7 +15,7 @@
Makefile.am:
Include:
-"strcasestr.h"
+<string.h>
License:
LGPL