summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Josefsson <simon@josefsson.org>2004-09-29 17:46:55 +0000
committerSimon Josefsson <simon@josefsson.org>2004-09-29 17:46:55 +0000
commit12f5c586707fb11c658da5910ebfcf8cc318c8db (patch)
tree7e75ecd3eb63e56e4dc431fc3b2d223608f1f8d5
parentd1a3baa9f76377d74530c096ad8799b6866e6bbf (diff)
downloadgnutls-12f5c586707fb11c658da5910ebfcf8cc318c8db.tar.gz
Use strnstr from gnulib.
Gnulib sync.
-rw-r--r--configure.in4
-rw-r--r--gl/Makefile.am4
-rw-r--r--gl/m4/gnulib.m49
-rw-r--r--gl/m4/strnstr.m417
-rw-r--r--gl/minmax.h66
-rw-r--r--gl/progname.c15
-rw-r--r--gl/progname.h6
-rw-r--r--gl/strnstr.c53
-rw-r--r--gl/strnstr.h30
-rw-r--r--lib/Makefile.am2
-rw-r--r--lib/defines.h8
-rw-r--r--lib/strnstr.c50
12 files changed, 181 insertions, 83 deletions
diff --git a/configure.in b/configure.in
index 4b67880339..8c505e833e 100644
--- a/configure.in
+++ b/configure.in
@@ -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([***
diff --git a/gl/Makefile.am b/gl/Makefile.am
index f59ed59af8..0c5793d877 100644
--- a/gl/Makefile.am
+++ b/gl/Makefile.am
@@ -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
diff --git a/gl/m4/gnulib.m4 b/gl/m4/gnulib.m4
index fe1625e28a..aadeed19d9 100644
--- a/gl/m4/gnulib.m4
+++ b/gl/m4/gnulib.m4
@@ -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
index 0000000000..593736d473
--- /dev/null
+++ b/gl/m4/strnstr.m4
@@ -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], [:])
diff --git a/gl/minmax.h b/gl/minmax.h
index c2a2c61812..0e505109e7 100644
--- a/gl/minmax.h
+++ b/gl/minmax.h
@@ -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 */
diff --git a/gl/progname.c b/gl/progname.c
index 8453706c93..84989fd0cc 100644
--- a/gl/progname.c
+++ b/gl/progname.c
@@ -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;
+}
diff --git a/gl/progname.h b/gl/progname.h
index 5292cd1bfd..6b990654f7 100644
--- a/gl/progname.h
+++ b/gl/progname.h
@@ -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
index 0000000000..9989b9f9d3
--- /dev/null
+++ b/gl/strnstr.c
@@ -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
index 0000000000..b2bb4867f7
--- /dev/null
+++ b/gl/strnstr.h
@@ -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 */
diff --git a/lib/Makefile.am b/lib/Makefile.am
index f9f6682b3c..c5eb326918 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -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 \
diff --git a/lib/defines.h b/lib/defines.h
index 9f6ec12aa9..808f08363b 100644
--- a/lib/defines.h
+++ b/lib/defines.h
@@ -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
index d664384ee7..0000000000
--- a/lib/strnstr.c
+++ /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