xref: /llvm-project/libc/src/stdlib/qsort.cpp (revision 3f30effe1bd81fa1b039218a9bfe79c3b03fafad)
1 //===-- Implementation of qsort -------------------------------------------===//
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 //===----------------------------------------------------------------------===//
8 
9 #include "src/stdlib/qsort.h"
10 #include "src/__support/common.h"
11 #include "src/__support/macros/config.h"
12 #include "src/stdlib/qsort_util.h"
13 
14 #include <stdint.h>
15 
16 namespace LIBC_NAMESPACE_DECL {
17 
18 LLVM_LIBC_FUNCTION(void, qsort,
19                    (void *array, size_t array_size, size_t elem_size,
20                     int (*compare)(const void *, const void *))) {
21   if (array == nullptr || array_size == 0 || elem_size == 0)
22     return;
23   internal::Comparator c(compare);
24   internal::quicksort(internal::Array(reinterpret_cast<uint8_t *>(array),
25                                       array_size, elem_size, c));
26 }
27 
28 } // namespace LIBC_NAMESPACE_DECL
29