summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Josefsson <simon@josefsson.org>2008-01-08 10:18:23 +0100
committerSimon Josefsson <simon@josefsson.org>2008-01-08 10:18:23 +0100
commite879d4afc438e598d36c434121e786accd9bd452 (patch)
treef0bebfbbfaf7059e19c9cde1d475d3d22f34d928
parent198d6ec43af89846637b583995cdee0696d0da55 (diff)
downloadgnutls-e879d4afc438e598d36c434121e786accd9bd452.tar.gz
Update gnulib files.
-rw-r--r--NEWS2
-rw-r--r--gl/progname.c10
-rw-r--r--lgl/m4/memmem.m429
-rw-r--r--lgl/memmem.c40
4 files changed, 53 insertions, 28 deletions
diff --git a/NEWS b/NEWS
index 4fb76c637f..5cca31f255 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,8 @@ in a callback friendly way.
** Updated translations.
+** Update gnulib files.
+
** API and ABI modifications:
No changes since last version.
diff --git a/gl/progname.c b/gl/progname.c
index 47d08c65d5..2b77a5883c 100644
--- a/gl/progname.c
+++ b/gl/progname.c
@@ -1,5 +1,5 @@
/* Program name management.
- Copyright (C) 2001-2003, 2005-2007 Free Software Foundation, Inc.
+ Copyright (C) 2001-2003, 2005-2008 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
This program is free software: you can redistribute it and/or modify
@@ -42,8 +42,10 @@ set_program_name (const char *argv0)
slash = strrchr (argv0, '/');
base = (slash != NULL ? slash + 1 : argv0);
if (base - argv0 >= 7 && strncmp (base - 7, "/.libs/", 7) == 0)
- argv0 = base;
- if (strncmp (base, "lt-", 3) == 0)
- argv0 = base + 3;
+ {
+ argv0 = base;
+ if (strncmp (base, "lt-", 3) == 0)
+ argv0 = base + 3;
+ }
program_name = argv0;
}
diff --git a/lgl/m4/memmem.m4 b/lgl/m4/memmem.m4
index a529af3bec..9767354ad2 100644
--- a/lgl/m4/memmem.m4
+++ b/lgl/m4/memmem.m4
@@ -1,5 +1,5 @@
-# memmem.m4 serial 6
-dnl Copyright (C) 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
+# memmem.m4 serial 7
+dnl Copyright (C) 2002, 2003, 2004, 2007, 2008 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.
@@ -15,9 +15,28 @@ AC_DEFUN([gl_FUNC_MEMMEM],
if test $ac_cv_have_decl_memmem = no; then
HAVE_DECL_MEMMEM=0
else
- AC_CACHE_CHECK([whether memmem works], [gl_cv_func_memmem_works],
- [AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <string.h>],
- [return !memmem ("a", 1, NULL, 0);])],
+ AC_CACHE_CHECK([whether memmem works in linear time],
+ [gl_cv_func_memmem_works],
+ [AC_RUN_IFELSE([AC_LANG_PROGRAM([
+#include <string.h> /* for memmem */
+#include <stdlib.h> /* for malloc */
+#include <unistd.h> /* for alarm */
+], [[size_t m = 1000000;
+ char *haystack = (char *) malloc (2 * m + 1);
+ char *needle = (char *) malloc (m + 1);
+ void *result = 0;
+ /* Failure to compile this test due to missing alarm is okay,
+ since all such platforms (mingw) also lack memmem. */
+ alarm (5);
+ if (haystack && needle)
+ {
+ memset (haystack, 'A', 2 * m);
+ haystack[2 * m] = 'B';
+ memset (needle, 'A', m);
+ needle[m] = 'B';
+ result = memmem (haystack, 2 * m + 1, needle, m + 1);
+ }
+ return !result || !memmem ("a", 1, 0, 0);]])],
[gl_cv_func_memmem_works=yes], [gl_cv_func_memmem_works=no],
[dnl pessimistically assume the worst, since even glibc 2.6.1
dnl has quadratic complexity in its memmem
diff --git a/lgl/memmem.c b/lgl/memmem.c
index def0fa7454..1196b3e200 100644
--- a/lgl/memmem.c
+++ b/lgl/memmem.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,92,93,94,96,97,98,2000,2004,2007 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92,93,94,96,97,98,2000,2004,2007,2008 Free Software Foundation, Inc.
This file is part of the GNU C Library.
This program is free software; you can redistribute it and/or modify
@@ -34,9 +34,10 @@
Return a boolean indicating success. */
static bool
-knuth_morris_pratt (const char *haystack, const char *last_haystack,
- const char *needle, size_t m,
- const char **resultp)
+knuth_morris_pratt (const unsigned char *haystack,
+ const unsigned char *last_haystack,
+ const unsigned char *needle, size_t m,
+ const unsigned char **resultp)
{
/* Allocate the table. */
size_t *table = (size_t *) nmalloca (m, sizeof (size_t));
@@ -70,14 +71,14 @@ knuth_morris_pratt (const char *haystack, const char *last_haystack,
The inequality needle[x..i-1] != needle[0..i-1-x] is known to hold
for x < table[i-1], by induction.
Furthermore, if j>0: needle[i-1-j..i-2] = needle[0..j-1]. */
- unsigned char b = (unsigned char) needle[i - 1];
+ unsigned char b = needle[i - 1];
for (;;)
{
/* Invariants: The inequality needle[x..i-1] != needle[0..i-1-x]
is known to hold for x < i-1-j.
Furthermore, if j>0: needle[i-1-j..i-2] = needle[0..j-1]. */
- if (b == (unsigned char) needle[j])
+ if (b == needle[j])
{
/* Set table[i] := i-1-j. */
table[i] = i - ++j;
@@ -112,8 +113,8 @@ knuth_morris_pratt (const char *haystack, const char *last_haystack,
/* Search, using the table to accelerate the processing. */
{
size_t j;
- const char *rhaystack;
- const char *phaystack;
+ const unsigned char *rhaystack;
+ const unsigned char *phaystack;
*resultp = NULL;
j = 0;
@@ -121,7 +122,7 @@ knuth_morris_pratt (const char *haystack, const char *last_haystack,
phaystack = haystack;
/* Invariant: phaystack = rhaystack + j. */
while (phaystack != last_haystack)
- if ((unsigned char) needle[j] == (unsigned char) *phaystack)
+ if (needle[j] == *phaystack)
{
j++;
phaystack++;
@@ -157,11 +158,12 @@ void *
memmem (const void *haystack_start, size_t haystack_len,
const void *needle_start, size_t needle_len)
{
- /* Operating with void * is awkward. */
- const char *haystack = (const char *) haystack_start;
- const char *needle = (const char *) needle_start;
- const char *last_haystack = haystack + haystack_len;
- const char *last_needle = needle + needle_len;
+ /* Abstract memory is considered to be an array of 'unsigned char' values,
+ not an array of 'char' values. See ISO C 99 section 6.2.6.1. */
+ const unsigned char *haystack = (const unsigned char *) haystack_start;
+ const unsigned char *needle = (const unsigned char *) needle_start;
+ const unsigned char *last_haystack = haystack + haystack_len;
+ const unsigned char *last_needle = needle + needle_len;
if (needle_len == 0)
/* The first occurrence of the empty string is deemed to occur at
@@ -175,7 +177,7 @@ memmem (const void *haystack_start, size_t haystack_len,
/* Use optimizations in memchr when possible. */
if (__builtin_expect (needle_len == 1, 0))
- return memchr (haystack, (unsigned char) *needle, haystack_len);
+ return memchr (haystack, *needle, haystack_len);
/* Minimizing the worst-case complexity:
Let n = haystack_len, m = needle_len.
@@ -198,7 +200,7 @@ memmem (const void *haystack_start, size_t haystack_len,
/* Speed up the following searches of needle by caching its first
byte. */
- char b = *needle++;
+ unsigned char b = *needle++;
for (;; haystack++)
{
@@ -217,7 +219,7 @@ memmem (const void *haystack_start, size_t haystack_len,
if (comparison_count >= needle_len)
{
/* Try the Knuth-Morris-Pratt algorithm. */
- const char *result;
+ const unsigned char *result;
if (knuth_morris_pratt (haystack, last_haystack,
needle - 1, needle_len, &result))
return (void *) result;
@@ -230,8 +232,8 @@ memmem (const void *haystack_start, size_t haystack_len,
if (*haystack == b)
/* The first byte matches. */
{
- const char *rhaystack = haystack + 1;
- const char *rneedle = needle;
+ const unsigned char *rhaystack = haystack + 1;
+ const unsigned char *rneedle = needle;
for (;; rhaystack++, rneedle++)
{