]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Use strnstr from gnulib.
authorSimon Josefsson <simon@josefsson.org>
Wed, 29 Sep 2004 17:46:55 +0000 (17:46 +0000)
committerSimon Josefsson <simon@josefsson.org>
Wed, 29 Sep 2004 17:46:55 +0000 (17:46 +0000)
Gnulib sync.

12 files changed:
configure.in
gl/Makefile.am
gl/m4/gnulib.m4
gl/m4/strnstr.m4 [new file with mode: 0644]
gl/minmax.h
gl/progname.c
gl/progname.h
gl/strnstr.c [new file with mode: 0644]
gl/strnstr.h [new file with mode: 0644]
lib/Makefile.am
lib/defines.h
lib/strnstr.c [deleted file]

index 4b67880339df24c981ef9e5dc7151b4208234488..8c505e833e07ff5ffae6f3b3cad2e7f535e978ef 100644 (file)
@@ -163,7 +163,7 @@ AC_CHECK_HEADERS(errno.h sys/time.h time.h)
 AC_CHECK_HEADERS(math.h limits.h float.h stdarg.h ctype.h)
 dnl opencdk
 AC_CHECK_HEADERS(netdb.h)
-AC_CHECK_FUNCS(vasprintf isascii memmove strnstr mmap gmtime_r inet_ntop,,)
+AC_CHECK_FUNCS(vasprintf isascii memmove mmap gmtime_r inet_ntop,,)
 AC_FUNC_ALLOCA
 
 
