add pthread_atfork interface
[musl] / src / internal / libc.h
1 #ifndef LIBC_H
2 #define LIBC_H
3
4 #include <stdlib.h>
5 #include <stdio.h>
6
7 #define libc __libc
8 extern struct libc {
9         void (*lock)(volatile int *);
10         void (*cancelpt)(int);
11         int (*atexit)(void (*)(void));
12         void (*fini)(void);
13         void (*ldso_fini)(void);
14         int *(*errno_location)(void);
15         volatile int threads_minus_1;
16         int (*rsyscall)(int, long, long, long, long, long, long);
17         void (**tsd_keys)(void *);
18         void (*fork_handler)(int);
19 } libc;
20
21
22 /* Designed to avoid any overhead in non-threaded processes */
23 void __lock(volatile int *);
24 #define LOCK(x) (libc.threads_minus_1 ? (__lock(x),1) : ((void)(x),1))
25 #define UNLOCK(x) (*(x)=0)
26 #define CANCELPT(x) (libc.cancelpt ? libc.cancelpt((x)),0 : (void)(x),0)
27 #define CANCELPT_BEGIN CANCELPT(1)
28 #define CANCELPT_END CANCELPT(0)
29
30 extern char **__environ;
31 #define environ __environ
32
33 #undef weak_alias
34 #define weak_alias(old, new) \
35         extern __typeof(old) new __attribute__((weak, alias(#old)))
36
37 #undef LFS64_2
38 //#define LFS64_2(x, y) weak_alias(x, y)
39 #define LFS64_2(x, y) extern __typeof(x) y
40
41 #undef LFS64
42 #define LFS64(x) LFS64_2(x, x##64)
43
44 #endif