]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
dos2unix
authorMichael Jerris <mike@jerris.com>
Wed, 27 May 2009 23:07:50 +0000 (23:07 +0000)
committerMichael Jerris <mike@jerris.com>
Wed, 27 May 2009 23:07:50 +0000 (23:07 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13473 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/inet_pton.c
src/switch_dso.c

index 0788940cde6a1c2184a85d415b5fe660239d7004..33e55c1de81ed7646b9beb11c2ab40a0557d9d38 100644 (file)
-/* This is from the BIND 4.9.4 release, modified to compile by itself */\r
-\r
-/* Copyright (c) 1996 by Internet Software Consortium.\r
- *\r
- * Permission to use, copy, modify, and distribute this software for any\r
- * purpose with or without fee is hereby granted, provided that the above\r
- * copyright notice and this permission notice appear in all copies.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS\r
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES\r
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE\r
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL\r
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\r
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\r
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\r
- * SOFTWARE.\r
- */\r
-\r
-#ifndef HAVE_INET_PTON\r
-\r
-#ifdef HAVE_SYS_PARAM_H\r
-#include <sys/param.h>\r
-#endif\r
-#ifdef HAVE_SYS_TYPES_H\r
-#include <sys/types.h>\r
-#endif\r
-#ifdef HAVE_SYS_SOCKET_H\r
-#include <sys/socket.h>\r
-#endif\r
-#ifdef HAVE_NETINET_IN_H\r
-#include <netinet/in.h>\r
-#endif\r
-#ifdef HAVE_ARPA_INET_H\r
-#include <arpa/inet.h>\r
-#endif\r
-#include <string.h>\r
-#include <errno.h>\r
-\r
-#define IN6ADDRSZ       16\r
-#define INADDRSZ         4\r
-#define INT16SZ          2\r
-\r
-#ifdef WIN32\r
-#include <winsock2.h>\r
-#define EAFNOSUPPORT    WSAEAFNOSUPPORT\r
-#endif\r
-\r
-/*\r
- * WARNING: Don't even consider trying to compile this on a system where\r
- * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.\r
- */\r
-\r
-static int      inet_pton4(const char *src, unsigned char *dst);\r
-#ifdef ENABLE_IPV6\r
-static int      inet_pton6(const char *src, unsigned char *dst);\r
-#endif\r
-\r
-/* int\r
- * inet_pton(af, src, dst)\r
- *      convert from presentation format (which usually means ASCII printable)\r
- *      to network format (which is usually some kind of binary format).\r
- * return:\r
- *      1 if the address was valid for the specified address family\r
- *      0 if the address wasn't valid (`dst' is untouched in this case)\r
- *      -1 if some other error occurred (`dst' is untouched in this case, too)\r
- * author:\r
- *      Paul Vixie, 1996.\r
- */\r
-int\r
-switch_inet_pton(int af, const char *src, void *dst)\r
-{\r
-  switch (af) {\r
-  case AF_INET:\r
-    return (inet_pton4(src, (unsigned char *)dst));\r
-#ifdef ENABLE_IPV6\r
-#ifndef AF_INET6\r
-#define AF_INET6        (AF_MAX+1)        /* just to let this compile */\r
-#endif\r
-  case AF_INET6:\r
-    return (inet_pton6(src, (unsigned char *)dst));\r
-#endif\r
-  default:\r
-    errno = EAFNOSUPPORT;\r
-    return (-1);\r
-  }\r
-  /* NOTREACHED */\r
-}\r
-\r
-/* int\r
- * inet_pton4(src, dst)\r
- *      like inet_aton() but without all the hexadecimal and shorthand.\r
- * return:\r
- *      1 if `src' is a valid dotted quad, else 0.\r
- * notice:\r
- *      does not touch `dst' unless it's returning 1.\r
- * author:\r
- *      Paul Vixie, 1996.\r
- */\r
-static int\r
-inet_pton4(const char *src, unsigned char *dst)\r
-{\r
-  static const char digits[] = "0123456789";\r
-  int saw_digit, octets, ch;\r
-  unsigned char tmp[INADDRSZ], *tp;\r
-\r
-  saw_digit = 0;\r
-  octets = 0;\r
-  tp = tmp;\r
-  *tp = 0;\r
-  while ((ch = *src++) != '\0') {\r
-    const char *pch;\r
-\r
-    if ((pch = strchr(digits, ch)) != NULL) {\r
-      unsigned int val = *tp * 10 + (unsigned int)(pch - digits);\r
-\r
-      if (val > 255)\r
-        return (0);\r
-      *tp = (unsigned char)val;\r
-      if (! saw_digit) {\r
-        if (++octets > 4)\r
-          return (0);\r
-        saw_digit = 1;\r
-      }\r
-    } else if (ch == '.' && saw_digit) {\r
-      if (octets == 4)\r
-        return (0);\r
-      *++tp = 0;\r
-      saw_digit = 0;\r
-    } else\r
-      return (0);\r
-  }\r
-  if (octets < 4)\r
-    return (0);\r
-  /* bcopy(tmp, dst, INADDRSZ); */\r
-  memcpy(dst, tmp, INADDRSZ);\r
-  return (1);\r
-}\r
-\r
-#ifdef ENABLE_IPV6\r
-/* int\r
- * inet_pton6(src, dst)\r
- *      convert presentation level address to network order binary form.\r
- * return:\r
- *      1 if `src' is a valid [RFC1884 2.2] address, else 0.\r
- * notice:\r
- *      (1) does not touch `dst' unless it's returning 1.\r
- *      (2) :: in a full address is silently ignored.\r
- * credit:\r
- *      inspired by Mark Andrews.\r
- * author:\r
- *      Paul Vixie, 1996.\r
- */\r
-static int\r
-inet_pton6(const char *src, unsigned char *dst)\r
-{\r
-  static const char xdigits_l[] = "0123456789abcdef",\r
-    xdigits_u[] = "0123456789ABCDEF";\r
-  unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp;\r
-  const char *xdigits, *curtok;\r
-  int ch, saw_xdigit;\r
-  unsigned int val;\r
-\r
-  memset((tp = tmp), 0, IN6ADDRSZ);\r
-  endp = tp + IN6ADDRSZ;\r
-  colonp = NULL;\r
-  /* Leading :: requires some special handling. */\r
-  if (*src == ':')\r
-    if (*++src != ':')\r
-      return (0);\r
-  curtok = src;\r
-  saw_xdigit = 0;\r
-  val = 0;\r
-  while ((ch = *src++) != '\0') {\r
-    const char *pch;\r
-\r
-    if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)\r
-      pch = strchr((xdigits = xdigits_u), ch);\r
-    if (pch != NULL) {\r
-      val <<= 4;\r
-      val |= (pch - xdigits);\r
-      if (val > 0xffff)\r
-        return (0);\r
-      saw_xdigit = 1;\r
-      continue;\r
-    }\r
-    if (ch == ':') {\r
-      curtok = src;\r
-      if (!saw_xdigit) {\r
-        if (colonp)\r
-          return (0);\r
-        colonp = tp;\r
-        continue;\r
-      }\r
-      if (tp + INT16SZ > endp)\r
-        return (0);\r
-      *tp++ = (unsigned char) (val >> 8) & 0xff;\r
-      *tp++ = (unsigned char) val & 0xff;\r
-      saw_xdigit = 0;\r
-      val = 0;\r
-      continue;\r
-    }\r
-    if (ch == '.' && ((tp + INADDRSZ) <= endp) &&\r
-        inet_pton4(curtok, tp) > 0) {\r
-      tp += INADDRSZ;\r
-      saw_xdigit = 0;\r
-      break;    /* '\0' was seen by inet_pton4(). */\r
-    }\r
-    return (0);\r
-  }\r
-  if (saw_xdigit) {\r
-    if (tp + INT16SZ > endp)\r
-      return (0);\r
-    *tp++ = (unsigned char) (val >> 8) & 0xff;\r
-    *tp++ = (unsigned char) val & 0xff;\r
-  }\r
-  if (colonp != NULL) {\r
-    /*\r
-     * Since some memmove()'s erroneously fail to handle\r
-     * overlapping regions, we'll do the shift by hand.\r
-     */\r
-    const int n = tp - colonp;\r
-    int i;\r
-\r
-    for (i = 1; i <= n; i++) {\r
-      endp[- i] = colonp[n - i];\r
-      colonp[n - i] = 0;\r
-    }\r
-    tp = endp;\r
-  }\r
-  if (tp != endp)\r
-    return (0);\r
-  /* bcopy(tmp, dst, IN6ADDRSZ); */\r
-  memcpy(dst, tmp, IN6ADDRSZ);\r
-  return (1);\r
-}\r
-#endif /* ENABLE_IPV6 */\r
-\r
-#endif /* HAVE_INET_PTON */\r
+/* This is from the BIND 4.9.4 release, modified to compile by itself */
+
+/* Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifndef HAVE_INET_PTON
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#include <string.h>
+#include <errno.h>
+
+#define IN6ADDRSZ       16
+#define INADDRSZ         4
+#define INT16SZ          2
+
+#ifdef WIN32
+#include <winsock2.h>
+#define EAFNOSUPPORT    WSAEAFNOSUPPORT
+#endif
+
+/*
+ * WARNING: Don't even consider trying to compile this on a system where
+ * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.
+ */
+
+static int      inet_pton4(const char *src, unsigned char *dst);
+#ifdef ENABLE_IPV6
+static int      inet_pton6(const char *src, unsigned char *dst);
+#endif
+
+/* int
+ * inet_pton(af, src, dst)
+ *      convert from presentation format (which usually means ASCII printable)
+ *      to network format (which is usually some kind of binary format).
+ * return:
+ *      1 if the address was valid for the specified address family
+ *      0 if the address wasn't valid (`dst' is untouched in this case)
+ *      -1 if some other error occurred (`dst' is untouched in this case, too)
+ * author:
+ *      Paul Vixie, 1996.
+ */
+int
+switch_inet_pton(int af, const char *src, void *dst)
+{
+  switch (af) {
+  case AF_INET:
+    return (inet_pton4(src, (unsigned char *)dst));
+#ifdef ENABLE_IPV6
+#ifndef AF_INET6
+#define AF_INET6        (AF_MAX+1)        /* just to let this compile */
+#endif
+  case AF_INET6:
+    return (inet_pton6(src, (unsigned char *)dst));
+#endif
+  default:
+    errno = EAFNOSUPPORT;
+    return (-1);
+  }
+  /* NOTREACHED */
+}
+
+/* int
+ * inet_pton4(src, dst)
+ *      like inet_aton() but without all the hexadecimal and shorthand.
+ * return:
+ *      1 if `src' is a valid dotted quad, else 0.
+ * notice:
+ *      does not touch `dst' unless it's returning 1.
+ * author:
+ *      Paul Vixie, 1996.
+ */
+static int
+inet_pton4(const char *src, unsigned char *dst)
+{
+  static const char digits[] = "0123456789";
+  int saw_digit, octets, ch;
+  unsigned char tmp[INADDRSZ], *tp;
+
+  saw_digit = 0;
+  octets = 0;
+  tp = tmp;
+  *tp = 0;
+  while ((ch = *src++) != '\0') {
+    const char *pch;
+
+    if ((pch = strchr(digits, ch)) != NULL) {
+      unsigned int val = *tp * 10 + (unsigned int)(pch - digits);
+
+      if (val > 255)
+        return (0);
+      *tp = (unsigned char)val;
+      if (! saw_digit) {
+        if (++octets > 4)
+          return (0);
+        saw_digit = 1;
+      }
+    } else if (ch == '.' && saw_digit) {
+      if (octets == 4)
+        return (0);
+      *++tp = 0;
+      saw_digit = 0;
+    } else
+      return (0);
+  }
+  if (octets < 4)
+    return (0);
+  /* bcopy(tmp, dst, INADDRSZ); */
+  memcpy(dst, tmp, INADDRSZ);
+  return (1);
+}
+
+#ifdef ENABLE_IPV6
+/* int
+ * inet_pton6(src, dst)
+ *      convert presentation level address to network order binary form.
+ * return:
+ *      1 if `src' is a valid [RFC1884 2.2] address, else 0.
+ * notice:
+ *      (1) does not touch `dst' unless it's returning 1.
+ *      (2) :: in a full address is silently ignored.
+ * credit:
+ *      inspired by Mark Andrews.
+ * author:
+ *      Paul Vixie, 1996.
+ */
+static int
+inet_pton6(const char *src, unsigned char *dst)
+{
+  static const char xdigits_l[] = "0123456789abcdef",
+    xdigits_u[] = "0123456789ABCDEF";
+  unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
+  const char *xdigits, *curtok;
+  int ch, saw_xdigit;
+  unsigned int val;
+
+  memset((tp = tmp), 0, IN6ADDRSZ);
+  endp = tp + IN6ADDRSZ;
+  colonp = NULL;
+  /* Leading :: requires some special handling. */
+  if (*src == ':')
+    if (*++src != ':')
+      return (0);
+  curtok = src;
+  saw_xdigit = 0;
+  val = 0;
+  while ((ch = *src++) != '\0') {
+    const char *pch;
+
+    if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
+      pch = strchr((xdigits = xdigits_u), ch);
+    if (pch != NULL) {
+      val <<= 4;
+      val |= (pch - xdigits);
+      if (val > 0xffff)
+        return (0);
+      saw_xdigit = 1;
+      continue;
+    }
+    if (ch == ':') {
+      curtok = src;
+      if (!saw_xdigit) {
+        if (colonp)
+          return (0);
+        colonp = tp;
+        continue;
+      }
+      if (tp + INT16SZ > endp)
+        return (0);
+      *tp++ = (unsigned char) (val >> 8) & 0xff;
+      *tp++ = (unsigned char) val & 0xff;
+      saw_xdigit = 0;
+      val = 0;
+      continue;
+    }
+    if (ch == '.' && ((tp + INADDRSZ) <= endp) &&
+        inet_pton4(curtok, tp) > 0) {
+      tp += INADDRSZ;
+      saw_xdigit = 0;
+      break;    /* '\0' was seen by inet_pton4(). */
+    }
+    return (0);
+  }
+  if (saw_xdigit) {
+    if (tp + INT16SZ > endp)
+      return (0);
+    *tp++ = (unsigned char) (val >> 8) & 0xff;
+    *tp++ = (unsigned char) val & 0xff;
+  }
+  if (colonp != NULL) {
+    /*
+     * Since some memmove()'s erroneously fail to handle
+     * overlapping regions, we'll do the shift by hand.
+     */
+    const int n = tp - colonp;
+    int i;
+
+    for (i = 1; i <= n; i++) {
+      endp[- i] = colonp[n - i];
+      colonp[n - i] = 0;
+    }
+    tp = endp;
+  }
+  if (tp != endp)
+    return (0);
+  /* bcopy(tmp, dst, IN6ADDRSZ); */
+  memcpy(dst, tmp, IN6ADDRSZ);
+  return (1);
+}
+#endif /* ENABLE_IPV6 */
+
+#endif /* HAVE_INET_PTON */
index 259bf1fc23bce53574673d90061d274918fafa78..a1c63f092c314a9f3e1ec594daafc9be86132e11 100644 (file)
-/* \r
- * Cross Platform dso/dll load abstraction\r
- * Copyright(C) 2008 Michael Jerris\r
- *\r
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell\r
- * copies of the Software, and permit persons to whom the Software is\r
- * furnished to do so.\r
- *\r
- * This work is provided under this license on an "as is" basis, without warranty of any kind,\r
- * either expressed or implied, including, without limitation, warranties that the covered code\r
- * is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire\r
- * risk as to the quality and performance of the covered code is with you. Should any covered\r
- * code prove defective in any respect, you (not the initial developer or any other contributor)\r
- * assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty\r
- * constitutes an essential part of this license. No use of any covered code is authorized hereunder\r
- * except under this disclaimer. \r
- *\r
- */\r
-\r
-#include <switch.h>\r
-#include "switch_dso.h"\r
-#include <stdlib.h>\r
-#include <string.h>\r
-\r
-#ifdef WIN32\r
-\r
-SWITCH_DECLARE(void) switch_dso_destroy(switch_dso_lib_t *lib) {\r
-       if (lib && *lib) {\r
-               FreeLibrary(*lib);\r
-               *lib = NULL;\r
-       }\r
-}\r
-\r
-SWITCH_DECLARE(switch_dso_lib_t) switch_dso_open(const char *path, int global, char **err) {\r
-    HINSTANCE lib;\r
-       \r
-       lib = LoadLibraryEx(path, NULL, 0);\r
-\r
-       if (!lib) {\r
-               LoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);\r
-       }\r
-\r
-       if (!lib) {\r
-               DWORD error = GetLastError();\r
-               *err = switch_mprintf("dll open error [%ul]\n", error);\r
-       }\r
-\r
-       return lib;\r
-}\r
-\r
-SWITCH_DECLARE(switch_dso_func_t) switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {\r
-       FARPROC func = GetProcAddress(lib, sym);\r
-       if (!func) {\r
-               DWORD error = GetLastError();\r
-               *err = switch_mprintf("dll sym error [%ul]\n", error);\r
-       }\r
-       return (switch_dso_func_t)func;\r
-}\r
-\r
-SWITCH_DECLARE(void *) switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err) {\r
-       FARPROC addr = GetProcAddress(lib, sym);\r
-       if (!addr) {\r
-               DWORD error = GetLastError();\r
-               *err = switch_mprintf("dll sym error [%ul]\n", error);\r
-       }\r
-       return (void *)(intptr_t)addr;\r
-}\r
-\r
-\r
-#else\r
-/*\r
-** {========================================================================\r
-** This is an implementation of loadlib based on the dlfcn interface.\r
-** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,\r
-** NetBSD, AIX 4.2, HPUX 11, and  probably most other Unix flavors, at least\r
-** as an emulation layer on top of native functions.\r
-** =========================================================================\r
-*/\r
-\r
-\r
-#include <dlfcn.h>\r
-\r
-void switch_dso_destroy(switch_dso_lib_t *lib) {\r
-       if (lib && *lib) {\r
-               dlclose(*lib);\r
-               *lib = NULL;\r
-       }\r
-}\r
-\r
-switch_dso_lib_t switch_dso_open(const char *path, int global, char **err) {\r
-       void *lib;\r
-       \r
-       if (global) {\r
-               lib = dlopen(path, RTLD_NOW | RTLD_GLOBAL);\r
-       } else {\r
-               lib = dlopen(path, RTLD_NOW | RTLD_LOCAL);\r
-       }\r
-\r
-       if (lib == NULL) {\r
-               const char *dlerr = dlerror();\r
-               /* Work around broken uclibc returning NULL on both dlopen() and dlerror() */\r
-               if (dlerr) {\r
-                       *err = strdup(dlerr);\r
-               } else {\r
-                       *err = strdup("Unknown error");\r
-               }\r
-       }\r
-       return lib;\r
-}\r
-\r
-switch_dso_func_t switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {\r
-       void *func = dlsym(lib, sym);\r
-       if (!func) {\r
-               *err = strdup(dlerror());\r
-       }\r
-       return (switch_dso_func_t)(intptr_t)func;\r
-}\r
-\r
-void *switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err) {\r
-       void *addr = dlsym(lib, sym);\r
-       if (!addr) {\r
-               *err = strdup(dlerror());\r
-       }\r
-       return addr;\r
-}\r
-\r
-#endif\r
-/* }====================================================== */\r
-\r
-/* For Emacs:\r
- * Local Variables:\r
- * mode:c\r
- * indent-tabs-mode:t\r
- * tab-width:4\r
- * c-basic-offset:4\r
- * End:\r
- * For VIM:\r
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4\r
- */\r
+/* 
+ * Cross Platform dso/dll load abstraction
+ * Copyright(C) 2008 Michael Jerris
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so.
+ *
+ * This work is provided under this license on an "as is" basis, without warranty of any kind,
+ * either expressed or implied, including, without limitation, warranties that the covered code
+ * is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire
+ * risk as to the quality and performance of the covered code is with you. Should any covered
+ * code prove defective in any respect, you (not the initial developer or any other contributor)
+ * assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty
+ * constitutes an essential part of this license. No use of any covered code is authorized hereunder
+ * except under this disclaimer. 
+ *
+ */
+
+#include <switch.h>
+#include "switch_dso.h"
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef WIN32
+
+SWITCH_DECLARE(void) switch_dso_destroy(switch_dso_lib_t *lib) {
+       if (lib && *lib) {
+               FreeLibrary(*lib);
+               *lib = NULL;
+       }
+}
+
+SWITCH_DECLARE(switch_dso_lib_t) switch_dso_open(const char *path, int global, char **err) {
+    HINSTANCE lib;
+       
+       lib = LoadLibraryEx(path, NULL, 0);
+
+       if (!lib) {
+               LoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
+       }
+
+       if (!lib) {
+               DWORD error = GetLastError();
+               *err = switch_mprintf("dll open error [%ul]\n", error);
+       }
+
+       return lib;
+}
+
+SWITCH_DECLARE(switch_dso_func_t) switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+       FARPROC func = GetProcAddress(lib, sym);
+       if (!func) {
+               DWORD error = GetLastError();
+               *err = switch_mprintf("dll sym error [%ul]\n", error);
+       }
+       return (switch_dso_func_t)func;
+}
+
+SWITCH_DECLARE(void *) switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+       FARPROC addr = GetProcAddress(lib, sym);
+       if (!addr) {
+               DWORD error = GetLastError();
+               *err = switch_mprintf("dll sym error [%ul]\n", error);
+       }
+       return (void *)(intptr_t)addr;
+}
+
+
+#else
+/*
+** {========================================================================
+** This is an implementation of loadlib based on the dlfcn interface.
+** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,
+** NetBSD, AIX 4.2, HPUX 11, and  probably most other Unix flavors, at least
+** as an emulation layer on top of native functions.
+** =========================================================================
+*/
+
+
+#include <dlfcn.h>
+
+void switch_dso_destroy(switch_dso_lib_t *lib) {
+       if (lib && *lib) {
+               dlclose(*lib);
+               *lib = NULL;
+       }
+}
+
+switch_dso_lib_t switch_dso_open(const char *path, int global, char **err) {
+       void *lib;
+       
+       if (global) {
+               lib = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
+       } else {
+               lib = dlopen(path, RTLD_NOW | RTLD_LOCAL);
+       }
+
+       if (lib == NULL) {
+               const char *dlerr = dlerror();
+               /* Work around broken uclibc returning NULL on both dlopen() and dlerror() */
+               if (dlerr) {
+                       *err = strdup(dlerr);
+               } else {
+                       *err = strdup("Unknown error");
+               }
+       }
+       return lib;
+}
+
+switch_dso_func_t switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+       void *func = dlsym(lib, sym);
+       if (!func) {
+               *err = strdup(dlerror());
+       }
+       return (switch_dso_func_t)(intptr_t)func;
+}
+
+void *switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+       void *addr = dlsym(lib, sym);
+       if (!addr) {
+               *err = strdup(dlerror());
+       }
+       return addr;
+}
+
+#endif
+/* }====================================================== */
+
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:t
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4
+ */