summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-03-06 22:01:03 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:18:26 -0500
commitf76fe23e11110422e98f7c3660dca81dd509e979 (patch)
tree2290d62d0bba69ae515d116cce2b75ba89544cf1
parent640ab28d78dac5c2bcee8b641c8971fcbcd87dfa (diff)
downloadsamba-f76fe23e11110422e98f7c3660dca81dd509e979.tar.gz
samba-f76fe23e11110422e98f7c3660dca81dd509e979.tar.bz2
samba-f76fe23e11110422e98f7c3660dca81dd509e979.zip
r21725: Fix for memalign used without test guards. Was
breaking the build on *BSD's. Tested by Herb. Jeremy. (This used to be commit 4816af5ce9070385b292f666779a24057b39e457)
-rw-r--r--source3/lib/system.c29
-rw-r--r--source3/lib/util.c15
2 files changed, 22 insertions, 22 deletions
diff --git a/source3/lib/system.c b/source3/lib/system.c
index 20b31113ec..eaebc7190f 100644
--- a/source3/lib/system.c
+++ b/source3/lib/system.c
@@ -47,20 +47,35 @@
A wrapper for memalign
********************************************************************/
-void* sys_memalign( size_t align, size_t size )
+void *sys_memalign( size_t align, size_t size )
{
-#if defined(HAVE_MEMALIGN)
- return memalign( align, size );
-#elif defined(HAVE_POSIX_MEMALIGN)
- char *p = NULL;
+#if defined(HAVE_POSIX_MEMALIGN)
+ void *p = NULL;
int ret = posix_memalign( &p, align, size );
if ( ret == 0 )
return p;
return NULL;
+#elif defined(HAVE_MEMALIGN)
+ return memalign( align, size );
#else
- DEBUG(0,("memalign functionalaity not available on this platform!\n"));
- return NULL;
+ /* On *BSD systems memaligns doesn't exist, but memory will
+ * be aligned on allocations of > pagesize. */
+#if defined(SYSCONF_SC_PAGESIZE)
+ size_t pagesize = (size_t)sysconf(_SC_PAGESIZE);
+#elif defined(HAVE_GETPAGESIZE)
+ size_t pagesize = (size_t)getpagesize();
+#else
+ size_t pagesize = (size_t)-1;
+#endif
+ if (pagesize == (size_t)-1) {
+ DEBUG(0,("memalign functionalaity not available on this platform!\n"));
+ return NULL;
+ }
+ if (size < pagesize) {
+ size = pagesize;
+ }
+ return SMB_MALLOC(size);
#endif
}
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 67c9c8d37a..b29f459c02 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -913,17 +913,6 @@ void *malloc_(size_t size)
}
/****************************************************************************
- Internal malloc wrapper. Externally visible.
-****************************************************************************/
-
-void *memalign_(size_t align, size_t size)
-{
-#undef memalign
- return memalign(align, size);
-#define memalign(align, s) __ERROR_DONT_USE_MEMALIGN_DIRECTLY
-}
-
-/****************************************************************************
Internal calloc wrapper. Not externally visible.
****************************************************************************/
@@ -974,11 +963,7 @@ void *memalign_array(size_t el_size, size_t align, unsigned int count)
return NULL;
}
-#if defined(PARANOID_MALLOC_CHECKER)
- return memalign_(align, el_size*count);
-#else
return sys_memalign(align, el_size*count);
-#endif
}
/****************************************************************************