
We cannot just look for any declaration of qsort_r, because some operating systems have a qsort_r that has a different prototype but which still has a pair of pointers in the right places (the last two args are interchanged): so use AC_LINK_IFELSE to check for both known variants of qsort_r(), and swap their args into a consistent order in a suitable inline function. (The code for this is taken almost unchanged from gnulib.) (Now we are not using AC_LIBOBJ any more, we can use a better name for the qsort_r replacement as well.) libctf/ * qsort_r.c: Rename to... * ctf-qsort_r.c: ... this. (_quicksort): Define to ctf_qsort_r. * ctf-decls.h (qsort_r): Remove. (ctf_qsort_r): Add. (struct ctf_qsort_arg): New, transport the real ARG and COMPAR. (ctf_qsort_compar_thunk): Rearrange the arguments to COMPAR. * Makefile.am (libctf_a_LIBADD): Remove. (libctf_a_SOURCES): New, add ctf-qsort_r.c. * ctf-archive.c (ctf_arc_write): Call ctf_qsort_r, not qsort_r. * ctf-create.c (ctf_update): Likewise. * configure.ac: Check for BSD versus GNU qsort_r signature. * Makefile.in: Regenerate. * config.h.in: Likewise. * configure: Likewise.
70 lines
1.9 KiB
C
70 lines
1.9 KiB
C
/* Declarations for missing functions.
|
|
Copyright (C) 2019 Free Software Foundation, Inc.
|
|
|
|
This file is part of libctf.
|
|
|
|
libctf is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free
|
|
Software Foundation; either version 3, 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 General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; see the file COPYING. If not see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef _CTF_DECLS_H
|
|
#define _CTF_DECLS_H
|
|
|
|
#include "config.h"
|
|
|
|
#include <stddef.h>
|
|
#include <stdlib.h>
|
|
|
|
#if HAVE_QSORT_R_ARG_LAST
|
|
static inline void
|
|
ctf_qsort_r (void *base, size_t nmemb, size_t size,
|
|
int (*compar)(const void *, const void *, void *),
|
|
void *arg)
|
|
{
|
|
qsort_r (base, nmemb, size, compar, arg);
|
|
}
|
|
#elif HAVE_QSORT_R_COMPAR_LAST
|
|
struct ctf_qsort_arg
|
|
{
|
|
int (*compar) (const void *, const void *, void *);
|
|
void *arg;
|
|
};
|
|
|
|
static int
|
|
ctf_qsort_compar_thunk (void *arg, const void *a, const void *b)
|
|
{
|
|
struct ctf_qsort_arg *qsort_arg = (struct ctf_qsort_arg *) arg;
|
|
|
|
return qsort_arg->compar (a, b, arg);
|
|
}
|
|
|
|
static inline void
|
|
ctf_qsort_r (void *base, size_t nmemb, size_t size,
|
|
int (*compar)(const void *, const void *, void *),
|
|
void *arg)
|
|
{
|
|
struct ctf_qsort_arg thunk = { compar, arg };
|
|
qsort_r (base, nmemb, size, &thunk, ctf_qsort_compar_thunk);
|
|
}
|
|
#else
|
|
void ctf_qsort_r (void *base, size_t nmemb, size_t size,
|
|
int (*compar)(const void *, const void *, void *),
|
|
void *arg);
|
|
#endif
|
|
|
|
#undef MAX
|
|
#undef MIN
|
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
|
|
#endif /* _CTF_DECLS_H */
|