initial check-in, version 0.5.0
[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 } libc;
19
20
21 /* Designed to avoid any overhead in non-threaded processes */
22 void __lock(volatile int *);
23 #define LOCK(x) (libc.threads_minus_1 ? (__lock(x),1) : ((void)(x),1))
24 #define UNLOCK(x) (*(x)=0)
25 #define CANCELPT(x) (libc.cancelpt ? libc.cancelpt((x)),0 : (void)(x),0)
26 #define CANCELPT_BEGIN CANCELPT(1)
27 #define CANCELPT_END CANCELPT(0)
28
29 extern char **__environ;
30 #define environ __environ
31
32 #undef weak_alias
33 #define weak_alias(old, new) \
34         extern __typeof(old) new __attribute__((weak, alias(#old)))
35
36 #undef LFS64_2
37 //#define LFS64_2(x, y) weak_alias(x, y)
38 #define LFS64_2(x, y) extern __typeof(x) y
39
40 #undef LFS64
41 #define LFS64(x) LFS64_2(x, x##64)
42
43 #endif