[libc] Deprecate LLVM_ENABLE_PROJECTS in favor of LLVM_ENABLE_RUNTIMES. (#117265)
[llvm-project.git] / libc / src / pthread / pthread_getname_np.cpp
blob8df3ae2458621fc75b0d58090c6fcd17da0b3d4f
1 //===-- Linux implementation of the pthread_setname_np function -----------===//
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 "pthread_getname_np.h"
11 #include "src/__support/CPP/span.h"
12 #include "src/__support/CPP/stringstream.h"
13 #include "src/__support/common.h"
14 #include "src/__support/macros/config.h"
15 #include "src/__support/threads/thread.h"
17 #include <pthread.h>
18 #include <stddef.h>
20 namespace LIBC_NAMESPACE_DECL {
22 static_assert(sizeof(pthread_t) == sizeof(LIBC_NAMESPACE::Thread),
23 "Mismatch between pthread_t and internal Thread.");
25 LLVM_LIBC_FUNCTION(int, pthread_getname_np,
26 (pthread_t th, char *buf, size_t len)) {
27 auto *thread = reinterpret_cast<LIBC_NAMESPACE::Thread *>(&th);
28 cpp::span<char> name_buf(buf, len);
29 cpp::StringStream name_stream(name_buf);
30 return thread->get_name(name_stream);
33 } // namespace LIBC_NAMESPACE_DECL