Alter the prototype of qsort_r(3) to match POSIX, which adopted the
authorEd Schouten <ed@FreeBSD.org>
Fri, 30 Sep 2022 22:26:30 +0000 (15:26 -0700)
committerXin LI <delphij@FreeBSD.org>
Fri, 30 Sep 2022 22:26:30 +0000 (15:26 -0700)
commitaf3c78886fd8d4ca5eebdbe581a459a6f6d29d6a
tree9ff804d16ae1d811e013a58e71f8c824c2ff2488
parent69d79ceb2c01931c129c5bafc300c33f3e106efd
Alter the prototype of qsort_r(3) to match POSIX, which adopted the
glibc-based interface.

Unfortunately, the glibc maintainers, despite knowing the existence
of the FreeBSD qsort_r(3) interface in 2004 and refused to add the
same interface to glibc based on grounds of the lack of standardization
and portability concerns, has decided it was a good idea to introduce
their own qsort_r(3) interface in 2007 as a GNU extension with a
slightly different and incompatible interface.

With the adoption of their interface as POSIX standard, let's switch
to the same prototype, there is no need to remain incompatible.

C++ and C applications written for the historical FreeBSD interface
get source level compatibility when building in C++ mode, or when
building with a C compiler with C11 generics support, provided that
the caller passes a fifth parameter of qsort_r() that exactly matches
the historical FreeBSD comparator function pointer type and does not
redefine the historical qsort_r(3) prototype in their source code.

Symbol versioning is used to keep old binaries working.

MFC: never
Relnotes: yes
Reviewed by: cem, imp, hps, pauamma
Differential revision: https://reviews.freebsd.org/D17083
19 files changed:
include/stdlib.h
lib/libc/gen/scandir-compat11.c
lib/libc/gen/scandir.c
lib/libc/stdlib/Makefile.inc
lib/libc/stdlib/Symbol.map
lib/libc/stdlib/qsort.3
lib/libc/stdlib/qsort.c
lib/libc/stdlib/qsort_r.c
lib/libc/stdlib/qsort_r_compat.c [copied from lib/libc/stdlib/qsort_r.c with 75% similarity]
lib/libc/tests/stdlib/Makefile
lib/libc/tests/stdlib/qsort_r_compat_test.c [copied from lib/libc/tests/stdlib/qsort_r_test.c with 93% similarity]
lib/libc/tests/stdlib/qsort_r_test.c
lib/libproc/proc_sym.c
sys/compat/linuxkpi/common/src/linux_compat.c
sys/dev/bhnd/nvram/bhnd_nvram_store_subr.c
sys/dev/drm2/drm_linux_list_sort.c
sys/libkern/qsort.c
sys/netgraph/ng_ppp.c
sys/sys/libkern.h