xref: /llvm-project/libc/src/string/strerror_r.cpp (revision 5ff3ff33ff930e4ec49da7910612d8a41eb068cb)
1a9f95b76SMichael Jones //===-- Implementation of strerror_r --------------------------------------===//
2a9f95b76SMichael Jones //
3a9f95b76SMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4a9f95b76SMichael Jones // See https://llvm.org/LICENSE.txt for license information.
5a9f95b76SMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6a9f95b76SMichael Jones //
7a9f95b76SMichael Jones //===----------------------------------------------------------------------===//
8a9f95b76SMichael Jones 
9a9f95b76SMichael Jones #include "src/string/strerror_r.h"
1007793f95SMichael Jones #include "src/__support/StringUtil/error_to_string.h"
11a9f95b76SMichael Jones #include "src/__support/common.h"
12*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
13a9f95b76SMichael Jones 
14a9f95b76SMichael Jones #include <stddef.h>
15a9f95b76SMichael Jones 
16*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
17a9f95b76SMichael Jones 
18a9f95b76SMichael Jones // This is the gnu version of strerror_r. The XSI version may be added later.
19a9f95b76SMichael Jones LLVM_LIBC_FUNCTION(char *, strerror_r,
20a9f95b76SMichael Jones                    (int err_num, char *buf, size_t buflen)) {
21a9f95b76SMichael Jones   return const_cast<char *>(get_error_string(err_num, {buf, buflen}).data());
22a9f95b76SMichael Jones }
23a9f95b76SMichael Jones 
24*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
25