lib/util Move sys_memalign into lib/util/system.c
authorAndrew Bartlett <abartlet@samba.org>
Tue, 31 May 2011 00:41:42 +0000 (10:41 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 31 May 2011 00:57:19 +0000 (02:57 +0200)
lib/util/system.c
lib/util/util.h
source3/include/proto.h
source3/lib/system.c

index 17c0553102b5be3af6df8593354299a135bbd1b9..1e80f1a88a301828913c724b0485e6f77a93e473 100644 (file)
@@ -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:
      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);
 }
+
index 93b181b1fcec91b4d4fdb40f69751bedbf5737fb..d1c5e82bdd7d9682864ee35edc1f9ac94d2449dc 100644 (file)
@@ -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
index 1f094617ad7f777a98d3cb7d5baefad04ecda20d..23654e1ec6e9c7ee96ead6a6e72303ff67b1a0c5 100644 (file)
@@ -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);
index 292965f47fac1f9db4627b67d6163cb81ecea203..0dd4b81a43adeb60d87ef274264131cb89468b68 100644 (file)
 
 
 
-/*******************************************************************
- 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.
 ********************************************************************/