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//===----------------------------------------------------------------------===//
8
9#include "pthread_getname_np.h"
10
11#include "src/__support/CPP/span.h"
12#include "src/__support/CPP/stringstream.h"
13#include "src/__support/common.h"
14#include "src/__support/threads/thread.h"
15
16#include <pthread.h>
17#include <stddef.h>
18
19namespace LIBC_NAMESPACE {
20
21static_assert(sizeof(pthread_t) == sizeof(LIBC_NAMESPACE::Thread),
22 "Mismatch between pthread_t and internal Thread.");
23
24LLVM_LIBC_FUNCTION(int, pthread_getname_np,
25 (pthread_t th, char *buf, size_t len)) {
26 auto *thread = reinterpret_cast<LIBC_NAMESPACE::Thread *>(&th);
27 cpp::span<char> name_buf(buf, len);
28 cpp::StringStream name_stream(name_buf);
29 return thread->get_name(name&: name_stream);
30}
31
32} // namespace LIBC_NAMESPACE
33

source code of libc/src/pthread/pthread_getname_np.cpp