]> git.sesse.net Git - vlc/commitdiff
Replace posix_memalign()
authorRémi Denis-Courmont <remi@remlab.net>
Wed, 29 Feb 2012 16:59:54 +0000 (18:59 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Wed, 29 Feb 2012 16:59:54 +0000 (18:59 +0200)
compat/posix_memalign.c [new file with mode: 0644]
configure.ac
include/vlc_common.h
include/vlc_fixups.h

diff --git a/compat/posix_memalign.c b/compat/posix_memalign.c
new file mode 100644 (file)
index 0000000..cd89a0f
--- /dev/null
@@ -0,0 +1,55 @@
+/*****************************************************************************
+ * posix_memalign.c: POSIX posix_memalign() replacement
+ *****************************************************************************
+ * Copyright © 2012 Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <errno.h>
+
+#ifndef WIN32
+#include <malloc.h>
+
+static int check_align (size_t align)
+{
+    for (size_t i = sizeof (void *); i != 0; i *= 2)
+        if (align == i)
+            return 0;
+    return EINVAL;
+}
+
+int posix_memalign (void **ptr, size_t align, size_t size)
+{
+    if (check_align (align))
+        return EINVAL;
+
+    int saved_errno = errno;
+    void *p = memalign (align, size);
+    if (p == NULL)
+    {
+        errno = saved_errno;
+        return ENOMEM;
+    }
+
+    *ptr = p;
+    return 0;
+}
+#endif
index efb2e99326351f584f5da87e3d3e1c6b8f61a5b9..5918a08a97ce690391f128d732e3e539c0ecf568 100644 (file)
@@ -491,7 +491,7 @@ need_libc=false
 dnl Check for usual libc functions
 AC_CHECK_DECLS([nanosleep],,,[#include <time.h>])
 AC_CHECK_FUNCS([daemon fcntl fstatvfs fork getenv getpwuid_r if_nameindex if_nametoindex isatty lstat memalign mmap openat pread posix_fadvise posix_madvise setlocale stricmp strnicmp strptime uselocale])
-AC_REPLACE_FUNCS([atof atoll dirfd fdopendir flockfile fsync getdelim getpid gmtime_r inet_pton lldiv localtime_r nrand48 poll rewind setenv strcasecmp strcasestr strdup strlcpy strncasecmp strndup strnlen strsep strtof strtok_r strtoll swab tdestroy strverscmp])
+AC_REPLACE_FUNCS([atof atoll dirfd fdopendir flockfile fsync getdelim getpid gmtime_r inet_pton lldiv localtime_r nrand48 poll posix_memalign rewind setenv strcasecmp strcasestr strdup strlcpy strncasecmp strndup strnlen strsep strtof strtok_r strtoll swab tdestroy strverscmp])
 AC_CHECK_FUNCS(fdatasync,,
   [AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])
 ])
index 545b1cd08b3ae0ecfecd26e4db64778838ccd214..5cb0adf12b62e9ea59942a19d0cde5c697f769c2 100644 (file)
@@ -904,9 +904,6 @@ static void vlc_free(void *ptr)
     if (ptr)
         free((char*)ptr - ((char*)ptr)[-1]);
 }
-#elif defined(__ANDROID__)
-# define vlc_memalign(align, size) memalign(align, size)
-# define vlc_free(base) free(base)
 #else
 static inline void *vlc_memalign(size_t align, size_t size)
 {
index 9b6ac2159bc9abcedd2f788b4c50596ed91381a6..d91e155e501c14212f90f59c456c5faace24d8c5 100644 (file)
@@ -48,7 +48,8 @@ typedef struct
 # include <stdio.h> /* FILE */
 #endif
 
-#if !defined (HAVE_STRLCPY) || \
+#if !defined (HAVE_POSIX_MEMALIGN) || \
+    !defined (HAVE_STRLCPY) || \
     !defined (HAVE_STRNDUP) || \
     !defined (HAVE_STRNLEN)
 # include <stddef.h> /* size_t */
@@ -212,6 +213,10 @@ int setenv (const char *, const char *, int);
 int unsetenv (const char *);
 #endif
 
+#ifndef HAVE_POSIX_MEMALIGN
+int posix_memalign (void **, size_t, size_t);
+#endif
+
 /* locale.h */
 #ifndef HAVE_USELOCALE
 #define LC_NUMERIC_MASK  0