use weak aliases rather than function pointers to simplify some code
[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         int threaded;
10         int canceldisable;
11         int (*atexit)(void (*)(void));
12         void (*fini)(void);
13         void (*ldso_fini)(void);
14         volatile int threads_minus_1;
15         int ofl_lock;
16         FILE *ofl_head;
17         void *main_thread;
18 };
19
20
21 #if 100*__GNUC__+__GNUC_MINOR__ >= 303 || defined(__PCC__) || defined(__TINYC__)
22 extern struct __libc __libc __attribute__((visibility("hidden")));
23 #define libc __libc
24
25 #elif !defined(__PIC__)
26 extern struct __libc __libc;
27 #define libc __libc
28
29 #else
30 #define USE_LIBC_ACCESSOR
31 extern struct __libc *__libc_loc(void) __attribute__((const));
32 #define libc (*__libc_loc())
33
34 #endif
35
36
37 /* Designed to avoid any overhead in non-threaded processes */
38 void __lock(volatile int *);
39 int __lockfile(FILE *);
40 void __unlockfile(FILE *);
41 #define LOCK(x) (libc.threads_minus_1 ? (__lock(x),1) : ((void)(x),1))
42 #define UNLOCK(x) (*(volatile int *)(x)=0)
43
44 void __synccall(void (*)(void *), void *);
45 int __setxid(int, int, int, int);
46
47 extern char **__environ;
48 #define environ __environ
49
50 #undef weak_alias
51 #define weak_alias(old, new) \
52         extern __typeof(old) new __attribute__((weak, alias(#old)))
53
54 #undef LFS64_2
55 //#define LFS64_2(x, y) weak_alias(x, y)
56 #define LFS64_2(x, y) extern __typeof(x) y
57
58 #undef LFS64
59 #define LFS64(x) LFS64_2(x, x##64)
60
61 #endif