summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib')
-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
}
/****************************************************************************