[libc++][Android] Allow testing libc++ with clang-r536225 (#116149)
[llvm-project.git] / libc / src / stdlib / qsort_r.cpp
blobbf61a40e847341fcfecf3593844163bd9071a5ee
1 //===-- Implementation of qsort_r -----------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "src/stdlib/qsort_r.h"
10 #include "src/__support/common.h"
11 #include "src/__support/macros/config.h"
12 #include "src/stdlib/qsort_util.h"
14 #include <stdint.h>
16 namespace LIBC_NAMESPACE_DECL {
18 LLVM_LIBC_FUNCTION(void, qsort_r,
19 (void *array, size_t array_size, size_t elem_size,
20 int (*compare)(const void *, const void *, void *),
21 void *arg)) {
22 if (array == nullptr || array_size == 0 || elem_size == 0)
23 return;
24 internal::Comparator c(compare, arg);
25 auto arr = internal::Array(reinterpret_cast<uint8_t *>(array), array_size,
26 elem_size, c);
28 internal::sort(arr);
31 } // namespace LIBC_NAMESPACE_DECL