xref: /aosp_15_r20/external/llvm-libc/src/pthread/pthread_attr_getstack.cpp (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1 //===-- Implementation of the pthread_attr_getstack -----------------===//
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 "pthread_attr_getstack.h"
10 #include "pthread_attr_getstacksize.h"
11 
12 #include "src/__support/common.h"
13 #include "src/__support/macros/config.h"
14 #include "src/__support/macros/optimization.h"
15 
16 #include <pthread.h>
17 
18 namespace LIBC_NAMESPACE_DECL {
19 
20 LLVM_LIBC_FUNCTION(int, pthread_attr_getstack,
21                    (const pthread_attr_t *__restrict attr,
22                     void **__restrict stack, size_t *__restrict stacksize)) {
23   // As of writing this `pthread_attr_getstacksize` can never fail.
24   int result = LIBC_NAMESPACE::pthread_attr_getstacksize(attr, stacksize);
25   if (LIBC_UNLIKELY(result != 0))
26     return result;
27   *stack = attr->__stack;
28   return 0;
29 }
30 
31 } // namespace LIBC_NAMESPACE_DECL
32