summaryrefslogtreecommitdiff
path: root/libgcompat/pthread.c
diff options
context:
space:
mode:
authorWilliam Pitcock <nenolod@dereferenced.org>2017-06-14 13:09:23 -0500
committerWilliam Pitcock <nenolod@dereferenced.org>2017-06-14 13:09:23 -0500
commitf67416822a54109bd9cfa0fd210d7d8f53412ced (patch)
tree7d3d14933f39ca160d706d1bec25ce541a188962 /libgcompat/pthread.c
parent2b58008b911d9dc8354b9001e22b594fa6456dd1 (diff)
downloadgcompat-f67416822a54109bd9cfa0fd210d7d8f53412ced.tar.gz
gcompat-f67416822a54109bd9cfa0fd210d7d8f53412ced.tar.bz2
gcompat-f67416822a54109bd9cfa0fd210d7d8f53412ced.tar.xz
gcompat-f67416822a54109bd9cfa0fd210d7d8f53412ced.zip
move all compatibility library stuff into libgcompat/
Diffstat (limited to 'libgcompat/pthread.c')
-rw-r--r--libgcompat/pthread.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/libgcompat/pthread.c b/libgcompat/pthread.c
new file mode 100644
index 0000000..b4ea054
--- /dev/null
+++ b/libgcompat/pthread.c
@@ -0,0 +1,31 @@
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+/* "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;
+}