Commit 66b10200 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Replace posix_memalign()

parent cdf21929
/*****************************************************************************
* 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
...@@ -491,7 +491,7 @@ need_libc=false ...@@ -491,7 +491,7 @@ need_libc=false
dnl Check for usual libc functions dnl Check for usual libc functions
AC_CHECK_DECLS([nanosleep],,,[#include <time.h>]) 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_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_CHECK_FUNCS(fdatasync,,
[AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.]) [AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])
]) ])
......
...@@ -904,9 +904,6 @@ static void vlc_free(void *ptr) ...@@ -904,9 +904,6 @@ static void vlc_free(void *ptr)
if (ptr) if (ptr)
free((char*)ptr - ((char*)ptr)[-1]); free((char*)ptr - ((char*)ptr)[-1]);
} }
#elif defined(__ANDROID__)
# define vlc_memalign(align, size) memalign(align, size)
# define vlc_free(base) free(base)
#else #else
static inline void *vlc_memalign(size_t align, size_t size) static inline void *vlc_memalign(size_t align, size_t size)
{ {
......
...@@ -48,7 +48,8 @@ typedef struct ...@@ -48,7 +48,8 @@ typedef struct
# include <stdio.h> /* FILE */ # include <stdio.h> /* FILE */
#endif #endif
#if !defined (HAVE_STRLCPY) || \ #if !defined (HAVE_POSIX_MEMALIGN) || \
!defined (HAVE_STRLCPY) || \
!defined (HAVE_STRNDUP) || \ !defined (HAVE_STRNDUP) || \
!defined (HAVE_STRNLEN) !defined (HAVE_STRNLEN)
# include <stddef.h> /* size_t */ # include <stddef.h> /* size_t */
...@@ -212,6 +213,10 @@ int setenv (const char *, const char *, int); ...@@ -212,6 +213,10 @@ int setenv (const char *, const char *, int);
int unsetenv (const char *); int unsetenv (const char *);
#endif #endif
#ifndef HAVE_POSIX_MEMALIGN
int posix_memalign (void **, size_t, size_t);
#endif
/* locale.h */ /* locale.h */
#ifndef HAVE_USELOCALE #ifndef HAVE_USELOCALE
#define LC_NUMERIC_MASK 0 #define LC_NUMERIC_MASK 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment