Index: /trunk/src/lib/restartable-syscall-wrappers.c
===================================================================
--- /trunk/src/lib/restartable-syscall-wrappers.c	(revision 2445)
+++ /trunk/src/lib/restartable-syscall-wrappers.c	(revision 2446)
@@ -58,11 +58,4 @@
 #endif
 
-/** Optional '64' suffix string for dlsym.  */
-#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
-# define SYM_64_SUFFIX "64"
-#else
-# define SYM_64_SUFFIX ""
-#endif
-
 /** Mangle a syscall name with optional '64' suffix. */
 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
@@ -79,4 +72,10 @@
 #endif
 
+/** Used by XSTR. */
+#define XSTR_INNER(x)   #x
+/** Returns the expanded argument as a string. */
+#define XSTR(x)         XSTR_INNER(x)
+
+
 
 extern int WRAP64(open)(const char *pszName, int fFlags, ...);
@@ -155,4 +154,17 @@
     void        *pvLibc;
     void        *pvSym;
+
+    /*
+     * Use the RTLD_NEXT dl feature if present, it's designed for doing
+     * exactly what we want here.
+     */
+#ifdef RTLD_NEXT
+    pvSym = dlsym(RTLD_NEXT, pszSymbol);
+    if (pvSym)
+    {
+        *ppvSym = pvSym;
+        return 0;
+    }
+#endif
 
     /*
@@ -163,7 +175,12 @@
     {
 #ifdef RTLD_NOLOAD
-        pvLibc = dlopen("/libc/libc.so", RTLD_NOLOAD);
-#else
-        pvLibc = dlopen("/libc/libc.so", RTLD_GLOBAL);
+        unsigned fFlags = RTLD_NOLOAD | RTLD_NOW;
+#else
+        unsigned fFlags = RTLD_GLOBAL | RTLD_NOW;
+#endif
+#ifdef KBUILD_OS_LINUX
+        pvLibc = dlopen("/lib/libc.so.6", fFlags);
+#else
+        pvLibc = dlopen("/lib/libc.so", fFlags);
 #endif
         if (!pvLibc)
@@ -197,20 +214,38 @@
     static union
     {
-        FILE *(* pfnFopen)(const char *, const char *);
+        FILE *(* pfnFOpen)(const char *, const char *);
         void *pvSym;
     } s_u;
     FILE *pFile;
 
-    if (   !s_u.pfnFopen
-        && dlsym_libc("fopen" SYM_64_SUFFIX, &s_u.pvSym) != 0)
+    if (   !s_u.pfnFOpen
+        && dlsym_libc("fopen", &s_u.pvSym) != 0)
         return NULL;
 
     do
-        pFile = s_u.pfnFopen(pszName, pszMode);
+        pFile = s_u.pfnFOpen(pszName, pszMode);
     while (!pFile && SHOULD_RESTART());
     return pFile;
 }
 
+FILE *fopen64(const char *pszName, const char *pszMode)
+{
+    static union
+    {
+        FILE *(* pfnFOpen64)(const char *, const char *);
+        void *pvSym;
+    } s_u;
+    FILE *pFile;
+
+    if (   !s_u.pfnFOpen64
+        && dlsym_libc("fopen64", &s_u.pvSym) != 0)
+        return NULL;
+
+    do
+        pFile = s_u.pfnFOpen64(pszName, pszMode);
+    while (!pFile && SHOULD_RESTART());
+    return pFile;
+}
+
 /** @todo chmod, chown, chgrp, times, and possible some more. */
 
-
