From 1cf343d5739f1b73e8d03efdb59a31495268b28d Mon Sep 17 00:00:00 2001 From: "Gary V. Vaughan" Date: Thu, 8 Apr 2004 13:51:15 +0000 Subject: [PATCH] * libltdl/ltdl.c: Move standard headers and preprocessor guards from here... * libltdl/lt__private.h: ...to here. New file to declare ltdl's internal interfaces. * libltdl/ltdl.c: Include lt__private.h. * m4/ltdl.m4 (AC_LIB_LTDL): Add lt_dirent to AC_LIBOBJ if all of opendir, readdir and closedir are missing. (AC_CHECK_HEADERS): Remove assert.h, ctype.h, errno.h, malloc.h, stdio.h and stdlib.h; these headers are all available in standard c89 environments and newer. * libltdl/lt__private.h: Include them here unconditionally. * libltdl/lt__dirent.c (opendir, readdir, closedir): New file. Windows dirent emulation functions moved to here... * libltdl/ltdl.c (opendir, readdir, closedir): ...from here. * libltdl/lt__dirent.h: New file. Rename the global symbols from lt__dirent.c into the lt__ namespace so they don't clash with other libraries. --- ChangeLog | 20 +++++ libltdl/lt__dirent.c | 101 +++++++++++++++++++++++ libltdl/lt__dirent.h | 97 ++++++++++++++++++++++ libltdl/lt__private.h | 81 +++++++++++++++++++ libltdl/lt_system.h | 3 + libltdl/ltdl.c | 181 +----------------------------------------- m4/ltdl.m4 | 6 +- 7 files changed, 307 insertions(+), 182 deletions(-) create mode 100644 libltdl/lt__dirent.c create mode 100644 libltdl/lt__dirent.h create mode 100644 libltdl/lt__private.h diff --git a/ChangeLog b/ChangeLog index 351edeae8..b037508da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2004-04-08 Gary V. Vaughan + + * libltdl/ltdl.c: Move standard headers and preprocessor guards + from here... + * libltdl/lt__private.h: ...to here. New file to declare ltdl's + internal interfaces. + * libltdl/ltdl.c: Include lt__private.h. + * m4/ltdl.m4 (AC_LIB_LTDL): Add lt_dirent to AC_LIBOBJ if all of + opendir, readdir and closedir are missing. + (AC_CHECK_HEADERS): Remove assert.h, ctype.h, errno.h, malloc.h, + stdio.h and stdlib.h; these headers are all available in standard + c89 environments and newer. + * libltdl/lt__private.h: Include them here unconditionally. + * libltdl/lt__dirent.c (opendir, readdir, closedir): New file. + Windows dirent emulation functions moved to here... + * libltdl/ltdl.c (opendir, readdir, closedir): ...from here. + * libltdl/lt__dirent.h: New file. Rename the global symbols from + lt__dirent.c into the lt__ namespace so they don't clash with + other libraries. + 2004-04-08 Gary V. Vaughan Factor out the bottom portability layer from ltdl. Code in this diff --git a/libltdl/lt__dirent.c b/libltdl/lt__dirent.c new file mode 100644 index 000000000..511572d14 --- /dev/null +++ b/libltdl/lt__dirent.c @@ -0,0 +1,101 @@ +/* lt__dirent.c -- internal directory entry scanning interface + Copyright (C) 2001, 2004 Free Software Foundation, Inc. + Originally by Bob Friesenhahn + + NOTE: The canonical source of this file is maintained with the + GNU Libtool package. Report bugs to bug-libtool@gnu.org. + +This 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 of the License, or (at your option) any later version. + +As a special exception to the GNU Lesser General Public License, +if you distribute this file as part of a program or library that +is built using GNU libtool, you may include it under the same +distribution terms that you use for the rest of that program. + +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 +#include + +#include "lt__dirent.h" + +#if __WINDOWS__ + +void +closedir (DIR *entry) +{ + assert (entry != (DIR *) NULL); + FindClose (entry->hSearch); + free ((void *) entry); +} + + +DIR * +opendir (const char *path) +{ + char file_specification[LT_FILENAME_MAX]; + DIR *entry; + + assert (path != (char *) 0); + (void) strncpy (file_specification, path, LT_FILENAME_MAX-1); + (void) strcat (file_specification, "\\"); + entry = (DIR *) malloc (sizeof(DIR)); + if (entry != (DIR *) 0) + { + entry->firsttime = TRUE; + entry->hSearch = FindFirstFile (file_specification, + &entry->Win32FindData); + + if (entry->hSearch == INVALID_HANDLE_VALUE) + { + (void) strcat (file_specification, "\\*.*"); + entry->hSearch = FindFirstFile (file_specification, + &entry->Win32FindData); + if (entry->hSearch == INVALID_HANDLE_VALUE) + { + entry = (free (entry), (DIR *) 0); + } + } + } + + return entry; +} + + +struct dirent * +readdir (DIR *entry) +{ + int status; + + if (entry == (DIR *) 0) + return (struct dirent *) 0; + + if (!entry->firsttime) + { + status = FindNextFile (entry->hSearch, &entry->Win32FindData); + if (status == 0) + return (struct dirent *) 0; + } + + entry->firsttime = FALSE; + (void) strncpy (entry->file_info.d_name, entry->Win32FindData.cFileName, + LT_FILENAME_MAX - 1); + entry->file_info.d_namlen = strlen (entry->file_info.d_name); + + return &entry->file_info; +} + +#endif /*__WINDOWS__*/ diff --git a/libltdl/lt__dirent.h b/libltdl/lt__dirent.h new file mode 100644 index 000000000..203e4867b --- /dev/null +++ b/libltdl/lt__dirent.h @@ -0,0 +1,97 @@ +/* lt__dirent.h -- internal directory entry scanning interface + Copyright (C) 2001, 2004 Free Software Foundation, Inc. + Originally by Bob Friesenhahn + + NOTE: The canonical source of this file is maintained with the + GNU Libtool package. Report bugs to bug-libtool@gnu.org. + +This 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 of the License, or (at your option) any later version. + +As a special exception to the GNU Lesser General Public License, +if you distribute this file as part of a program or library that +is built using GNU libtool, you may include it under the same +distribution terms that you use for the rest of that program. + +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 + +*/ + +#ifndef LT__DIRENT_H +#define LT__DIRENT_H 1 + +#ifdef HAVE_CONFIG_H +# include HAVE_CONFIG_H +#endif + +#include "lt_system.h" + +#if defined(HAVE_CLOSEDIR) && defined(HAVE_OPENDIR) && defined(HAVE_READDIR) && defined(HAVE_DIRENT_H) +/* We have a fully operational dirent subsystem. */ +# include +# define D_NAMLEN(dirent) (strlen((dirent)->d_name)) + +#elif !defined(__WINDOWS__) +/* We are not on windows, so we can get the same functionality from the + `direct' API. */ +# define dirent direct +# define D_NAMLEN(dirent) ((dirent)->d_namlen) +# if HAVE_SYS_NDIR_H +# include +# endif +# if HAVE_SYS_DIR_H +# include +# endif +# if HAVE_NDIR_H +# include +# endif + +#else /* __WINDOWS__ */ +/* Use some wrapper code to emulate dirent on windows.. */ +# define WINDOWS_DIRENT_EMULATION 1 + +# include + +# define D_NAMLEN(dirent) (strlen((dirent)->d_name)) +# define dirent lt__dirent +# define DIR lt__DIR +# define opendir lt__opendir +# define readdir lt__readdir +# define closedir lt__closedir + +LT_BEGIN_C_DECLS + +struct dirent +{ + char d_name[LT_FILENAME_MAX]; + int d_namlen; +}; + +typedef struct +{ + HANDLE hSearch; + WIN32_FIND_DATA Win32FindData; + BOOL firsttime; + struct dirent file_info; +} DIR; + + +DIR * opendir (const char *path); +struct dirent * readdir (DIR *entry); +void closedir (DIR *entry); + +LT_END_C_DECLS + +#endif /*!__WINDOWS__*/ + +#endif /*!LT__DIRENT_H*/ diff --git a/libltdl/lt__private.h b/libltdl/lt__private.h new file mode 100644 index 000000000..b2b91299d --- /dev/null +++ b/libltdl/lt__private.h @@ -0,0 +1,81 @@ +/* lt__private.h -- internal apis for libltdl + Copyright (C) 2004 Free Software Foundation, Inc. + Originally by Gary V. Vaughan + + NOTE: The canonical source of this file is maintained with the + GNU Libtool package. Report bugs to bug-libtool@gnu.org. + +This 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 of the License, or (at your option) any later version. + +As a special exception to the GNU Lesser General Public License, +if you distribute this file as part of a program or library that +is built using GNU libtool, you may include it under the same +distribution terms that you use for the rest of that program. + +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 + +*/ + +#ifndef LT__PRIVATE_H +#define LT__PRIVATE_H 1 + +#ifdef HAVE_CONFIG_H +# include HAVE_CONFIG_H +#endif + +#include +#include +#include +#include + +#if HAVE_UNISTD_H +# include +#endif + +#if HAVE_STRING_H +# include +#else +# if HAVE_STRINGS_H +# include +# endif +#endif +#if HAVE_MEMORY_H +# include +#endif + +#include "lt__alloc.h" +#include "lt__dirent.h" +#include "lt__pre89.h" +#include "lt_system.h" +#include "ltdl.h" + +#if WITH_DMALLOC +# include +#endif + +#ifdef DLL_EXPORT +# define LT_GLOBAL_DATA __declspec(dllexport) +#else +# define LT_GLOBAL_DATA +#endif + +LT_BEGIN_C_DECLS + +#ifndef errno +extern int errno; +#endif + +LT_END_C_DECLS + +#endif /*!LT__PRIVATE_H*/ diff --git a/libltdl/lt_system.h b/libltdl/lt_system.h index 4d8b62955..4a70c60d7 100644 --- a/libltdl/lt_system.h +++ b/libltdl/lt_system.h @@ -41,6 +41,9 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA # define EXIT_FAILURE 1 #endif +/* Just pick a big number... */ +#define LT_FILENAME_MAX 2048 + /* Saves on those hard to debug '\0' typos.... */ #define LT_EOS_CHAR '\0' diff --git a/libltdl/ltdl.c b/libltdl/ltdl.c index 620a281aa..0f15e5784 100644 --- a/libltdl/ltdl.c +++ b/libltdl/ltdl.c @@ -27,95 +27,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA */ -#ifdef HAVE_CONFIG_H -# include HAVE_CONFIG_H -#endif - -#if HAVE_UNISTD_H -# include -#endif - -#if HAVE_STDIO_H -# include -#endif - -#if HAVE_STRING_H -# include -#else -# if HAVE_STRINGS_H -# include -# endif -#endif - -#if HAVE_CTYPE_H -# include -#endif - -#if HAVE_MEMORY_H -# include -#endif - -#if HAVE_ERRNO_H -# include -#endif - -#if HAVE_ARGZ_H -# include -#endif - -#if HAVE_ASSERT_H -# include -#else -# define assert(arg) ((void) 0) -#endif - -#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. */ -# include -# define LT_D_NAMLEN(dirent) (strlen((dirent)->d_name)) - -#elif !defined(__WINDOWS__) -/* We are not on windows, so we can get the same functionality from the - `direct' API. */ -# define dirent direct -# define LT_D_NAMLEN(dirent) ((dirent)->d_namlen) -# if HAVE_SYS_NDIR_H -# include -# endif -# if HAVE_SYS_DIR_H -# include -# endif -# if HAVE_NDIR_H -# include -# endif - -#else /* __WINDOWS__ */ -/* Use some wrapper code to emulate dirent on windows.. */ -# define LT_USE_WINDOWS_DIRENT_EMULATION -#endif - -#if WITH_DMALLOC -# include -#endif - - - - -/* --- WINDOWS SUPPORT --- */ - - -#ifdef DLL_EXPORT -# define LT_GLOBAL_DATA __declspec(dllexport) -#else -# define LT_GLOBAL_DATA -#endif +#include "lt__private.h" - /* --- MANIFEST CONSTANTS --- */ @@ -141,97 +55,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA #define LT_SYMBOL_OVERHEAD 5 - - -# if LT_USE_WINDOWS_DIRENT_EMULATION - -# include - -# define LT_D_NAMLEN(dirent) (strlen((dirent)->d_name)) -# define dirent lt_dirent -# define DIR lt_DIR - -struct dirent -{ - char d_name[2048]; - int d_namlen; -}; - -typedef struct _DIR -{ - HANDLE hSearch; - WIN32_FIND_DATA Win32FindData; - BOOL firsttime; - struct dirent file_info; -} DIR; - -static void -closedir (DIR *entry) -{ - assert (entry != (DIR *) NULL); - FindClose (entry->hSearch); - free ((void *) entry); -} - - -static DIR * -opendir (const char *path) -{ - char file_specification[LT_FILENAME_MAX]; - DIR *entry; - - assert (path != (char *) NULL); - (void) strncpy (file_specification, path, LT_FILENAME_MAX-1); - (void) strcat (file_specification, "\\"); - entry = (DIR *) malloc (sizeof(DIR)); - if (entry != (DIR *) 0) - { - entry->firsttime = TRUE; - entry->hSearch = FindFirstFile (file_specification, - &entry->Win32FindData); - - if (entry->hSearch == INVALID_HANDLE_VALUE) - { - (void) strcat (file_specification, "\\*.*"); - entry->hSearch = FindFirstFile (file_specification, - &entry->Win32FindData); - if (entry->hSearch == INVALID_HANDLE_VALUE) - { - entry = (free (entry), (DIR *) 0); - } - } - } - - return entry; -} - - -static struct dirent * -readdir (DIR *entry) -{ - int status; - - if (entry == (DIR *) 0) - return (struct dirent *) 0; - - if (!entry->firsttime) - { - status = FindNextFile (entry->hSearch, &entry->Win32FindData); - if (status == 0) - return (struct dirent *) 0; - } - - entry->firsttime = FALSE; - (void) strncpy (entry->file_info.d_name, entry->Win32FindData.cFileName, - LT_FILENAME_MAX - 1); - entry->file_info.d_namlen = strlen (entry->file_info.d_name); - - return &entry->file_info; -} -#endif /* !LT_USE_WINDOWS_DIRENT_EMULATION */ - - - #if ! HAVE_ARGZ_APPEND # define argz_append rpl_argz_append @@ -3074,7 +2897,7 @@ lt_argz_insertdir (char **pargz, size_t *pargz_len, const char *dirnam, assert (dp); dir_len = LT_STRLEN (dirnam); - end = dp->d_name + LT_D_NAMLEN(dp); + end = dp->d_name + D_NAMLEN(dp); /* Ignore version numbers. */ { diff --git a/m4/ltdl.m4 b/m4/ltdl.m4 index fc9cfb5a9..004d5bd21 100644 --- a/m4/ltdl.m4 +++ b/m4/ltdl.m4 @@ -105,8 +105,7 @@ m4_ifset([AC_LIST_HEADERS], [CONFIG_H=config.h;AC_CONFIG_HEADERS([config.h])]) AC_SUBST([CONFIG_H]) -AC_CHECK_HEADERS([assert.h ctype.h errno.h malloc.h memory.h stdlib.h \ - stdio.h unistd.h dl.h sys/dl.h dld.h mach-o/dyld.h], +AC_CHECK_HEADERS([memory.h unistd.h dl.h sys/dl.h dld.h mach-o/dyld.h], [], [], [AC_INCLUDES_DEFAULT]) AC_CHECK_HEADERS([string.h strings.h], [break], [], [AC_INCLUDES_DEFAULT]) @@ -126,8 +125,9 @@ AC_CHECK_FUNC([memcpy], [AC_DEFINE([HAVE_MEMCPY])], [AC_CHECK_FUNC([bcopy], [AC_DEFINE([HAVE_BCOPY])], [AC_LIBOBJ([memcpy])])]) +AC_CHECK_FUNCS([closedir opendir readdir], [], [AC_LIBOBJ([lt__dirent])]) + AC_REPLACE_FUNCS([memmove strcmp]) -AC_CHECK_FUNCS([closedir opendir readdir]) ])# AC_LIB_LTDL -- 2.47.2