diff options
-rw-r--r-- | lib/util/system.c | 39 | ||||
-rw-r--r-- | lib/util/util.h | 2 | ||||
-rw-r--r-- | source3/include/proto.h | 1 | ||||
-rw-r--r-- | source3/lib/system.c | 36 |
4 files changed, 41 insertions, 37 deletions
diff --git a/lib/util/system.c b/lib/util/system.c index 17c0553102..1e80f1a88a 100644 --- a/lib/util/system.c +++ b/lib/util/system.c @@ -22,6 +22,8 @@ #include "system/network.h" #include "system/filesys.h" +#undef malloc + /* The idea is that this file will eventually have wrappers around all important system calls in samba. The aims are: @@ -37,6 +39,42 @@ 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 +} + /************************************************************************** A wrapper for gethostbyname() that tries avoids looking up hostnames in the root domain, which can cause dial-on-demand links to come up for no @@ -189,3 +227,4 @@ _PUBLIC_ int sys_connect(int fd, const struct sockaddr * addr) return connect(fd, addr, salen); } + diff --git a/lib/util/util.h b/lib/util/util.h index 93b181b1fc..d1c5e82bdd 100644 --- a/lib/util/util.h +++ b/lib/util/util.h @@ -115,6 +115,8 @@ void CatchChildLeaveStatus(void); /* The following definitions come from lib/util/system.c */ +void *sys_memalign( size_t align, size_t size ); + /************************************************************************** A wrapper for gethostbyname() that tries avoids looking up hostnames in the root domain, which can cause dial-on-demand links to come up for no diff --git a/source3/include/proto.h b/source3/include/proto.h index 1f094617ad..23654e1ec6 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -352,7 +352,6 @@ int sys_set_nfs_quota(const char *path, const char *bdev, /* The following definitions come from lib/system.c */ -void *sys_memalign( size_t align, size_t size ); int sys_usleep(long usecs); ssize_t sys_read(int fd, void *buf, size_t count); ssize_t sys_write(int fd, const void *buf, size_t count); diff --git a/source3/lib/system.c b/source3/lib/system.c index 292965f47f..0dd4b81a43 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -48,42 +48,6 @@ /******************************************************************* - 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 SMB_MALLOC(size); -#endif -} - -/******************************************************************* A wrapper for usleep in case we don't have one. ********************************************************************/ |