@@ -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)
+gl_MODULES(getline error exit progname getpass-gnu minmax strnstr)
 gl_INIT
 
 AC_MSG_RESULT([***
index f59ed59af8981e9d86f2507501cfc23f74ac04af..0c5793d877e8d4355e9a6bbbc1c137dc8585fab1 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 minmax progname stdbool unlocked-io
+# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --libtool  error exit extensions getline getpass-gnu gettext minmax progname stdbool strnstr unlocked-io
 
 AUTOMAKE_OPTIONS = 1.8 gnits
 
@@ -51,6 +51,8 @@ stdbool.h: stdbool_.h
        mv $@-t $@
 MOSTLYCLEANFILES += stdbool.h stdbool.h-t
 
+libgnu_la_SOURCES += strnstr.h
+
 libgnu_la_SOURCES += unlocked-io.h
 
 
index fe1625e28af1a73ef6be7a2d7f6427f0516a181c..aadeed19d9518c2b83f2f9ab48d3acc1806b5406 100644 (file)
@@ -8,7 +8,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 minmax progname stdbool unlocked-io
+# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --libtool  error exit extensions getline getpass-gnu gettext minmax progname stdbool strnstr unlocked-io
 
 AC_DEFUN([gl_EARLY],
 [
@@ -24,6 +24,7 @@ AC_DEFUN([gl_INIT],
   gl_FUNC_GETPASS_GNU
   dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac.
   AM_STDBOOL_H
+  gl_FUNC_STRNSTR
   gl_FUNC_GLIBC_UNLOCKED_IO
 ])
 
@@ -36,4 +37,10 @@ AC_DEFUN([gl_SOURCE_BASE], [])
 dnl Usage: gl_M4_BASE(DIR)
 AC_DEFUN([gl_M4_BASE], [])
 
+dnl Usage: gl_LIB(LIBNAME)
+AC_DEFUN([gl_LIB], [])
+
+dnl Usage: gl_LGPL
+AC_DEFUN([gl_LGPL], [])
+
 # gnulib.m4 ends here
diff --git a/gl/m4/strnstr.m4 b/gl/m4/strnstr.m4
new file mode 100644 (file)
index 0000000..593736d
--- /dev/null
@@ -0,0 +1,17 @@
+# strnstr.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
+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_STRNSTR],
+[
+  AC_REPLACE_FUNCS(strnstr)
+  AC_CHECK_DECLS_ONCE(strnstr)
+  gl_PREREQ_STRNSTR
+])
+
+# Prerequisites of lib/strnstr.c.
+AC_DEFUN([gl_PREREQ_STRNSTR], [:])
index c2a2c61812bef2d0f7fac5bec68800005059c5ac..0e505109e745d24277d7a50a34efa63c5a1afa3a 100644 (file)
@@ -1,31 +1,53 @@
-/* Copyright (C) 2004 Simon Josefsson
-   Copyright (C) 1995,1996,1997,2000,2001,2003 Free Software Foundation, Inc.
+/* MIN, MAX macros.
+   Copyright (C) 1995, 1998, 2001, 2003 Free Software Foundation, Inc.
 
-   This file is free software; you can redistribute it and/or modify
-   it under the terms of the GNU Lesser General Public License as
-   published by the Free Software Foundation; either version 2.1 of
-   the License, or (at your option) any later version.
+   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 file 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
-   Lesser General Public License for more details.
+   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 Lesser General Public
-   License along with this file; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-   USA.  */
+   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.  */
 
-#ifndef MINMAX_H
-# define MINMAX_H
+#ifndef _MINMAX_H
+#define _MINMAX_H
 
-/* Macros for min/max.  */
-#ifndef MIN
-# define MIN(a,b) (((a)<(b))?(a):(b))
-#endif
+/* Note: MIN, MAX are also defined in <sys/param.h> on some systems
+   (glibc, IRIX, HP-UX, OSF/1).  Therefore you might get warnings about
+   MIN, MAX macro redefinitions on some systems; the workaround is to
+   #include this file as the last one among the #include list.  */
+
+/* Before we define the following symbols we get the <limits.h> file
+   since otherwise we get redefinitions on some systems.  */
+#include <limits.h>
+
+/* Note: MIN and MAX should be used with two arguments of the
+   same type.  They might not return the minimum and maximum of their two
+   arguments, if the arguments have different types or have unusual
+   floating-point values.  For example, on a typical host with 32-bit 'int',
+   64-bit 'long long', and 64-bit IEEE 754 'double' types:
+
+     MAX (-1, 2147483648) returns 4294967295.
+     MAX (9007199254740992.0, 9007199254740993) returns 9007199254740992.0.
+     MAX (NaN, 0.0) returns 0.0.
+     MAX (+0.0, -0.0) returns -0.0.
 
+   and in each case the answer is in some sense bogus.  */
+
+/* MAX(a,b) returns the maximum of A and B.  */
 #ifndef MAX
-# define MAX(a,b) (((a)>(b))?(a):(b))
+# define MAX(a,b) ((a) > (b) ? (a) : (b))
+#endif
+
+/* MIN(a,b) returns the minimum of A and B.  */
+#ifndef MIN
+# define MIN(a,b) ((a) < (b) ? (a) : (b))
 #endif
 
-#endif /* MINMAX_H */
+#endif /* _MINMAX_H */
index 8453706c9341051b1a397bb55b3976064469c3c7..84989fd0cc00b6f8ea9db43041dc02f433fa9519 100644 (file)
@@ -1,5 +1,5 @@
 /* Program name management.
-   Copyright (C) 2001-2003 Free Software Foundation, Inc.
+   Copyright (C) 2001-2004 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
@@ -51,3 +51,16 @@ set_program_name (const char *argv0)
     argv0 = base + 3;
   program_name = argv0;
 }
+
+/* Return short program name of the current executable, based on the
+   earlier call to set_program_name.  Return NULL if unknown.  The
+   short program name is computed by removing all directory names and
+   path separators. */
+const char *
+get_short_program_name (void)
+{
+  const char *slash = NULL;
+  if (program_name)
+    slash = strrchr (program_name, '/');
+  return slash != NULL ? slash + 1 : program_name;
+}
index 5292cd1bfd387a2f049e7315dc5b285d2cb7737a..6b990654f77d40a99e4ae3df0386db424f4c9c70 100644 (file)
@@ -35,6 +35,12 @@ extern const char *program_name;
 /* Set program_name, based on argv[0].  */
 extern void set_program_name (const char *argv0);
 
+/* Return short program name of the current executable, based on the
+   earlier call to set_program_name.  Return NULL if unknown.  The
+   short program name is computed by removing all directory names and
+   path separators. */
+extern const char *get_short_program_name (void);
+
 #if ENABLE_RELOCATABLE
 
 /* Set program_name, based on argv[0], and original installation prefix and
diff --git a/gl/strnstr.c b/gl/strnstr.c
new file mode 100644 (file)
index 0000000..9989b9f
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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 MIN. */
+#include <minmax.h>
+
+/* Get strlen, strncmp. */
+#include <string.h>
+
+/* Locate first occurance of zero terminated string LITLE in the first
+   MIN(LEN, strlen(BIG)) characters of the string BIG.  Returns
+   pointer to match within BIG, or NULL if no match is found.  If
+   LITTLE is the empty string, BIG is returned.  */
+char *
+strnstr (const char *big, const char *little, size_t len)
+{
+  size_t searchlen = MIN (len, strlen (big));
+  size_t littlelen = strlen (little);
+  char *p = (char*) big;
+  size_t i;
+
+  if (*little == '\0')
+    return p;
+
+  if (searchlen < littlelen)
+    return NULL;
+
+  for (i = 0; i <= searchlen - littlelen; i++)
+    if (strncmp (&p[i], little, littlelen) == 0)
+      return &p[i];
+
+  return NULL;
+}
diff --git a/gl/strnstr.h b/gl/strnstr.h
new file mode 100644 (file)
index 0000000..b2bb486
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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.  */
+
+#ifndef STRNSTR_H
+# define STRNSTR_H
+
+/* Get strnstr, if available. */
+# include <string.h>
+
+# if defined HAVE_DECL_STRNSTR && !HAVE_DECL_STRNSTR
+char *strnstr (const char *big, const char *little, size_t len);
+# endif
+
+#endif /* STRNSTR_H */
index f9f6682b3c03f0e138ec6ec3a0babbb1a9dfc131..c5eb326918d6cf0044560b6a2d3a24040bdf90fa 100644 (file)
@@ -48,7 +48,7 @@ COBJECTS = gnutls_record.c gnutls_compress.c debug.c gnutls_cipher.c  \
        ext_max_record.c gnutls_alert.c gnutls_int_compat.c             \
        gnutls_str.c gnutls_state.c gnutls_x509.c ext_cert_type.c       \
        gnutls_rsa_export.c auth_rsa_export.c ext_server_name.c         \
-       auth_dh_common.c strnstr.c
+       auth_dh_common.c
 
 HFILES = debug.h gnutls_compress.h defines.h gnutls_cipher.h           \
        gnutls_buffers.h gnutls_errors.h gnutls_int.h                   \
index 9f6ec12aa93f98c57dfdbf3d6b0c461ae24b5d25..808f08363b451229cd346a4f13bdac57b1d0e8c5 100644 (file)
@@ -1,5 +1,6 @@
 /*
- *      Copyright (C) 2000,2001,2002 Nikos Mavroyanopoulos
+ * Copyright (C) 2004 Free Software Foundation
+ * Copyright (C) 2000,2001,2002 Nikos Mavroyanopoulos
  *
  * This file is part of GNUTLS.
  *
@@ -39,10 +40,7 @@ typedef int ssize_t;
 # include <strings.h>
 #endif
 
-#ifndef HAVE_STRNSTR
-char *strnstr(const char *haystack, const char *needle,
-             size_t haystacklen);
-#endif
+#include <strnstr.h>
 
 #ifdef HAVE_STDDEF_H
 # include <stddef.h>
diff --git a/lib/strnstr.c b/lib/strnstr.c
deleted file mode 100644 (file)
index d664384..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- *  Copyright (C) 2003 Nikos Mavroyanopoulos
- *  Copyright (C) 2004 Free Software Foundation
- *
- *  This file is part of GNUTLS.
- *
- *  The GNUTLS library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public   
- *  License as published by the Free Software Foundation; either 
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This library 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
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
- *
- */
-
-#include <defines.h>
-#ifndef HAVE_STRNSTR
-# include <string.h>
-
-char *strnstr(const char *haystack, const char *needle, size_t haystacklen)
-{
-    char *p;
-    ssize_t plen;
-    ssize_t len = strlen(needle);
-
-    if (*needle == '\0')       /* everything matches empty string */
-       return (char *) haystack;
-
-    plen = haystacklen;
-    for (p = (char *) haystack; p != NULL;
-        p = memchr(p + 1, *needle, plen - 1)) {
-       plen = haystacklen - (p - haystack);
-
-       if (plen < len)
-           return NULL;
-
-       if (strncmp(p, needle, len) == 0)
-           return (p);
-    }
-    return NULL;
-}
-
-#endif