rework langinfo code for ABI compat and for use by time 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         void *main_thread;
9         int threaded;
10         int secure;
11         size_t *auxv;
12         volatile int threads_minus_1;
13         int canceldisable;
14         FILE *ofl_head;
15         int ofl_lock[2];
16         size_t tls_size;
17 };
18
19 extern size_t __hwcap;
20
21 #if !defined(__PIC__) || (100*__GNUC__+__GNUC_MINOR__ >= 303 && !defined(__PCC__))
22
23 #ifdef __PIC__
24 #if __GNUC__ < 4
25 #define BROKEN_VISIBILITY 1
26 #endif
27 #define ATTR_LIBC_VISIBILITY __attribute__((visibility("hidden")))
28 #else
29 #define ATTR_LIBC_VISIBILITY
30 #endif
31
32 extern struct __libc __libc ATTR_LIBC_VISIBILITY;
33 #define libc __libc
34
35 #else
36
37 #define USE_LIBC_ACCESSOR
38 #define ATTR_LIBC_VISIBILITY
39 extern struct __libc *__libc_loc(void) __attribute__((const));
40 #define libc (*__libc_loc())
41
42 #endif
43
44
45 /* Designed to avoid any overhead in non-threaded processes */
46 void __lock(volatile int *) ATTR_LIBC_VISIBILITY;
47 void __unlock(volatile int *) ATTR_LIBC_VISIBILITY;
48 int __lockfile(FILE *) ATTR_LIBC_VISIBILITY;
49 void __unlockfile(FILE *) ATTR_LIBC_VISIBILITY;
50 #define LOCK(x) (libc.threads_minus_1 ? (__lock(x),1) : ((void)(x),1))
51 #define UNLOCK(x) (libc.threads_minus_1 ? (__unlock(x),1) : ((void)(x),1))
52
53 void __synccall(void (*)(void *), void *);
54 int __setxid(int, int, int, int);
55
56 extern char **__environ;
57
58 #undef weak_alias
59 #define weak_alias(old, new) \
60         extern __typeof(old) new __attribute__((weak, alias(#old)))
61
62 #undef LFS64_2
63 #define LFS64_2(x, y) weak_alias(x, y)
64
65 #undef LFS64
66 #define LFS64(x) LFS64_2(x, x##64)
67
68 #endif