--- /dev/null
+/*****************************************************************************
+ * 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
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.])
])
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)
{
# 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 */
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