[vlc-commits] Replace posix_memalign()
Rémi Denis-Courmont
git at videolan.org
Wed Feb 29 18:00:00 CET 2012
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Feb 29 18:59:54 2012 +0200| [66b102008a70402b3ac0b4e92153664ce27a9369] | committer: Rémi Denis-Courmont
Replace posix_memalign()
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=66b102008a70402b3ac0b4e92153664ce27a9369
---
compat/posix_memalign.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++
configure.ac | 2 +-
include/vlc_common.h | 3 --
include/vlc_fixups.h | 7 +++++-
4 files changed, 62 insertions(+), 5 deletions(-)
diff --git a/compat/posix_memalign.c b/compat/posix_memalign.c
new file mode 100644
index 0000000..cd89a0f
--- /dev/null
+++ b/compat/posix_memalign.c
@@ -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
diff --git a/configure.ac b/configure.ac
index efb2e99..5918a08 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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.])
])
diff --git a/include/vlc_common.h b/include/vlc_common.h
index 545b1cd..5cb0adf 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -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)
{
diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
index 9b6ac21..d91e155 100644
--- a/include/vlc_fixups.h
+++ b/include/vlc_fixups.h
@@ -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
More information about the vlc-commits
mailing list