diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2016-10-04 05:27:04 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2016-10-04 05:27:04 -0500 |
commit | 0912f6890925a9e9aa552fb841f9162ea6bd3d70 (patch) | |
tree | 43800f360d677b163f745badc11bde81ea810b3c /pthread.c | |
parent | 6b43a6a6c1f238b5ddea05964e19de86fe2fcda1 (diff) | |
download | gcompat-0912f6890925a9e9aa552fb841f9162ea6bd3d70.tar.gz gcompat-0912f6890925a9e9aa552fb841f9162ea6bd3d70.tar.bz2 gcompat-0912f6890925a9e9aa552fb841f9162ea6bd3d70.tar.xz gcompat-0912f6890925a9e9aa552fb841f9162ea6bd3d70.zip |
Add some new interfaces
Diffstat (limited to 'pthread.c')
-rw-r--r-- | pthread.c | 31 |
1 files changed, 31 insertions, 0 deletions
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 <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; +} |