60a25eff7cf0321824a550001e1d3142da7aad52
[musl] / src / internal / libc.h
1 #ifndef LIBC_H
2 #define LIBC_H
3
4 #include <stdlib.h>
5 #include <stdio.h>
6
7 struct __libc {
8         int *(*errno_location)(void);
9         void (*cancelpt)(int);
10         void (*lock)(volatile int *);
11         void (*lockfile)(FILE *);
12         void (**tsd_keys)(void *);
13         void (*sigtimer)();
14         int (*atexit)(void (*)(void));
15         void (*fini)(void);
16         void (*ldso_fini)(void);
17         volatile int threads_minus_1;
18         int ofl_lock;
19         int (*rsyscall)(int, long, long, long, long, long, long);
20         void (*fork_handler)(int);
21         FILE *ofl_head;
22 };
23
24
25 #if 100*__GNUC__+__GNUC_MINOR__ >= 303 || defined(__PCC__) || defined(__TINYC__)
26 extern struct __libc __libc __attribute__((visibility("hidden")));
27 #define libc __libc
28
29 #elif !defined(__PIC__)
30 extern struct __libc __libc;
31 #define libc __libc
32
33 #else
34 #define USE_LIBC_ACCESSOR
35 extern struct __libc *__libc_loc(void) __attribute__((const));
36 #define libc (*__libc_loc())
37
38 #endif
39
40
41 /* Designed to avoid any overhead in non-threaded processes */
42 void __lock(volatile int *);
43 void __lockfile(FILE *);
44 #define LOCK(x) (libc.threads_minus_1 ? (__lock(x),1) : ((void)(x),1))
45 #define UNLOCK(x) (*(x)=0)
46 #define CANCELPT(x) (libc.cancelpt ? libc.cancelpt((x)),0 : (void)(x),0)
47 #define CANCELPT_BEGIN CANCELPT(1)
48 #define CANCELPT_TRY CANCELPT(0)
49 #define CANCELPT_END CANCELPT(-1)
50
51 extern char **__environ;
52 #define environ __environ
53
54 #undef weak_alias
55 #define weak_alias(old, new) \
56         extern __typeof(old) new __attribute__((weak, alias(#old)))
57
58 #undef LFS64_2
59 //#define LFS64_2(x, y) weak_alias(x, y)
60 #define LFS64_2(x, y) extern __typeof(x) y
61
62 #undef LFS64
63 #define LFS64(x) LFS64_2(x, x##64)
64
65 #endif