summaryrefslogtreecommitdiff
path: root/libgcompat
diff options
context:
space:
mode:
Diffstat (limited to 'libgcompat')
-rw-r--r--libgcompat/alias.h4
-rw-r--r--libgcompat/internal.h13
-rw-r--r--libgcompat/pthread.c25
-rw-r--r--libgcompat/wchar.c2
4 files changed, 33 insertions, 11 deletions
diff --git a/libgcompat/alias.h b/libgcompat/alias.h
index 3f54672..bb99690 100644
--- a/libgcompat/alias.h
+++ b/libgcompat/alias.h
@@ -1,9 +1,9 @@
#ifndef _ALIAS_H_
#define _ALIAS_H_
-#define alias(old, new) \
+#define alias(old, new) \
extern __typeof(old) new __attribute__((__alias__(#old)))
-#define weak_alias(old, new) \
+#define weak_alias(old, new) \
extern __typeof(old) new __attribute__((weak, __alias__(#old)))
#endif /* _ALIAS_H_ */
diff --git a/libgcompat/internal.h b/libgcompat/internal.h
index 3b08271..a246547 100644
--- a/libgcompat/internal.h
+++ b/libgcompat/internal.h
@@ -3,12 +3,11 @@
void GCOMPAT__panic(const char *fmt, ...) __attribute__((noreturn));
-#define GCOMPAT__assert_with_reason(chk, ...) \
- do { \
- if (!(chk)) { \
- GCOMPAT__panic(__VA_ARGS__); \
- } \
- } \
- while(0);
+#define GCOMPAT__assert_with_reason(chk, ...) \
+ do { \
+ if (!(chk)) { \
+ GCOMPAT__panic(__VA_ARGS__); \
+ } \
+ } while (0);
#endif
diff --git a/libgcompat/pthread.c b/libgcompat/pthread.c
index 4ebbe6b..0456c40 100644
--- a/libgcompat/pthread.c
+++ b/libgcompat/pthread.c
@@ -1,4 +1,8 @@
-#include <pthread.h>
+#define _GNU_SOURCE
+#include <errno.h> /* errno */
+#include <fcntl.h> /* O_CLOEXEC, O_RDONLY */
+#include <pthread.h> /* pthread_atfork */
+#include <unistd.h> /* open, read */
#include "alias.h" /* weak_alias */
@@ -27,3 +31,22 @@ int __register_atfork(void (*prepare)(void), void (*parent)(void),
return pthread_atfork(prepare, parent, child);
}
weak_alias(__register_atfork, register_atfork);
+
+/**
+ * Get the name of a thread.
+ */
+int pthread_getname_np(pthread_t thread, char *name, size_t len)
+{
+ int fd = open("/proc/thread-self/comm", O_RDONLY | O_CLOEXEC);
+ char dummy;
+
+ if (fd < 0)
+ return errno;
+ if (read(fd, name, len) < 0)
+ return errno;
+ /* If there's more to read, the buffer was too small. */
+ if (read(fd, &dummy, 1) > 0)
+ return ERANGE;
+
+ return 0;
+}
diff --git a/libgcompat/wchar.c b/libgcompat/wchar.c
index 823c3e3..c60963e 100644
--- a/libgcompat/wchar.c
+++ b/libgcompat/wchar.c
@@ -45,7 +45,7 @@ int __vswprintf_chk(wchar_t *s, size_t n, int flag, size_t slen,
* LSB 5.0: LSB-Core-generic/baselib---wcstol-internal-1.html
*/
long int __wcstol_internal(const wchar_t *nptr, wchar_t **endptr, int base,
- int group)
+ int group)
{
assert(group == 0);
return wcstol(nptr, endptr, base);