+2004-04-08 Gary V. Vaughan <gary@gnu.org>
+
+ Factor out the bottom portability layer from ltdl. Code in this
+ layer has global symbols renamed by lt__pre89.h, and may not
+ refer to any symbols except those provided by the system libraries
+ or other code in the portability layer:
+
+ * libltdl/lt__pre89.h: New file. Rename all the symbols from
+ LTLIBOBJS into the lt__ namespace so that they don't clash with
+ other libraries.
+ * libltdl/ltdl.c (rpl_memcpy, rpl_memmove, rpl_strchr, rpl_strcmp)
+ (rpl_strrchr): Moved from here...
+ * libltdl/memcpy.c (memcpy): ...to here, and fixed void *
+ dereference bug...
+ * libltdl/memmove.c (memmove): ...to here, and fixed void *
+ dereference bug...
+ * libltdl/strchr.c (strchr): ...to here...
+ * libltdl/strcmp.c (strcmp): ...here...
+ * libltdl/strrchr.c (strrchr): ...and here.
+ * libltdl/Makefile.am (libltdl_la_SOURCES): Add lt__pre89.h.
+ (libltdl_la_LIBADD, libltdlc_la_LIBADD): Add $(LTLIBOBJS).
+ (ltdldata_DATA): Add replacement sources files.
+ * m4/ltdl.m4 (AC_LIB_LTDL): Do careful config.h and LTLIBOBJ
+ setting for missing pre89 functions.
+
2004-04-08 Gary V. Vaughan <gary@gnu.org>
* libltdl/ltdl.h (LT_PARAMS): Removed. Changed all users to
## default.
CLEANFILES = libltdl.la libltdlc.la
-libltdl_la_SOURCES = lt__alloc.c lt__alloc.h lt_system.h ltdl.c ltdl.h
+libltdl_la_SOURCES = lt__alloc.c lt__alloc.h lt__pre89.h lt_system.h \
+ ltdl.c ltdl.h
libltdl_la_LDFLAGS = -no-undefined -version-info 5:0:2
-libltdl_la_LIBADD = $(LIBADD_DL)
+libltdl_la_LIBADD = $(LIBADD_DL) $(LTLIBOBJS)
libltdlc_la_SOURCES = $(libltdl_la_SOURCES)
-libltdlc_la_LIBADD = $(LIBADD_DL)
+libltdlc_la_LIBADD = $(LIBADD_DL) $(LTLIBOBJS)
## These are installed as a subdirectory of pkgdatadir so that
## libtoolize --ltdl can find them later:
ltdldatadir = $(pkgdatadir)/libltdl
-ltdldata_DATA = COPYING.LIB Makefile.am README $(libltdl_la_SOURCES)
+ltdldata_DATA = COPYING.LIB Makefile.am README $(libltdl_la_SOURCES) \
+ memcpy.c memmove.c strchr.c strcmp.c strrchr.c
#include "ltdl.h"
#include "lt__alloc.h"
+#include "lt__pre89.h"
#if defined(HAVE_CLOSEDIR) && defined(HAVE_OPENDIR) && defined(HAVE_READDIR) && defined(HAVE_DIRENT_H)
/* We have a fully operational dirent subsystem. */
-\f
-/* --- REPLACEMENT FUNCTIONS --- */
-
-
-#if ! HAVE_STRCMP
-
-#undef strcmp
-#define strcmp rpl_strcmp
-
-static int
-strcmp (const char *str1, const char *str2)
-{
- if (str1 == str2)
- return 0;
- if (str1 == 0)
- return -1;
- if (str2 == 0)
- return 1;
-
- for (;*str1 && *str2; ++str1, ++str2)
- {
- if (*str1 != *str2)
- break;
- }
-
- return (int)(*str1 - *str2);
-}
-#endif
-
-
-#if ! HAVE_STRCHR
-
-# if HAVE_INDEX
-# define strchr index
-# else
-# define strchr rpl_strchr
-
-static const char *
-strchr (const char *str, int ch)
-{
- const char *p;
-
- for (p = str; *p != (char)ch && *p != LT_EOS_CHAR; ++p)
- /*NOWORK*/;
-
- return (*p == (char)ch) ? p : 0;
-}
-
-# endif
-#endif /* !HAVE_STRCHR */
-
-
-#if ! HAVE_STRRCHR
-
-# if HAVE_RINDEX
-# define strrchr rindex
-# else
-# define strrchr rpl_strrchr
-
-static const char *
-strrchr (const char *str, int ch)
-{
- const char *p, *q = 0;
-
- for (p = str; *p != LT_EOS_CHAR; ++p)
- {
- if (*p == (char) ch)
- {
- q = p;
- }
- }
-
- return q;
-}
-
-# endif
-#endif
-
-/* NOTE: Neither bcopy nor the memcpy implementation below can
- reliably handle copying in overlapping areas of memory. Use
- memmove (for which there is a fallback implmentation below)
- if you need that behaviour. */
-#if ! HAVE_MEMCPY
-
-# if HAVE_BCOPY
-# define memcpy(dest, src, size) bcopy (src, dest, size)
-# else
-# define memcpy rpl_memcpy
-
-static void *
-memcpy (void *dest, const void *src, size_t size)
-{
- size_t i = 0;
-
- for (i = 0; i < size; ++i)
- {
- dest[i] = src[i];
- }
-
- return dest;
-}
-
-# endif /* !HAVE_BCOPY */
-#endif /* !HAVE_MEMCPY */
-
-#if ! HAVE_MEMMOVE
-# define memmove rpl_memmove
-
-static void *
-memmove (void *dest, const void *src, size_t size)
-{
- size_t i;
-
- if (dest < src)
- for (i = 0; i < size; ++i)
- {
- dest[i] = src[i];
- }
- else if (dest > src)
- for (i = size -1; i >= 0; --i)
- {
- dest[i] = src[i];
- }
-
- return dest;
-}
-
-#endif /* !HAVE_MEMMOVE */
# if LT_USE_WINDOWS_DIRENT_EMULATION
[], [], [AC_INCLUDES_DEFAULT])
AC_CHECK_HEADERS([string.h strings.h], [break], [], [AC_INCLUDES_DEFAULT])
-AC_CHECK_FUNCS([strchr index], [break])
-AC_CHECK_FUNCS([strrchr rindex], [break])
-AC_CHECK_FUNCS([memcpy bcopy], [break])
-AC_CHECK_FUNCS([memmove strcmp])
+AC_FOREACH([LTDL_Func], [strchr index strrchr rindex memcpy bcopy],
+ [AH_TEMPLATE(AS_TR_CPP(HAVE_[]LTDL_Func),
+ [Define to 1 if you have the `]LTDL_Func[' function.])])
+
+AC_CHECK_FUNC([strchr], [AC_DEFINE([HAVE_STRCHR])],
+ [AC_CHECK_FUNC([index], [AC_DEFINE([HAVE_INDEX])],
+ [AC_LIBOBJ([strchr])])])
+
+AC_CHECK_FUNC([strrchr], [AC_DEFINE([HAVE_STRRCHR])],
+ [AC_CHECK_FUNC([rindex], [AC_DEFINE([HAVE_RINDEX])],
+ [AC_LIBOBJ([strrchr])])])
+
+AC_CHECK_FUNC([memcpy], [AC_DEFINE([HAVE_MEMCPY])],
+ [AC_CHECK_FUNC([bcopy], [AC_DEFINE([HAVE_BCOPY])],
+ [AC_LIBOBJ([memcpy])])])
+
+AC_REPLACE_FUNCS([memmove strcmp])
AC_CHECK_FUNCS([closedir opendir readdir])
])# AC_LIB_LTDL