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