[project @ 2001-02-14 11:02:36 by sewardj]
authorsewardj <unknown>
Wed, 14 Feb 2001 11:02:36 +0000 (11:02 +0000)
committersewardj <unknown>
Wed, 14 Feb 2001 11:02:36 +0000 (11:02 +0000)
Allow addDLL to return error message strings to caller.

ghc/rts/Linker.c
ghc/rts/Linker.h

index d6a5ef2..d76e042 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Linker.c,v 1.28 2001/02/13 18:01:22 simonmar Exp $
+ * $Id: Linker.c,v 1.29 2001/02/14 11:02:36 sewardj Exp $
  *
  * (c) The GHC Team, 2000
  *
@@ -285,18 +285,27 @@ initLinker( void )
  * lookupSymbol() will subsequently see them by dlsym on the program's
  * dl-handle.  Returns 0 if fail, 1 if success.
  */
-int
+char*
 addDLL ( char* dll_name )
 {
 #  if defined(OBJFORMAT_ELF)
    void *hdl;
    char *buf;
+   char *errmsg;
 
    buf = stgMallocBytes(strlen(dll_name) + 10, "addDll");
    sprintf(buf, "lib%s.so", dll_name);
-   hdl = dlopen(buf, RTLD_NOW | RTLD_GLOBAL);
+   hdl = dlopen(buf, RTLD_NOW | RTLD_GLOBAL );
    free(buf);
-   return (hdl == NULL) ? 0 : 1;
+   if (hdl == NULL) {
+      /* dlopen failed; return a ptr to the error msg. */
+      errmsg = dlerror();
+      if (errmsg == NULL) errmsg = "addDLL: unknown error";
+      return errmsg;
+   } else {
+      return NULL;
+   }
+   ASSERT(0); /*NOTREACHED*/
 #  elif defined(OBJFORMAT_PEi386)
    barf("addDLL: not implemented on PEi386 yet");
    return 0;
index 2424f9c..5ab3c64 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Linker.h,v 1.3 2001/02/13 18:01:22 simonmar Exp $
+ * $Id: Linker.h,v 1.4 2001/02/14 11:02:36 sewardj Exp $
  *
  * (c) The GHC Team, 2000
  *
@@ -23,4 +23,4 @@ HsInt loadObj( char *path );
 HsInt resolveObjs( void );
 
 /* load a dynamic library */
-HsInt addDLL( char *path );
+char *addDLL( char *path );