Index: trunk/src/emx/include/dlfcn.h
===================================================================
--- trunk/src/emx/include/dlfcn.h	(revision 234)
+++ trunk/src/emx/include/dlfcn.h	(revision 234)
@@ -0,0 +1,60 @@
+/* dlfcn.h,v 1.1 2003/05/26 09:28:55 bird Exp */
+/** @file
+ * Dynamic Library Loading.
+ *
+ * Copyright (c) 2001-2003 knut st. osmundsen <bird@anduin.net>
+ *
+ * This program 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.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 _DLFCN_H_
+#define _DLFCN_H_
+
+
+/*******************************************************************************
+*   Defined Constants And Macros                                               *
+*******************************************************************************/
+/** @name dlopen flags
+ * @{ */
+/** Relocations are performed at an implementation-defined time.
+ * OS2: Happens when the pages are touched. Option is ignored. */
+#define RTLD_LAZY   1
+/** Relocations are performed when the object is loaded.
+ * OS2: Happens when the pages are touched. Option is ignored. */
+#define RTLD_NOW    2
+/** All symbols are available for relocation processing of other modules.
+ * OS2: Ignored as symbols are resolved using explicit link time reference. */
+#define RTLD_GLOBAL 0x100
+/** All symbols are not made available for relocation processing by other modules.
+ * OS2: Ignored as symbols are resolved using explicit link time reference. */
+#define RTLD_LOCAL  0
+/** @} */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void *          dlopen(const char * pszLibrary, int flFlags);
+const char *    dlerror(void);
+void *          dlsym(void *pvHandle, const char * pszSymbol);
+int             dlclose(void *pvHandle);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
Index: trunk/src/emx/src/lib/dlfcn/dl.smak
===================================================================
--- trunk/src/emx/src/lib/dlfcn/dl.smak	(revision 234)
+++ trunk/src/emx/src/lib/dlfcn/dl.smak	(revision 234)
@@ -0,0 +1,22 @@
+# This is the top-level submakefile for building EMX C runtime library
+include comend.smak
+
+.MODULE	:= libdl
+.MDESC	:= The dynamic loading library
+#.MDEP   := $(EMXIMP.DEPON) $(EMXOMF.DEPON)
+
+.TARGET	:= libdl_p.a
+.TKIND	:= aout prof
+.TSRC	:= $(wildcard src/lib/dlfcn/*.c)
+.INSDIR	= lib/
+.TKEEP	:= 1
+include mklib.smak
+include mkomflib.smak
+
+.TARGET	:= libdl.a
+.TKIND	:= aout
+include mklib.smak
+include mkomflib.smak
+
+# Forget temporary variables
+include comend.smak
Index: trunk/src/emx/src/lib/dlfcn/dlclose.c
===================================================================
--- trunk/src/emx/src/lib/dlfcn/dlclose.c	(revision 234)
+++ trunk/src/emx/src/lib/dlfcn/dlclose.c	(revision 234)
@@ -0,0 +1,45 @@
+/* $Id$ */
+/** @file
+ * dlclose - Close an dlopen'ed dynamic load library.
+ *
+ * Copyright (c) 2001-2003 knut st. osmundsen <bird@anduin.net>
+ *
+ * This program 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.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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
+ *
+ */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#define INCL_BASE
+#include <os2.h>
+#include <dlfcn.h>
+
+#include "dlfcn_private.h"
+
+
+/**
+ * Closes an open library.
+ * @param   pvHandle    Handle to close.
+ */
+int dlclose(void *pvHandle)
+{
+    APIRET rc;
+    rc = DosFreeModule((HMODULE)pvHandle);
+    dlfcn_enmLastOp     = dlfcn_dlclose;
+    dlfcn_ulLastError   = rc;
+    return rc;
+}
+
Index: trunk/src/emx/src/lib/dlfcn/dlerror.c
===================================================================
--- trunk/src/emx/src/lib/dlfcn/dlerror.c	(revision 234)
+++ trunk/src/emx/src/lib/dlfcn/dlerror.c	(revision 234)
@@ -0,0 +1,74 @@
+/* $Id$ */
+/** @file
+ * dlclose - Close an dlopen'ed dynamic load library.
+ *
+ * Copyright (c) 2001-2003 knut st. osmundsen <bird@anduin.net>
+ *
+ * This program 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.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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
+ *
+ */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#define INCL_BASE
+#include <os2.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <dlfcn.h>
+
+#include "dlfcn_private.h"
+
+
+/**
+ * Returns the last error.
+ * The last error is reset by this call.
+ * @returns NULL if not error since last dlerror call.
+ *          Error description string.
+ */
+const char *dlerror(void)
+{
+    if (dlfcn_ulLastError != NO_ERROR)
+    {
+        const char *pszOp = NULL;
+        char szTmpBuffer[DLFCN_MAX_ERROR_OBJ];
+
+        switch (dlfcn_enmLastOp)
+        {
+            case dlfcn_dlopen:  pszOp = "dlopen"; break;
+            case dlfcn_dlclose: pszOp = "dlclose"; break;
+            case dlfcn_dlsym:   pszOp = "dlerror"; break;
+            default:            pszOp = "!internal error!"; break;
+        }
+
+        szTmpBuffer[0] = '\0';
+        if (dlfcn_enmLastOp == dlfcn_dlopen || dlfcn_enmLastOp == dlfcn_dlclose)
+            strncat(&szTmpBuffer[0], &dlfcn_szLastError[0], sizeof(szTmpBuffer));
+
+        if (szTmpBuffer[0] != '\0')
+            sprintf(&dlfcn_szLastError[0], "%s rc=%lu extra=%s", pszOp, dlfcn_ulLastError, &szTmpBuffer[0]);
+        else
+            sprintf(&dlfcn_szLastError[0], "%s rc=%lu", pszOp, dlfcn_ulLastError);
+
+        dlfcn_ulLastError = NO_ERROR;
+        dlfcn_enmLastOp   = dlfcn_dlerror;
+        return &dlfcn_szLastError[0];
+    }
+
+    dlfcn_enmLastOp   = dlfcn_dlerror;
+    return NULL;
+}
+
Index: trunk/src/emx/src/lib/dlfcn/dlfcn_data.c
===================================================================
--- trunk/src/emx/src/lib/dlfcn/dlfcn_data.c	(revision 234)
+++ trunk/src/emx/src/lib/dlfcn/dlfcn_data.c	(revision 234)
@@ -0,0 +1,35 @@
+/* $Id$ */
+/** @file
+ * dlfcn - global data (thread unsafe, but I don't care)
+ *
+ * Copyright (c) 2001-2003 knut st. osmundsen <bird@anduin.net>
+ *
+ * This program 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.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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
+ *
+ */
+
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include "dlfcn_private.h"
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+char                dlfcn_szLastError[DLFCN_MAX_ERROR_STR];
+unsigned long       dlfcn_ulLastError;
+enum dlfcn_enmOp    dlfcn_enmLastOp = dlfcn_none;
+
Index: trunk/src/emx/src/lib/dlfcn/dlfcn_private.h
===================================================================
--- trunk/src/emx/src/lib/dlfcn/dlfcn_private.h	(revision 234)
+++ trunk/src/emx/src/lib/dlfcn/dlfcn_private.h	(revision 234)
@@ -0,0 +1,56 @@
+/* $Id$ */
+/** @file
+ * dlfcn - global data (thread unsafe, but I don't care)
+ *
+ * Copyright (c) 2001-2003 knut st. osmundsen <bird@anduin.net>
+ *
+ * This program 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.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 __DLFCN_PRIVATE_H_
+#define __DLFCN_PRIVATE_H_
+
+/*******************************************************************************
+*   Defined Constants And Macros                                               *
+*******************************************************************************/
+/** Max error object name length. */
+#define DLFCN_MAX_ERROR_OBJ     64
+/** Max error string returned by dlerror. */
+#define DLFCN_MAX_ERROR_STR     DLFCN_MAX_ERROR_OBJ + 64
+
+/*******************************************************************************
+*   Structures and Typedefs                                                    *
+*******************************************************************************/
+/** Enumeration of possible dlfcn operations in relation to dlerror processing. */
+enum dlfcn_enmOp {  dlfcn_none = 0,
+                    dlfcn_dlopen, dlfcn_dlsym, dlfcn_dlclose, dlfcn_dlerror};
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+/** Buffer which have two uses.
+ * Primary use is for dlerror return string.
+ * Secondary use is for dlopen and dlsym to pass a string to dlerror.
+ * Use dlfcn_enmLastOp to determin the content status.
+ */
+extern char             dlfcn_szLastError[DLFCN_MAX_ERROR_STR];
+/** Last return code from these functions. */
+extern unsigned long    dlfcn_ulLastError;
+/** Last operation. Decides the state of the ??LastError variables. */
+extern enum dlfcn_enmOp dlfcn_enmLastOp;
+
+
+#endif
Index: trunk/src/emx/src/lib/dlfcn/dlopen.c
===================================================================
--- trunk/src/emx/src/lib/dlfcn/dlopen.c	(revision 234)
+++ trunk/src/emx/src/lib/dlfcn/dlopen.c	(revision 234)
@@ -0,0 +1,62 @@
+/* $Id$ */
+/** @file
+ * dlclose - Close an dlopen'ed dynamic load library.
+ *
+ * Copyright (c) 2001-2003 knut st. osmundsen <bird@anduin.net>
+ *
+ * This program 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.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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
+ *
+ */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#define INCL_BASE
+#include <os2.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <dlfcn.h>
+
+#include "dlfcn_private.h"
+
+
+/**
+ * Opens the library pszLibrary.
+ * @returns Handle to module.
+ *          NULL if open failed.
+ * @param   pszLibrary      Name of library to load.
+ * @param   flFlags         Flags - ignored.
+ */
+void *  dlopen(const char *pszLibrary, int flFlags)
+{
+    HMODULE     hmod;
+    CHAR        szErrorObj[DLFCN_MAX_ERROR_OBJ];
+    APIRET      rc;
+
+    rc = DosLoadModule(&szErrorObj[0], sizeof(szErrorObj), pszLibrary, &hmod);
+    dlfcn_enmLastOp     = dlfcn_dlopen;
+    dlfcn_ulLastError   = rc;
+    if (rc != NO_ERROR)
+    {
+        dlfcn_szLastError[0] = '\0';
+        strncat(dlfcn_szLastError, szErrorObj, sizeof(dlfcn_szLastError));
+        hmod = NULLHANDLE;
+    }
+
+    flFlags = flFlags; /* ignore flags */
+    return (void*)hmod;
+}
+
Index: trunk/src/emx/src/lib/dlfcn/dlsym.c
===================================================================
--- trunk/src/emx/src/lib/dlfcn/dlsym.c	(revision 234)
+++ trunk/src/emx/src/lib/dlfcn/dlsym.c	(revision 234)
@@ -0,0 +1,59 @@
+/* $Id$ */
+/** @file
+ * dlclose - Close an dlopen'ed dynamic load library.
+ *
+ * Copyright (c) 2001-2003 knut st. osmundsen <bird@anduin.net>
+ *
+ * This program 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.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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
+ *
+ */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#define INCL_BASE
+#include <os2.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <dlfcn.h>
+
+#include "dlfcn_private.h"
+
+/**
+ * Find the address of a given symbol within the given library.
+ * @returns Address of symbol.
+ *          NULL if not found.
+ * @param   pvHandle    Module handle returned by dlopen.
+ * @param   pszSymbol   Name of the symbol.
+ */
+void * dlsym(void *pvHandle, const char *pszSymbol)
+{
+    APIRET  rc;                         /* Return code. */
+    PFN     pfn;                        /* Returned symbol pointer. */
+
+    rc = DosQueryProcAddr((HMODULE)pvHandle, 0, pszSymbol, &pfn);
+    dlfcn_enmLastOp     = dlfcn_dlsym;
+    dlfcn_ulLastError   = rc;
+    if (rc != NO_ERROR)
+    {
+        dlfcn_szLastError[0] = '\0';
+        strncat(dlfcn_szLastError, pszSymbol, sizeof(dlfcn_szLastError));
+        return NULL;
+    }
+
+    return (void*)pfn;
+}
+
Index: trunk/src/emx/src/libdl/dl.smak
===================================================================
--- trunk/src/emx/src/libdl/dl.smak	(revision 234)
+++ trunk/src/emx/src/libdl/dl.smak	(revision 234)
@@ -0,0 +1,22 @@
+# This is the top-level submakefile for building EMX C runtime library
+include comend.smak
+
+.MODULE	:= libdl
+.MDESC	:= The dynamic loading library
+#.MDEP   := $(EMXIMP.DEPON) $(EMXOMF.DEPON)
+
+.TARGET	:= libdl_p.a
+.TKIND	:= aout prof
+.TSRC	:= $(wildcard src/lib/dlfcn/*.c)
+.INSDIR	= lib/
+.TKEEP	:= 1
+include mklib.smak
+include mkomflib.smak
+
+.TARGET	:= libdl.a
+.TKIND	:= aout
+include mklib.smak
+include mkomflib.smak
+
+# Forget temporary variables
+include comend.smak
Index: trunk/src/emx/src/libdl/dlclose.c
===================================================================
--- trunk/src/emx/src/libdl/dlclose.c	(revision 234)
+++ trunk/src/emx/src/libdl/dlclose.c	(revision 234)
@@ -0,0 +1,45 @@
+/* $Id$ */
+/** @file
+ * dlclose - Close an dlopen'ed dynamic load library.
+ *
+ * Copyright (c) 2001-2003 knut st. osmundsen <bird@anduin.net>
+ *
+ * This program 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.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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
+ *
+ */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#define INCL_BASE
+#include <os2.h>
+#include <dlfcn.h>
+
+#include "dlfcn_private.h"
+
+
+/**
+ * Closes an open library.
+ * @param   pvHandle    Handle to close.
+ */
+int dlclose(void *pvHandle)
+{
+    APIRET rc;
+    rc = DosFreeModule((HMODULE)pvHandle);
+    dlfcn_enmLastOp     = dlfcn_dlclose;
+    dlfcn_ulLastError   = rc;
+    return rc;
+}
+
Index: trunk/src/emx/src/libdl/dlerror.c
===================================================================
--- trunk/src/emx/src/libdl/dlerror.c	(revision 234)
+++ trunk/src/emx/src/libdl/dlerror.c	(revision 234)
@@ -0,0 +1,74 @@
+/* $Id$ */
+/** @file
+ * dlclose - Close an dlopen'ed dynamic load library.
+ *
+ * Copyright (c) 2001-2003 knut st. osmundsen <bird@anduin.net>
+ *
+ * This program 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.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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
+ *
+ */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#define INCL_BASE
+#include <os2.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <dlfcn.h>
+
+#include "dlfcn_private.h"
+
+
+/**
+ * Returns the last error.
+ * The last error is reset by this call.
+ * @returns NULL if not error since last dlerror call.
+ *          Error description string.
+ */
+const char *dlerror(void)
+{
+    if (dlfcn_ulLastError != NO_ERROR)
+    {
+        const char *pszOp = NULL;
+        char szTmpBuffer[DLFCN_MAX_ERROR_OBJ];
+
+        switch (dlfcn_enmLastOp)
+        {
+            case dlfcn_dlopen:  pszOp = "dlopen"; break;
+            case dlfcn_dlclose: pszOp = "dlclose"; break;
+            case dlfcn_dlsym:   pszOp = "dlerror"; break;
+            default:            pszOp = "!internal error!"; break;
+        }
+
+        szTmpBuffer[0] = '\0';
+        if (dlfcn_enmLastOp == dlfcn_dlopen || dlfcn_enmLastOp == dlfcn_dlclose)
+            strncat(&szTmpBuffer[0], &dlfcn_szLastError[0], sizeof(szTmpBuffer));
+
+        if (szTmpBuffer[0] != '\0')
+            sprintf(&dlfcn_szLastError[0], "%s rc=%lu extra=%s", pszOp, dlfcn_ulLastError, &szTmpBuffer[0]);
+        else
+            sprintf(&dlfcn_szLastError[0], "%s rc=%lu", pszOp, dlfcn_ulLastError);
+
+        dlfcn_ulLastError = NO_ERROR;
+        dlfcn_enmLastOp   = dlfcn_dlerror;
+        return &dlfcn_szLastError[0];
+    }
+
+    dlfcn_enmLastOp   = dlfcn_dlerror;
+    return NULL;
+}
+
Index: trunk/src/emx/src/libdl/dlfcn_data.c
===================================================================
--- trunk/src/emx/src/libdl/dlfcn_data.c	(revision 234)
+++ trunk/src/emx/src/libdl/dlfcn_data.c	(revision 234)
@@ -0,0 +1,35 @@
+/* $Id$ */
+/** @file
+ * dlfcn - global data (thread unsafe, but I don't care)
+ *
+ * Copyright (c) 2001-2003 knut st. osmundsen <bird@anduin.net>
+ *
+ * This program 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.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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
+ *
+ */
+
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include "dlfcn_private.h"
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+char                dlfcn_szLastError[DLFCN_MAX_ERROR_STR];
+unsigned long       dlfcn_ulLastError;
+enum dlfcn_enmOp    dlfcn_enmLastOp = dlfcn_none;
+
Index: trunk/src/emx/src/libdl/dlfcn_private.h
===================================================================
--- trunk/src/emx/src/libdl/dlfcn_private.h	(revision 234)
+++ trunk/src/emx/src/libdl/dlfcn_private.h	(revision 234)
@@ -0,0 +1,56 @@
+/* $Id$ */
+/** @file
+ * dlfcn - global data (thread unsafe, but I don't care)
+ *
+ * Copyright (c) 2001-2003 knut st. osmundsen <bird@anduin.net>
+ *
+ * This program 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.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 __DLFCN_PRIVATE_H_
+#define __DLFCN_PRIVATE_H_
+
+/*******************************************************************************
+*   Defined Constants And Macros                                               *
+*******************************************************************************/
+/** Max error object name length. */
+#define DLFCN_MAX_ERROR_OBJ     64
+/** Max error string returned by dlerror. */
+#define DLFCN_MAX_ERROR_STR     DLFCN_MAX_ERROR_OBJ + 64
+
+/*******************************************************************************
+*   Structures and Typedefs                                                    *
+*******************************************************************************/
+/** Enumeration of possible dlfcn operations in relation to dlerror processing. */
+enum dlfcn_enmOp {  dlfcn_none = 0,
+                    dlfcn_dlopen, dlfcn_dlsym, dlfcn_dlclose, dlfcn_dlerror};
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+/** Buffer which have two uses.
+ * Primary use is for dlerror return string.
+ * Secondary use is for dlopen and dlsym to pass a string to dlerror.
+ * Use dlfcn_enmLastOp to determin the content status.
+ */
+extern char             dlfcn_szLastError[DLFCN_MAX_ERROR_STR];
+/** Last return code from these functions. */
+extern unsigned long    dlfcn_ulLastError;
+/** Last operation. Decides the state of the ??LastError variables. */
+extern enum dlfcn_enmOp dlfcn_enmLastOp;
+
+
+#endif
Index: trunk/src/emx/src/libdl/dlopen.c
===================================================================
--- trunk/src/emx/src/libdl/dlopen.c	(revision 234)
+++ trunk/src/emx/src/libdl/dlopen.c	(revision 234)
@@ -0,0 +1,62 @@
+/* $Id$ */
+/** @file
+ * dlclose - Close an dlopen'ed dynamic load library.
+ *
+ * Copyright (c) 2001-2003 knut st. osmundsen <bird@anduin.net>
+ *
+ * This program 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.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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
+ *
+ */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#define INCL_BASE
+#include <os2.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <dlfcn.h>
+
+#include "dlfcn_private.h"
+
+
+/**
+ * Opens the library pszLibrary.
+ * @returns Handle to module.
+ *          NULL if open failed.
+ * @param   pszLibrary      Name of library to load.
+ * @param   flFlags         Flags - ignored.
+ */
+void *  dlopen(const char *pszLibrary, int flFlags)
+{
+    HMODULE     hmod;
+    CHAR        szErrorObj[DLFCN_MAX_ERROR_OBJ];
+    APIRET      rc;
+
+    rc = DosLoadModule(&szErrorObj[0], sizeof(szErrorObj), pszLibrary, &hmod);
+    dlfcn_enmLastOp     = dlfcn_dlopen;
+    dlfcn_ulLastError   = rc;
+    if (rc != NO_ERROR)
+    {
+        dlfcn_szLastError[0] = '\0';
+        strncat(dlfcn_szLastError, szErrorObj, sizeof(dlfcn_szLastError));
+        hmod = NULLHANDLE;
+    }
+
+    flFlags = flFlags; /* ignore flags */
+    return (void*)hmod;
+}
+
Index: trunk/src/emx/src/libdl/dlsym.c
===================================================================
--- trunk/src/emx/src/libdl/dlsym.c	(revision 234)
+++ trunk/src/emx/src/libdl/dlsym.c	(revision 234)
@@ -0,0 +1,59 @@
+/* $Id$ */
+/** @file
+ * dlclose - Close an dlopen'ed dynamic load library.
+ *
+ * Copyright (c) 2001-2003 knut st. osmundsen <bird@anduin.net>
+ *
+ * This program 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.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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
+ *
+ */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#define INCL_BASE
+#include <os2.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <dlfcn.h>
+
+#include "dlfcn_private.h"
+
+/**
+ * Find the address of a given symbol within the given library.
+ * @returns Address of symbol.
+ *          NULL if not found.
+ * @param   pvHandle    Module handle returned by dlopen.
+ * @param   pszSymbol   Name of the symbol.
+ */
+void * dlsym(void *pvHandle, const char *pszSymbol)
+{
+    APIRET  rc;                         /* Return code. */
+    PFN     pfn;                        /* Returned symbol pointer. */
+
+    rc = DosQueryProcAddr((HMODULE)pvHandle, 0, pszSymbol, &pfn);
+    dlfcn_enmLastOp     = dlfcn_dlsym;
+    dlfcn_ulLastError   = rc;
+    if (rc != NO_ERROR)
+    {
+        dlfcn_szLastError[0] = '\0';
+        strncat(dlfcn_szLastError, pszSymbol, sizeof(dlfcn_szLastError));
+        return NULL;
+    }
+
+    return (void*)pfn;
+}
+
