libc.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef LIBC_H
  2. #define LIBC_H
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. struct __libc {
  6. int *(*errno_location)(void);
  7. void (*testcancel)(void);
  8. int threaded;
  9. int canceldisable;
  10. void (*fork_handler)(int);
  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. #if 100*__GNUC__+__GNUC_MINOR__ >= 303 || defined(__PCC__) || defined(__TINYC__)
  20. extern struct __libc __libc __attribute__((visibility("hidden")));
  21. #define libc __libc
  22. #elif !defined(__PIC__)
  23. extern struct __libc __libc;
  24. #define libc __libc
  25. #else
  26. #define USE_LIBC_ACCESSOR
  27. extern struct __libc *__libc_loc(void) __attribute__((const));
  28. #define libc (*__libc_loc())
  29. #endif
  30. /* Designed to avoid any overhead in non-threaded processes */
  31. void __lock(volatile int *);
  32. void __lockfile(FILE *);
  33. #define LOCK(x) (libc.threads_minus_1 ? (__lock(x),1) : ((void)(x),1))
  34. #define UNLOCK(x) (*(volatile int *)(x)=0)
  35. int __rsyscall(int, long, long, long, long, long, long);
  36. extern char **__environ;
  37. #define environ __environ
  38. #undef weak_alias
  39. #define weak_alias(old, new) \
  40. extern __typeof(old) new __attribute__((weak, alias(#old)))
  41. #undef LFS64_2
  42. //#define LFS64_2(x, y) weak_alias(x, y)
  43. #define LFS64_2(x, y) extern __typeof(x) y
  44. #undef LFS64
  45. #define LFS64(x) LFS64_2(x, x##64)
  46. #endif