6 #include "pthread_impl.h"
8 int pthread_getname_np(pthread_t thread, char *name, size_t len)
10 int fd, cs, status = 0;
11 char f[sizeof "/proc/self/task//comm" + 3*sizeof(int)];
13 if (len < 16) return ERANGE;
15 if (thread == pthread_self())
16 return prctl(PR_GET_NAME, (unsigned long)name, 0UL, 0UL, 0UL) ? errno : 0;
18 snprintf(f, sizeof f, "/proc/self/task/%d/comm", thread->tid);
19 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
20 if ((fd = open(f, O_RDONLY|O_CLOEXEC)) < 0 || (len = read(fd, name, len)) < 0) status = errno;
21 else name[len-1] = 0; /* remove trailing new line only if successful */
22 if (fd >= 0) close(fd);
23 pthread_setcancelstate(cs, 0);