]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Update Gnulib.
authorSimon Josefsson <simon@josefsson.org>
Tue, 5 Oct 2004 19:23:32 +0000 (19:23 +0000)
committerSimon Josefsson <simon@josefsson.org>
Tue, 5 Oct 2004 19:23:32 +0000 (19:23 +0000)
Replace memstr with memmem, see continued discussion on bug-gnulib.

14 files changed:
configure.in
gl/Makefile.am
gl/error.c
gl/getndelim2.c
gl/getpass.c
gl/m4/gnulib.m4
gl/m4/memmem.m4 [moved from gl/m4/memstr.m4 with 60% similarity]
gl/memmem.c [new file with mode: 0644]
gl/memmem.h [moved from gl/memstr.h with 77% similarity]
gl/memstr.c [deleted file]
gl/unlocked-io.h [deleted file]
lib/defines.h
lib/gnutls_x509.c
lib/x509_b64.c

index 3749af47f1fb7bf47c13c18217ea6d8b51ea2cf2..35c1be848f367bb021712d2fa31c80eff2d68964 100644 (file)
@@ -466,7 +466,7 @@ AC_MSG_RESULT([***
 
 gl_SOURCE_BASE(gl)
 gl_M4_BASE(gl/m4)
-gl_MODULES(getline error exit progname getpass-gnu minmax memstr)
+gl_MODULES(getline error exit progname getpass-gnu minmax memmem)
 gl_INIT
 
 AC_MSG_RESULT([***
index 98d95bdab739e9742f4f24397a64a49319db4f8e..799395915eed9c4314b4253578dd095a53b7a0b5 100644 (file)
@@ -10,7 +10,7 @@
 # Generated by gnulib-tool.
 #
 # Invoked as: gnulib-tool --import
-# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --libtool  error exit extensions getline getpass-gnu gettext memstr minmax progname stdbool unlocked-io
+# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --libtool  error exit getline getpass-gnu gettext memmem minmax progname stdbool
 
 AUTOMAKE_OPTIONS = 1.8 gnits
 
@@ -28,7 +28,6 @@ MAINTAINERCLEANFILES =
 
 libgnu_la_SOURCES += exit.h
 
-
 libgnu_la_SOURCES += getline.h
 EXTRA_DIST += getndelim2.h getndelim2.c
 
@@ -36,7 +35,7 @@ libgnu_la_SOURCES += getpass.h
 
 libgnu_la_SOURCES += gettext.h
 
-libgnu_la_SOURCES += memstr.h
+libgnu_la_SOURCES += memmem.h
 
 libgnu_la_SOURCES += minmax.h
 
@@ -53,7 +52,5 @@ stdbool.h: stdbool_.h
        mv $@-t $@
 MOSTLYCLEANFILES += stdbool.h stdbool.h-t
 
-libgnu_la_SOURCES += unlocked-io.h
-
 
 # Makefile.am ends here
index 5a5e126b0dfb1e14d772248a7d29c19f52c4cb81..9bb3e558cb8bc197bced81d4b8278e21c047b8cf 100644 (file)
@@ -40,7 +40,7 @@
 # define mbsrtowcs __mbsrtowcs
 #endif
 
-#if !_LIBC
+#if USE_UNLOCKED_IO
 # include "unlocked-io.h"
 #endif
 
index 9571e50a8f70092f5101992353cfef1b01c86c0e..aef97807a187eaa36f121531b6786656ee151342 100644 (file)
@@ -29,7 +29,9 @@
 #include <stdlib.h>
 #include <stddef.h>
 
-#include "unlocked-io.h"
+#if USE_UNLOCKED_IO
+# include "unlocked-io.h"
+#endif
 
 #include <limits.h>
 #if HAVE_INTTYPES_H
index 9ac01f22776749ffa4ab77f862d850a7d1ebceb8..bc8eb4498d04230145853458b58006f360f08752 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992-2001, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1992-2001, 2003, 2004 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
@@ -55,7 +55,7 @@
 #if _LIBC
 # define flockfile(s) _IO_flockfile (s)
 # define funlockfile(s) _IO_funlockfile (s)
-#else
+#elif USE_UNLOCKED_IO
 # include "unlocked-io.h"
 #endif
 
index 04f0ac84d9a478868610461d7cb45690c88526c7..ad4c5ebef3955476c9e356e67871d5c16c0dfff1 100644 (file)
@@ -8,24 +8,21 @@
 # Generated by gnulib-tool.
 #
 # Invoked as: gnulib-tool --import
-# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --libtool  error exit extensions getline getpass-gnu gettext memstr minmax progname stdbool unlocked-io
+# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --libtool  error exit getline getpass-gnu gettext memmem minmax progname stdbool
 
 AC_DEFUN([gl_EARLY],
 [
   AC_GNU_SOURCE
-  gl_USE_SYSTEM_EXTENSIONS
 ])
 
 AC_DEFUN([gl_INIT],
 [
   gl_ERROR
-  dnl gl_USE_SYSTEM_EXTENSIONS must be added quite early to configure.ac.
   AM_FUNC_GETLINE
   gl_FUNC_GETPASS_GNU
   dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac.
-  gl_FUNC_MEMSTR
+  gl_FUNC_MEMMEM
   AM_STDBOOL_H
-  gl_FUNC_GLIBC_UNLOCKED_IO
 ])
 
 dnl Usage: gl_MODULES(module1 module2 ...)
similarity index 60%
rename from gl/m4/memstr.m4
rename to gl/m4/memmem.m4
index 43414d9ed6f57a1678ad88882ccc3f8afb5b56b7..2e4a20bc3cedec9563f26097eedd25c409176dd4 100644 (file)
@@ -1,4 +1,4 @@
-# memstr.m4 serial 1
+# memmem.m4 serial 1
 dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
@@ -6,12 +6,15 @@ dnl Public License, this file may be distributed as part of a program
 dnl that contains a configuration script generated by Autoconf, under
 dnl the same distribution terms as the rest of that program.
 
-AC_DEFUN([gl_FUNC_MEMSTR],
+AC_DEFUN([gl_FUNC_MEMMEM],
 [
-  AC_REPLACE_FUNCS(memstr)
-  AC_CHECK_DECLS_ONCE(memstr)
-  gl_PREREQ_MEMSTR
+  dnl Persuade glibc <string.h> to declare memmem().
+  AC_REQUIRE([AC_GNU_SOURCE])
+
+  AC_REPLACE_FUNCS(memmem)
+  AC_CHECK_DECLS_ONCE(memmem)
+  gl_PREREQ_MEMMEM
 ])
 
-# Prerequisites of lib/memstr.c.
-AC_DEFUN([gl_PREREQ_MEMSTR], [:])
+# Prerequisites of lib/memmem.c.
+AC_DEFUN([gl_PREREQ_MEMMEM], [:])
diff --git a/gl/memmem.c b/gl/memmem.c
new file mode 100644 (file)
index 0000000..04e384c
--- /dev/null
@@ -0,0 +1,57 @@
+/* Copyright (C) 1991,92,93,94,96,97,98,2000,2004 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
+   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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#include <stddef.h>
+#include <string.h>
+
+#ifndef _LIBC
+# define __builtin_expect(expr, val)   (expr)
+#endif
+
+#undef memmem
+
+/* Return the first occurrence of NEEDLE in HAYSTACK.  */
+void *
+memmem (haystack, haystack_len, needle, needle_len)
+     const void *haystack;
+     size_t haystack_len;
+     const void *needle;
+     size_t needle_len;
+{
+  const char *begin;
+  const char *const last_possible
+    = (const char *) haystack + haystack_len - needle_len;
+
+  if (needle_len == 0)
+    /* The first occurrence of the empty string is deemed to occur at
+       the beginning of the string.  */
+    return (void *) haystack;
+
+  /* Sanity check, otherwise the loop might search through the whole
+     memory.  */
+  if (__builtin_expect (haystack_len < needle_len, 0))
+    return NULL;
+
+  for (begin = (const char *) haystack; begin <= last_possible; ++begin)
+    if (begin[0] == ((const char *) needle)[0] &&
+       !memcmp ((const void *) &begin[1],
+                (const void *) ((const char *) needle + 1),
+                needle_len - 1))
+      return (void *) begin;
+
+  return NULL;
+}
similarity index 77%
rename from gl/memstr.h
rename to gl/memmem.h
index 519036ec053ac36865be32e75509a7b45b4991d2..47dcbd83632fd1c0a149f98fc150b00aff4c81a9 100644 (file)
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  * 02111-1307, USA.  */
 
-#ifndef MEMSTR_H
-# define MEMSTR_H
+#ifndef MEMMEM_H
+# define MEMMEM_H
 
-/* Get memstr, if available. */
+/* Get memmem, if available. */
 # include <string.h>
 
-# if defined HAVE_DECL_MEMSTR && !HAVE_DECL_MEMSTR
-char *memstr (const char *big, const char *little, size_t len);
+# if defined HAVE_DECL_MEMMEM && !HAVE_DECL_MEMMEM
+void *
+memmem (const void *haystack, size_t haystack_len,
+       const void *needle, size_t needle_len);
 # endif
 
-#endif /* MEMSTR_H */
+#endif /* MEMMEM_H */
diff --git a/gl/memstr.c b/gl/memstr.c
deleted file mode 100644 (file)
index 489e38d..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2004 Free Software Foundation
- * Written by Simon Josefsson
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.  */
-
-#if HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-/* Get strlen, strncmp, size_t. */
-#include <string.h>
-
-/* Locate first occurance of zero terminated string LITTLE in the
-   first LEN characters of the string BIG.  The terminating zero in
-   LITTLE is not used for comparison.  Return pointer to match within
-   BIG, or NULL if no match is found.  If LITTLE is the empty string,
-   BIG is returned.  */
-char *
-memstr (const char *big, const char *little, size_t len)
-{
-  size_t littlelen = strlen (little);
-  char *p = (char*) big;
-  size_t i;
-
-  if (*little == '\0')
-    return p;
-
-  if (len < littlelen)
-    return NULL;
-
-  for (i = 0; i <= len - littlelen; i++)
-    if (memcmp (&p[i], little, littlelen) == 0)
-      return &p[i];
-
-  return NULL;
-}
diff --git a/gl/unlocked-io.h b/gl/unlocked-io.h
deleted file mode 100644 (file)
index 36a7a48..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-/* Prefer faster, non-thread-safe stdio functions if available.
-
-   Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
-
-   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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
-
-/* Written by Jim Meyering.  */
-
-#ifndef UNLOCKED_IO_H
-# define UNLOCKED_IO_H 1
-
-# ifndef USE_UNLOCKED_IO
-#  define USE_UNLOCKED_IO 1
-# endif
-
-# if USE_UNLOCKED_IO
-
-/* These are wrappers for functions/macros from the GNU C library, and
-   from other C libraries supporting POSIX's optional thread-safe functions.
-
-   The standard I/O functions are thread-safe.  These *_unlocked ones are
-   more efficient but not thread-safe.  That they're not thread-safe is
-   fine since all of the applications in this package are single threaded.
-
-   Also, some code that is shared with the GNU C library may invoke
-   the *_unlocked functions directly.  On hosts that lack those
-   functions, invoke the non-thread-safe versions instead.  */
-
-#  include <stdio.h>
-
-#  if HAVE_DECL_CLEARERR_UNLOCKED
-#   undef clearerr
-#   define clearerr(x) clearerr_unlocked (x)
-#  else
-#   define clearerr_unlocked(x) clearerr (x)
-#  endif
-#  if HAVE_DECL_FEOF_UNLOCKED
-#   undef feof
-#   define feof(x) feof_unlocked (x)
-#  else
-#   define feof_unlocked(x) feof (x)
-#  endif
-#  if HAVE_DECL_FERROR_UNLOCKED
-#   undef ferror
-#   define ferror(x) ferror_unlocked (x)
-#  else
-#   define ferror_unlocked(x) ferror (x)
-#  endif
-#  if HAVE_DECL_FFLUSH_UNLOCKED
-#   undef fflush
-#   define fflush(x) fflush_unlocked (x)
-#  else
-#   define fflush_unlocked(x) fflush (x)
-#  endif
-#  if HAVE_DECL_FGETS_UNLOCKED
-#   undef fgets
-#   define fgets(x,y,z) fgets_unlocked (x,y,z)
-#  else
-#   define fgets_unlocked(x,y,z) fgets (x,y,z)
-#  endif
-#  if HAVE_DECL_FPUTC_UNLOCKED
-#   undef fputc
-#   define fputc(x,y) fputc_unlocked (x,y)
-#  else
-#   define fputc_unlocked(x,y) fputc (x,y)
-#  endif
-#  if HAVE_DECL_FPUTS_UNLOCKED
-#   undef fputs
-#   define fputs(x,y) fputs_unlocked (x,y)
-#  else
-#   define fputs_unlocked(x,y) fputs (x,y)
-#  endif
-#  if HAVE_DECL_FREAD_UNLOCKED
-#   undef fread
-#   define fread(w,x,y,z) fread_unlocked (w,x,y,z)
-#  else
-#   define fread_unlocked(w,x,y,z) fread (w,x,y,z)
-#  endif
-#  if HAVE_DECL_FWRITE_UNLOCKED
-#   undef fwrite
-#   define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z)
-#  else
-#   define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
-#  endif
-#  if HAVE_DECL_GETC_UNLOCKED
-#   undef getc
-#   define getc(x) getc_unlocked (x)
-#  else
-#   define getc_unlocked(x) getc (x)
-#  endif
-#  if HAVE_DECL_GETCHAR_UNLOCKED
-#   undef getchar
-#   define getchar() getchar_unlocked ()
-#  else
-#   define getchar_unlocked() getchar ()
-#  endif
-#  if HAVE_DECL_PUTC_UNLOCKED
-#   undef putc
-#   define putc(x,y) putc_unlocked (x,y)
-#  else
-#   define putc_unlocked(x,y) putc (x,y)
-#  endif
-#  if HAVE_DECL_PUTCHAR_UNLOCKED
-#   undef putchar
-#   define putchar(x) putchar_unlocked (x)
-#  else
-#   define putchar_unlocked(x) putchar (x)
-#  endif
-
-#  undef flockfile
-#  define flockfile(x) ((void) 0)
-
-#  undef ftrylockfile
-#  define ftrylockfile(x) 0
-
-#  undef funlockfile
-#  define funlockfile(x) ((void) 0)
-
-# endif /* USE_UNLOCKED_IO */
-#endif /* UNLOCKED_IO_H */
index 267fe43cf26841cba899e2b2523b9aa3e865117e..5773b12ab1f73d2d8a015dee11f5ec8d877f1efb 100644 (file)
@@ -40,7 +40,7 @@ typedef int ssize_t;
 # include <strings.h>
 #endif
 
-#include <memstr.h>
+#include <memmem.h>
 
 #ifdef HAVE_STDDEF_H
 # include <stddef.h>
index e5dc7e52293d816b0b79fc0707ad371802210ed5..f5d59e29582ed044e81d78cbfbb2a054ab88d8f3 100644 (file)
@@ -438,8 +438,8 @@ static int parse_pem_cert_mem(gnutls_cert ** cert_list, uint * ncerts,
     int ret, count;
 
 #ifdef ENABLE_PKI
-    if ((ptr =
-        memstr(input_cert, PEM_PKCS7_SEP, input_cert_size)) != NULL) {
+    if ((ptr = memmem(input_cert, input_cert_size,
+                     PEM_PKCS7_SEP, sizeof (PEM_PKCS7_SEP) - 1)) != NULL) {
        size = strlen(ptr);
 
        ret = parse_pkcs7_cert_mem(cert_list, ncerts, ptr, size, CERT_PEM);
@@ -450,9 +450,11 @@ static int parse_pem_cert_mem(gnutls_cert ** cert_list, uint * ncerts,
 
     /* move to the certificate
      */
-    ptr = memstr(input_cert, PEM_CERT_SEP, input_cert_size);
+    ptr = memmem(input_cert, input_cert_size,
+                PEM_CERT_SEP, sizeof (PEM_CERT_SEP) - 1);
     if (ptr == NULL)
-       ptr = memstr(input_cert, PEM_CERT_SEP2, input_cert_size);
+       ptr = memmem(input_cert, input_cert_size,
+                    PEM_CERT_SEP2, sizeof (PEM_CERT_SEP2) - 1);
 
     if (ptr == NULL) {
        gnutls_assert();
@@ -502,9 +504,10 @@ static int parse_pem_cert_mem(gnutls_cert ** cert_list, uint * ncerts,
        if (size > 0) {
            char *ptr2;
 
-           ptr2 = memstr(ptr, PEM_CERT_SEP, size);
+           ptr2 = memmem(ptr, size, PEM_CERT_SEP, sizeof (PEM_CERT_SEP) - 1);
            if (ptr2 == NULL)
-               ptr2 = memstr(ptr, PEM_CERT_SEP2, size);
+               ptr2 = memmem(ptr, size, PEM_CERT_SEP2,
+                             sizeof (PEM_CERT_SEP2) - 1);
 
            ptr = ptr2;
        } else
@@ -1123,9 +1126,11 @@ static int parse_pem_ca_mem(gnutls_x509_crt_t ** cert_list, uint * ncerts,
 
     /* move to the certificate
      */
-    ptr = memstr(input_cert, PEM_CERT_SEP, input_cert_size);
+    ptr = memmem(input_cert, input_cert_size,
+                PEM_CERT_SEP, sizeof (PEM_CERT_SEP) - 1);
     if (ptr == NULL)
-       ptr = memstr(input_cert, PEM_CERT_SEP2, input_cert_size);
+       ptr = memmem(input_cert, input_cert_size,
+                    PEM_CERT_SEP2, sizeof (PEM_CERT_SEP2) - 1);
 
     if (ptr == NULL) {
        gnutls_assert();
@@ -1177,9 +1182,10 @@ static int parse_pem_ca_mem(gnutls_x509_crt_t ** cert_list, uint * ncerts,
        if (size > 0) {
            char *ptr2;
 
-           ptr2 = memstr(ptr, PEM_CERT_SEP, size);
+           ptr2 = memmem(ptr, size, PEM_CERT_SEP, sizeof (PEM_CERT_SEP) - 1);
            if (ptr2 == NULL)
-               ptr = memstr(ptr, PEM_CERT_SEP2, size);
+               ptr = memmem(ptr, size,
+                            PEM_CERT_SEP2, sizeof (PEM_CERT_SEP2) - 1);
 
            ptr = ptr2;
        } else
@@ -1395,7 +1401,8 @@ static int parse_pem_crl_mem(gnutls_x509_crl_t ** crl_list, uint * ncrls,
 
     /* move to the certificate
      */
-    ptr = memstr(input_crl, PEM_CRL_SEP, input_crl_size);
+    ptr = memmem(input_crl, input_crl_size,
+                PEM_CRL_SEP, sizeof (PEM_CRL_SEP) -1);
     if (ptr == NULL) {
        gnutls_assert();
        return GNUTLS_E_BASE64_DECODING_ERROR;
@@ -1445,7 +1452,7 @@ static int parse_pem_crl_mem(gnutls_x509_crl_t ** crl_list, uint * ncrls,
        size = input_crl_size - (ptr - input_crl);
 
        if (size > 0)
-           ptr = memstr(ptr, PEM_CRL_SEP, size);
+           ptr = memmem(ptr, size, PEM_CRL_SEP, sizeof (PEM_CRL_SEP) - 1);
        else
            ptr = NULL;
        i++;
index 3a5f06140f18c0f7a69454d14d6204280c9d265a..2c20602391447ac3fc841a1900d71c631a2ca1cb 100644 (file)
@@ -413,7 +413,7 @@ int _gnutls_fbase64_decode(const char *header, const opaque * data,
     if (header != NULL)
        _gnutls_str_cat(pem_header, sizeof(pem_header), header);
 
-    rdata = memstr(data, pem_header, data_size);
+    rdata = memmem(data, data_size, pem_header, strlen (pem_header));
 
     if (rdata == NULL) {
        gnutls_assert();
@@ -428,11 +428,11 @@ int _gnutls_fbase64_decode(const char *header, const opaque * data,
        return GNUTLS_E_BASE64_DECODING_ERROR;
     }
 
-    kdata = memstr(rdata, ENDSTR, data_size);
+    kdata = memmem(rdata, data_size, ENDSTR, sizeof (ENDSTR) - 1);
     /* allow CR as well.
      */
     if (kdata == NULL)
-       kdata = memstr(rdata, ENDSTR2, data_size);
+       kdata = memmem(rdata, data_size, ENDSTR2, sizeof (ENDSTR2) - 1);
 
     if (kdata == NULL) {
        gnutls_assert();
@@ -446,7 +446,7 @@ int _gnutls_fbase64_decode(const char *header, const opaque * data,
 
     /* position is now after the ---BEGIN--- headers */
 
-    kdata = memstr(rdata, bottom, data_size);
+    kdata = memmem(rdata, data_size, bottom, strlen (bottom));
     if (kdata == NULL) {
        gnutls_assert();
        return GNUTLS_E_BASE64_DECODING_ERROR;