summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2012-03-24 14:43:21 +0100
committerJelmer Vernooij <jelmer@samba.org>2012-03-24 14:43:21 +0100
commitd4c4cb06c52f6ded7d55d75201fb2107e76c1586 (patch)
tree6f71526793427e4a3f093e07508f2e75eba43196
parent1080483319d4eb7a8cdee767fc41f7258e0e2537 (diff)
downloadsamba-d4c4cb06c52f6ded7d55d75201fb2107e76c1586.tar.gz
samba-d4c4cb06c52f6ded7d55d75201fb2107e76c1586.tar.bz2
samba-d4c4cb06c52f6ded7d55d75201fb2107e76c1586.zip
replace: Move memalign() from lib/util/system.c to libreplace.
-rw-r--r--lib/replace/libreplace.m43
-rw-r--r--lib/replace/replace.c32
-rw-r--r--lib/replace/replace.h9
-rw-r--r--lib/replace/wscript4
-rw-r--r--lib/util/system.c35
-rw-r--r--source3/lib/util_malloc.c2
6 files changed, 46 insertions, 39 deletions
diff --git a/lib/replace/libreplace.m4 b/lib/replace/libreplace.m4
index e14fadabf1..72de91799c 100644
--- a/lib/replace/libreplace.m4
+++ b/lib/replace/libreplace.m4
@@ -121,9 +121,10 @@ AC_CHECK_HEADERS(stdarg.h vararg.h)
AC_CHECK_HEADERS(sys/mount.h mntent.h)
AC_CHECK_HEADERS(stropts.h)
AC_CHECK_HEADERS(unix.h)
+AC_CHECK_HEADERS(malloc.h)
AC_CHECK_FUNCS(seteuid setreuid setresuid setegid setregid setresgid)
-AC_CHECK_FUNCS(chroot bzero strerror strerror_r)
+AC_CHECK_FUNCS(chroot bzero strerror strerror_r memalign posix_memalign getpagesize)
AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
AC_CHECK_FUNCS(waitpid wait4 strlcpy strlcat initgroups memmove strdup)
AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp dup2 dprintf vdprintf)
diff --git a/lib/replace/replace.c b/lib/replace/replace.c
index d9a96ff8ef..f1454cbcd6 100644
--- a/lib/replace/replace.c
+++ b/lib/replace/replace.c
@@ -828,3 +828,35 @@ int rep_clock_gettime(clockid_t clk_id, struct timespec *tp)
return 0;
}
#endif
+
+#ifndef HAVE_MEMALIGN
+void *rep_memalign( size_t align, size_t size )
+{
+#if defined(HAVE_POSIX_MEMALIGN)
+ void *p = NULL;
+ int ret = posix_memalign( &p, align, size );
+ if ( ret == 0 )
+ return p;
+
+ return NULL;
+#else
+ /* 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 functionality not available on this platform!\n"));
+ return NULL;
+ }
+ if (size < pagesize) {
+ size = pagesize;
+ }
+ return malloc(size);
+#endif
+}
+#endif
diff --git a/lib/replace/replace.h b/lib/replace/replace.h
index 711241462e..3f289d7f47 100644
--- a/lib/replace/replace.h
+++ b/lib/replace/replace.h
@@ -56,6 +56,10 @@
#include <inttypes.h>
#endif
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
#ifndef __PRI64_PREFIX
# if __WORDSIZE == 64
# define __PRI64_PREFIX "l"
@@ -157,6 +161,11 @@ void *rep_memmem(const void *haystack, size_t haystacklen,
const void *needle, size_t needlelen);
#endif
+#ifndef HAVE_MEMALIGN
+#define memalign rep_memalign
+void *rep_memalign(size_t boundary, size_t size);
+#endif
+
#ifndef HAVE_MKTIME
#define mktime rep_mktime
/* prototype is in "system/time.h" */
diff --git a/lib/replace/wscript b/lib/replace/wscript
index 63944c3800..e1dc1e6a30 100644
--- a/lib/replace/wscript
+++ b/lib/replace/wscript
@@ -69,7 +69,7 @@ def configure(conf):
conf.CHECK_HEADERS('valgrind.h valgrind/valgrind.h valgrind/memcheck.h')
conf.CHECK_HEADERS('nss_common.h nsswitch.h ns_api.h')
conf.CHECK_HEADERS('sys/extattr.h sys/ea.h sys/proplist.h sys/cdefs.h')
- conf.CHECK_HEADERS('utmp.h utmpx.h lastlog.h')
+ conf.CHECK_HEADERS('utmp.h utmpx.h lastlog.h malloc.h')
conf.CHECK_HEADERS('syscall.h sys/syscall.h inttypes.h')
conf.CHECK_TYPES('"long long" intptr_t uintptr_t ptrdiff_t comparison_fn_t')
@@ -168,7 +168,7 @@ def configure(conf):
conf.CHECK_FUNCS('strtok_r mkdtemp dup2 dprintf vdprintf isatty chown lchown')
conf.CHECK_FUNCS('link readlink symlink realpath snprintf vsnprintf')
conf.CHECK_FUNCS('asprintf vasprintf setenv unsetenv strnlen strtoull __strtoull')
- conf.CHECK_FUNCS('strtouq strtoll __strtoll strtoq')
+ conf.CHECK_FUNCS('strtouq strtoll __strtoll strtoq memalign posix_memalign')
# libbsd on some platforms provides strlcpy and strlcat
if not conf.CHECK_FUNCS('strlcpy strlcat'):
diff --git a/lib/util/system.c b/lib/util/system.c
index 8625229404..ab0f1dc6c4 100644
--- a/lib/util/system.c
+++ b/lib/util/system.c
@@ -39,41 +39,6 @@
expansions/etc make sense to the OS should be acceptable to Samba.
*/
-/*******************************************************************
- A wrapper for memalign
-********************************************************************/
-
-void *sys_memalign( size_t align, size_t size )
-{
-#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
- /* 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 malloc(size);
-#endif
-}
/**************************************************************************
Wrapper for fork. Ensures we clear our pid cache.
diff --git a/source3/lib/util_malloc.c b/source3/lib/util_malloc.c
index c052adc41b..d773d8ffd6 100644
--- a/source3/lib/util_malloc.c
+++ b/source3/lib/util_malloc.c
@@ -79,7 +79,7 @@ void *memalign_array(size_t el_size, size_t align, unsigned int count)
return NULL;
}
- return sys_memalign(align, el_size*count);
+ return memalign(align, el_size*count);
}
/****************************************************************************