vlc | branch: master | Thomas Guillem <[email protected]> | Mon Jan 21 16:42:29 2019 +0100| [aa1f89e91f5c5b3c9573cd0d0c9f5da63cdcc0a6] | committer: Thomas Guillem
posix: implement vlc_qsort > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=aa1f89e91f5c5b3c9573cd0d0c9f5da63cdcc0a6 --- src/Makefile.am | 4 ++++ src/posix/sort.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/src/Makefile.am b/src/Makefile.am index 5defc9bff7..dc5f2bb238 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -449,6 +449,10 @@ libvlccore_la_SOURCES += \ linux/dirs.c \ linux/thread.c else + +# All except OS2/WIN32/NACL/ANDROID +libvlccore_la_SOURCES += posix/sort.c + if HAVE_DARWIN libvlccore_la_SOURCES += \ darwin/dirs.c \ diff --git a/src/posix/sort.c b/src/posix/sort.c new file mode 100644 index 0000000000..b3d5abc99b --- /dev/null +++ b/src/posix/sort.c @@ -0,0 +1,63 @@ +/****************************************************************************** + * sort.c: POSIX sort back-end + ****************************************************************************** + * Copyright © 2019 VLC authors and VideoLAN + * + * 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 <vlc_common.h> +#include <vlc_sort.h> + +#ifdef HAVE_BROKEN_QSORT_R + +struct compat_arg +{ + int (*compar)(const void *, const void *, void *); + void *arg; +}; + +static int compar_compat(void *arg, const void *a, const void *b) +{ + struct compat_arg *compat_arg = arg; + return compat_arg->compar(a, b, compat_arg->arg); +} + +/* Follow the FreeBSD prototype */ +void vlc_qsort(void *base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *, void *), + void *arg) +{ + struct compat_arg compat_arg = { + .compar = compar, + .arg = arg + }; + qsort_r(base, nmemb, size, &compat_arg, compar_compat); +} + +#else + +/* Follow the POSIX prototype */ +void vlc_qsort(void *base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *, void *), + void *arg) +{ + qsort_r(base, nmemb, size, compar, arg); +} +#endif _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
