vlc | branch: master | Jean-Baptiste Kempf <[email protected]> | Sun Jul 17 21:09:17 2016 +0200| [a051de1ac61c0fea6f72aa3a880248dd85da210b] | committer: Jean-Baptiste Kempf
compat: add memrchr replacement This is a very simple replacement. It probably can be better. Feel free. > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a051de1ac61c0fea6f72aa3a880248dd85da210b --- compat/memrchr.c | 41 +++++++++++++++++++++++++++++++++++++++++ configure.ac | 2 +- include/vlc_fixups.h | 4 ++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/compat/memrchr.c b/compat/memrchr.c new file mode 100644 index 0000000..c7a038c --- /dev/null +++ b/compat/memrchr.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2007 Todd C. Miller <[email protected]> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <string.h> + +/* + * Reverse memchr() + * Find the last occurrence of 'c' in the buffer 's' of size 'n'. + */ +void * +memrchr(const void *s, int c, size_t n) +{ + const unsigned char *cp; + + if (n != 0) { + cp = (unsigned char *)s + n; + do { + if (*(--cp) == (unsigned char)c) + return((void *)cp); + } while (--n != 0); + } + return(NULL); +} diff --git a/configure.ac b/configure.ac index 3c31066..8a855f2 100644 --- a/configure.ac +++ b/configure.ac @@ -584,7 +584,7 @@ need_libc=false dnl Check for usual libc functions AC_CHECK_DECLS([nanosleep],,,[#include <time.h>]) AC_CHECK_FUNCS([daemon fcntl flock fstatvfs fork getenv getpwuid_r isatty lstat memalign mkostemp mmap open_memstream openat pread posix_fadvise posix_madvise setlocale stricmp strnicmp strptime uselocale pthread_cond_timedwait_monotonic_np pthread_condattr_setclock]) -AC_REPLACE_FUNCS([atof atoll dirfd fdopendir ffsll flockfile fsync getdelim getpid lldiv nrand48 poll posix_memalign recvmsg rewind sendmsg setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tdestroy timegm timespec_get strverscmp]) +AC_REPLACE_FUNCS([atof atoll dirfd fdopendir ffsll flockfile fsync getdelim getpid lldiv memrchr nrand48 poll posix_memalign recvmsg rewind sendmsg setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tdestroy timegm timespec_get strverscmp]) AC_REPLACE_FUNCS([gettimeofday]) AC_CHECK_FUNCS(fdatasync,, [AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.]) diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h index 52209dc..d62920a 100644 --- a/include/vlc_fixups.h +++ b/include/vlc_fixups.h @@ -268,6 +268,10 @@ int unsetenv (const char *); int posix_memalign (void **, size_t, size_t); #endif +#ifndef HAVE_MEMRCHR +void *memrchr(const void *, int, size_t); +#endif + /* locale.h */ #ifndef HAVE_USELOCALE #define LC_ALL_MASK 0 _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
