From 0912f6890925a9e9aa552fb841f9162ea6bd3d70 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Tue, 4 Oct 2016 05:27:04 -0500 Subject: Add some new interfaces --- pthread.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 pthread.c (limited to 'pthread.c') diff --git a/pthread.c b/pthread.c new file mode 100644 index 0000000..b4ea054 --- /dev/null +++ b/pthread.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* "Now we are all sons of bitches." */ +int pthread_setname_np(pthread_t thread, const char *name) +{ + char path[PATH_MAX]; + int fd; + /* Cthulhu have mercy */ + pid_t *my_pid = (pid_t *)((void *)thread + (sizeof(uintptr_t) * 7)); + size_t len = strlen(name); + + if(len > 15) + { + return -ERANGE; + } + + snprintf(path, PATH_MAX, "/proc/self/tid/%u/name", *my_pid); + fd = open(path, O_RDWR); + write(fd, name, len + 1); + close(fd); + + return 0; +} -- cgit v1.2.3-60-g2f50