Coverage Report

Created: 2025-07-11 07:16

/src/vlc/src/misc/sort.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 * sort.c: sort back-end
3
 ******************************************************************************
4
 * Copyright © 2019 VLC authors and VideoLAN
5
 * Copyright © 2018 Rémi Denis-Courmont
6
 *
7
 * This program is free software; you can redistribute it and/or modify it
8
 * under the terms of the GNU Lesser General Public License as published by
9
 * the Free Software Foundation; either version 2.1 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License
18
 * along with this program; if not, write to the Free Software Foundation,
19
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20
 *****************************************************************************/
21
22
#ifdef HAVE_CONFIG_H
23
# include <config.h>
24
#endif
25
26
#include <vlc_common.h>
27
#include <vlc_sort.h>
28
29
static thread_local struct
30
{
31
    int (*compar)(const void *, const void *, void *);
32
    void *arg;
33
} state;
34
35
static int compar_wrapper(const void *a, const void *b)
36
0
{
37
0
    return state.compar(a, b, state.arg);
38
0
}
39
40
/* Follow the upcoming POSIX prototype, coming from GNU/libc.
41
 * Note that this differs from the BSD prototype. */
42
43
VLC_WEAK void vlc_qsort(void *base, size_t nmemb, size_t size,
44
                        int (*compar)(const void *, const void *, void *),
45
                        void *arg)
46
0
{
47
0
    int (*saved_compar)(const void *, const void *, void *) = state.compar;
48
0
    void *saved_arg = state.arg;
49
50
0
    state.compar = compar;
51
0
    state.arg = arg;
52
53
0
    qsort(base, nmemb, size, compar_wrapper);
54
55
    /* Restore state for nested reentrant calls */
56
0
    state.compar = saved_compar;
57
0
    state.arg = saved_arg;
58
0
}