[Box Backup-commit] COMMIT r2019 - box/trunk/lib/intercept

boxbackup-dev@fluffy.co.uk boxbackup-dev@fluffy.co.uk
Thu, 3 Jan 2008 22:51:22 +0000 (UTC)


Author: chris
Date: 2008-01-03 22:51:21 +0000 (Thu, 03 Jan 2008)
New Revision: 2019

Modified:
   box/trunk/lib/intercept/intercept.cpp
Log:
Use 64-bit versions of directory functions if we can find them, and if
we're compiling with large file support, otherwise fall back to 32-bit
versions. Hopefully fixes problems with FreeBSD without breaking other
platforms (raidfile tests pass on freebsd).


Modified: box/trunk/lib/intercept/intercept.cpp
===================================================================
--- box/trunk/lib/intercept/intercept.cpp	2008-01-02 13:36:19 UTC (rev 2018)
+++ box/trunk/lib/intercept/intercept.cpp	2008-01-03 22:51:21 UTC (rev 2019)
@@ -405,18 +405,31 @@
 static void * find_function(const char *pName)
 {
 	dlerror();
+	void *result = NULL;
 
-	void *result = dlsym(RTLD_NEXT, pName);
+	#ifdef HAVE_LARGE_FILE_SUPPORT
+	{
+		// search for the 64-bit version first
+		std::string name64(pName);
+		name64 += "64";
+		result = dlsym(RTLD_NEXT, name64.c_str());
+		if (dlerror() == NULL)
+		{
+			return result;
+		}
+	}
+	#endif
+
+	result = dlsym(RTLD_NEXT, pName);
 	const char *errmsg = (const char *)dlerror();
 
-	if (errmsg != NULL)
+	if (errmsg == NULL)
 	{
-		BOX_ERROR("Failed to find real " << pName << " function: " <<
-			errmsg);
-		return NULL;
+		return result;
 	}
 
-	return result;
+	BOX_ERROR("Failed to find real " << pName << " function: " << errmsg);
+	return NULL;
 }
 
 extern "C" 
@@ -457,11 +470,7 @@
 
 	if (readdir_real == NULL)
 	{
-		#ifdef HAVE_LARGE_FILE_SUPPORT
-		readdir_real = (readdir_t*)find_function("readdir64");
-		#else
 		readdir_real = (readdir_t*)find_function("readdir");
-		#endif
 	}
 
 	if (readdir_real == NULL)
@@ -506,17 +515,9 @@
 	if (lstat_real == NULL)
 	{
 	#ifdef LINUX_WEIRD_LSTAT
-		#ifdef HAVE_LARGE_FILE_SUPPORT
-		lstat_real = (lstat_t*)find_function("__lxstat64");
-		#else
 		lstat_real = (lstat_t*)find_function("__lxstat");
-		#endif
 	#else
-		#ifdef HAVE_LARGE_FILE_SUPPORT
-		lstat_real = (lstat_t*)find_function("lstat64");
-		#else
 		lstat_real = (lstat_t*)find_function("lstat");
-		#endif
 	#endif
 	}