libtool
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: libltdl obscures error messages


From: Marius Vollmer
Subject: Re: libltdl obscures error messages
Date: 25 Aug 2001 23:10:07 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.102

Marius Vollmer <address@hidden> writes:

> Gary V.Vaughan <address@hidden> writes:
> 
> > I would be delighted to help you implement this...
> 
> Great!  I'll prepare a patch...

Still interested? ;)

Here is a sort-of-minimal patch.

--- ltdl.c.~1.152.~     Sat Aug 25 20:59:17 2001
+++ ltdl.c      Sat Aug 25 23:05:14 2001
@@ -84,6 +84,7 @@
 
 /* I have never seen a system without this:  */
 #include <assert.h>
+#include <fcntl.h>
 
 #include "ltdl.h"
 
@@ -2230,15 +2231,25 @@
 {
   lt_dlhandle  *handle = (lt_dlhandle *) data;
   int          is_done = 0;
-
-  if (tryall_dlopen (handle, filename) == 0)
-    {
-      is_done = 1;
-    }
-
-  return is_done;
+  int fd;
+  
+  fd =  open (filename, O_RDONLY);
+  if (fd < 0 && errno == ENOENT)
+    return 0;
+  
+  /* found. try to dlopen it, but do not continue searching in any
+     case. */
+  close (fd);
+  if (tryall_dlopen (handle, filename) != 0)
+    *handle = NULL;
+  return 1;
 }
 
+/* Return NULL when the file has not been found.  Return HANDLE when
+   it has been found.  *HANDLE is non-null when the file could be
+   opened successfully, and it is NULL when there was some error.
+*/
+
 static lt_dlhandle *
 find_handle (search_path, base_name, handle)
      const char *search_path;
@@ -2482,8 +2493,9 @@
 }
 
 lt_dlhandle
-lt_dlopen (filename)
+lt_dlopen1 (filename, not_found)
      const char *filename;
+     int *not_found;
 {
   lt_dlhandle handle = 0, newhandle;
   const char *ext;
@@ -2497,6 +2509,8 @@
 
   LT_DLMUTEX_GETERROR (saved_error);
 
+  *not_found = 0;
+
   /* dlopen self? */
   if (!filename)
     {
@@ -2611,11 +2625,10 @@
       if (!file)
        {
          LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));
+         *not_found = 1;
+         goto cleanup;
        }
 
-      if (!file)
-       goto cleanup;
-
       line_len = LT_FILENAME_MAX;
       line = LT_EMALLOC (char, line_len);
       if (!line)
@@ -2780,7 +2793,12 @@
 #ifdef LTDL_SYSSEARCHPATH
                   && !find_handle (sys_search_path, base_name, &newhandle)
 #endif
-                  )) && tryall_dlopen (&newhandle, filename))
+                  )))
+       {
+         tryall_dlopen (&newhandle, filename);
+       }
+
+      if (newhandle == NULL)
        {
          LT_DLFREE (handle);
          goto cleanup;
@@ -2812,15 +2830,27 @@
 }
 
 lt_dlhandle
+lt_dlopen (filename)
+     const char *filename;
+{
+  int unused;
+  return lt_dlopen1 (filename, &unused);
+}
+
+/* If FILENAME has the ".la" or LTDL_SHLIB_EXT extension, try it as it
+   is.  Else, first try ".la" and if that fails due to a
+   file-not-found error, try LTDL_SHLIB_EXT.
+*/
+
+lt_dlhandle
 lt_dlopenext (filename)
      const char *filename;
 {
   lt_dlhandle handle;
-  char *tmp;
+  char *tmp;
+  char *ext;
   int  len;
-  const char *saved_error;
-
-  LT_DLMUTEX_GETERROR (saved_error);
+  int not_found;
 
   if (!filename)
     {
@@ -2834,6 +2864,10 @@
       return 0;
     }
 
+  ext = strrchr(filename, '.');
+  if (ext && (strcmp(ext, ".la") == 0 || strcmp(ext, LTDL_SHLIB_EXT) == 0))
+    return lt_dlopen (filename);
+
   /* try "filename.la" */
   tmp = LT_EMALLOC (char, len+4);
   if (!tmp)
@@ -2841,50 +2875,26 @@
 
   strcpy (tmp, filename);
   strcat (tmp, ".la");
-  handle = lt_dlopen (tmp);
-  if (handle)
-    {
-      LT_DLMUTEX_SETERROR (saved_error);
-      LT_DLFREE (tmp);
-      return handle;
-    }
+  handle = lt_dlopen1 (tmp, &not_found);
+  LT_DLFREE (tmp);
+  if (handle || !not_found)
+    return handle;
 
 #ifdef LTDL_SHLIB_EXT
   /* try "filename.EXT" */
-  if (LT_STRLEN(shlib_ext) > 3)
-    {
-      LT_DLFREE (tmp);
-      tmp = LT_EMALLOC (char, len + LT_STRLEN (shlib_ext) + 1);
-      if (!tmp)
-       return 0;
-
-      strcpy (tmp, filename);
-    }
-  else
-    {
-      tmp[len] = LT_EOS_CHAR;
-    }
+  tmp = LT_EMALLOC (char, len + LT_STRLEN (shlib_ext) + 1);
+  if (!tmp)
+    return 0;
 
+  strcpy (tmp, filename);
   strcat(tmp, shlib_ext);
   handle = lt_dlopen (tmp);
-  if (handle)
-    {
-      LT_DLMUTEX_SETERROR (saved_error);
-      LT_DLFREE (tmp);
-      return handle;
-    }
-#endif
-
-  /* try the normal file name */
-  handle = lt_dlopen (filename);
-  if (handle)
-    {
-      return handle;
-    }
-
-  LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));
   LT_DLFREE (tmp);
+  return handle;
+#else
+  LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));
   return 0;
+#endif
 }
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]