libc-internal.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /* Copyright (C) 1991,92,93,95,96,97,98,99,2000,2001 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #ifndef _LIBC_INTERNAL_H
  16. #define _LIBC_INTERNAL_H 1
  17. #include <features.h>
  18. #ifndef __ASSEMBLER__
  19. /* GCC understands weak symbols and aliases; use its interface where
  20. possible, instead of embedded assembly language. */
  21. /* Define ALIASNAME as a strong alias for NAME. */
  22. # define strong_alias(name, aliasname) _strong_alias(name, aliasname)
  23. # define _strong_alias(name, aliasname) \
  24. extern __typeof (name) aliasname __attribute__ ((alias (#name)));
  25. /* This comes between the return type and function name in
  26. a function definition to make that definition weak. */
  27. # define weak_function __attribute__ ((weak))
  28. # define weak_const_function __attribute__ ((weak, __const__))
  29. /* Define ALIASNAME as a weak alias for NAME.
  30. If weak aliases are not available, this defines a strong alias. */
  31. # define weak_alias(name, aliasname) _weak_alias (name, aliasname)
  32. # define _weak_alias(name, aliasname) \
  33. extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
  34. /* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */
  35. # define weak_extern(symbol) _weak_extern (weak symbol)
  36. # define _weak_extern(expr) _Pragma (#expr)
  37. #else /* __ASSEMBLER__ */
  38. # define C_SYMBOL_NAME(name) __C_SYMBOL_PREFIX__ ##name
  39. # define strong_alias(name, aliasname) \
  40. .global C_SYMBOL_NAME (aliasname) ; \
  41. .set C_SYMBOL_NAME(aliasname),C_SYMBOL_NAME(name)
  42. # define weak_alias(name, aliasname) \
  43. .weak C_SYMBOL_NAME(aliasname) ; \
  44. C_SYMBOL_NAME(aliasname) = C_SYMBOL_NAME(name)
  45. # define weak_extern(symbol) \
  46. .weak C_SYMBOL_NAME(symbol)
  47. #endif /* __ASSEMBLER__ */
  48. /* When a reference to SYMBOL is encountered, the linker will emit a
  49. warning message MSG. */
  50. #ifdef __HAVE_ELF__
  51. /* We want the .gnu.warning.SYMBOL section to be unallocated. */
  52. # define __make_section_unallocated(section_string) \
  53. asm (".section " section_string "\n\t.previous");
  54. /* Tacking on "\n\t#" to the section name makes gcc put it's bogus
  55. section attributes on what looks like a comment to the assembler. */
  56. # define __sec_comment "\n\t#"
  57. # ifdef __cris__
  58. # define link_warning(symbol, msg)
  59. # else
  60. # define link_warning(symbol, msg) \
  61. __make_section_unallocated (".gnu.warning." #symbol) \
  62. static const char __evoke_link_warning_##symbol[] \
  63. __attribute__ ((used, section (".gnu.warning." #symbol __sec_comment))) \
  64. = msg;
  65. # endif
  66. #else /* __HAVE_ELF__ */
  67. # define link_warning(symbol, msg) \
  68. asm (".stabs \"" msg "\",30,0,0,0\n\t" \
  69. ".stabs \"" __C_SYMBOL_PREFIX__ #symbol "\",1,0,0,0\n");
  70. #endif /* __HAVE_ELF__ */
  71. #ifndef weak_function
  72. /* If we do not have the __attribute__ ((weak)) syntax, there is no way we
  73. can define functions as weak symbols. The compiler will emit a `.globl'
  74. directive for the function symbol, and a `.weak' directive in addition
  75. will produce an error from the assembler. */
  76. # define weak_function /* empty */
  77. # define weak_const_function /* empty */
  78. #endif
  79. /* On some platforms we can make internal function calls (i.e., calls of
  80. functions not exported) a bit faster by using a different calling
  81. convention. */
  82. #if 0 /*def __i386__*/
  83. # define internal_function __attribute__ ((regparm (3), stdcall))
  84. #endif
  85. #ifndef internal_function
  86. # define internal_function /* empty */
  87. #endif
  88. #ifndef NOT_IN_libc
  89. # define IS_IN_libc 1
  90. #endif
  91. /* Prepare for the case that `__builtin_expect' is not available. */
  92. #if __GNUC__ == 2 && __GNUC_MINOR__ < 96
  93. # define __builtin_expect(x, expected_value) (x)
  94. #endif
  95. #ifndef likely
  96. # define likely(x) __builtin_expect((!!(x)),1)
  97. #endif
  98. #ifndef unlikely
  99. # define unlikely(x) __builtin_expect((!!(x)),0)
  100. #endif
  101. #ifndef __LINUX_COMPILER_H
  102. # define __LINUX_COMPILER_H
  103. #endif
  104. #ifndef __cast__
  105. # define __cast__(_to)
  106. #endif
  107. #define attribute_unused __attribute__ ((unused))
  108. /* Arrange to hide uClibc internals */
  109. #if __GNUC_PREREQ (3, 3)
  110. # define attribute_hidden __attribute__ ((visibility ("hidden")))
  111. #else
  112. # define attribute_hidden
  113. #endif
  114. #define hidden_def(name) extern __typeof (name) name attribute_hidden;
  115. #ifndef __ASSEMBLER__
  116. # define hidden_strong_alias(name, aliasname) _hidden_strong_alias(name, aliasname)
  117. # define _hidden_strong_alias(name, aliasname) \
  118. extern __typeof (name) aliasname __attribute__ ((alias (#name))) attribute_hidden;
  119. # define hidden_weak_alias(name, aliasname) _hidden_weak_alias (name, aliasname)
  120. # define _hidden_weak_alias(name, aliasname) \
  121. extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))) attribute_hidden;
  122. #else /* __ASSEMBLER__ */
  123. # define hidden_strong_alias(name, aliasname) \
  124. .global C_SYMBOL_NAME (aliasname) ; \
  125. .hidden C_SYMBOL_NAME (aliasname) ; \
  126. .set C_SYMBOL_NAME(aliasname),C_SYMBOL_NAME(name)
  127. # define hidden_weak_alias(name, aliasname) \
  128. .weak C_SYMBOL_NAME(aliasname) ; \
  129. .hidden C_SYMBOL_NAME(aliasname) ; \
  130. C_SYMBOL_NAME(aliasname) = C_SYMBOL_NAME(name)
  131. #endif /* __ASSEMBLER__ */
  132. #ifdef __UCLIBC_BUILD_RELRO__
  133. # define attribute_relro __attribute__ ((section (".data.rel.ro")))
  134. #else
  135. # define attribute_relro
  136. #endif
  137. #ifdef __GNUC__
  138. # define attribute_noreturn __attribute__ ((__noreturn__))
  139. #else
  140. # define attribute_noreturn
  141. #endif
  142. /* Pull in things like __attribute_used__ */
  143. #include <sys/cdefs.h>
  144. /* --- this is added to integrate linuxthreads */
  145. #define __USE_UNIX98 1
  146. #ifndef __ASSEMBLER__
  147. # ifdef IS_IN_libc
  148. # define __UC(N) __ ## N
  149. # define __UC_ALIAS(N) strong_alias( __ ## N , N )
  150. # if defined __UCLIBC_HAS_XLOCALE__ && defined __UCLIBC_DO_XLOCALE
  151. # define __UCXL(N) __ ## N ## _l
  152. # define __UCXL_ALIAS(N) strong_alias ( __ ## N ## _l , N ## _l )
  153. # else
  154. # define __UCXL(N) __UC(N)
  155. # define __UCXL_ALIAS(N) __UC_ALIAS(N)
  156. # endif
  157. # define __need_size_t
  158. # include <stddef.h>
  159. # include <bits/types.h>
  160. # ifndef __ssize_t_defined
  161. typedef __ssize_t ssize_t;
  162. # define __ssize_t_defined
  163. # endif
  164. # include <bits/sigset.h>
  165. /* prototypes for internal use, please keep these in sync w/ updated headers */
  166. /* #include <fcntl.h> */
  167. #ifndef __USE_FILE_OFFSET64
  168. extern int __open (__const char *__file, int __oflag, ...) __nonnull ((1)) attribute_hidden;
  169. extern int __fcntl (int __fd, int __cmd, ...) attribute_hidden;
  170. #else
  171. # ifdef __REDIRECT
  172. extern int __REDIRECT (__open, (__const char *__file, int __oflag, ...), __open64)
  173. __nonnull ((1)) attribute_hidden;
  174. extern int __REDIRECT (__fcntl, (int __fd, int __cmd, ...), __fcntl64) attribute_hidden;
  175. # else
  176. # define __open __open64
  177. # define __fcntl __fcntl64
  178. # endif
  179. #endif
  180. #ifdef __USE_LARGEFILE64
  181. extern int __open64 (__const char *__file, int __oflag, ...) __nonnull ((1)) attribute_hidden;
  182. extern int __fcntl64 (int __fd, int __cmd, ...) attribute_hidden;
  183. #endif
  184. /* #include <string.h> */
  185. extern int __memcmp (__const void *__s1, __const void *__s2, size_t __n) attribute_hidden;
  186. extern void *__memcpy (void *__restrict __dest,
  187. __const void *__restrict __src, size_t __n) attribute_hidden;
  188. extern void *__memmove (void *__dest, __const void *__src, size_t __n) attribute_hidden;
  189. extern void *__memset (void *__s, int __c, size_t __n) attribute_hidden;
  190. extern char *__strcpy (char *__restrict __dest, __const char *__restrict __src) attribute_hidden;
  191. extern size_t __strlen (__const char *__s) attribute_hidden;
  192. extern int __strcmp (__const char *__s1, __const char *__s2) attribute_hidden;
  193. extern char *__strcat (char *__restrict __dest, __const char *__restrict __src) attribute_hidden;
  194. extern char *__strncpy (char *__restrict __dest,
  195. __const char *__restrict __src, size_t __n) attribute_hidden;
  196. extern char *__strchr (__const char *__s, int __c) attribute_hidden;
  197. extern int __strncmp (__const char *__s1, __const char *__s2, size_t __n) attribute_hidden;
  198. extern char *__strdup (__const char *__s) attribute_hidden;
  199. extern int __strcasecmp (__const char *__s1, __const char *__s2) attribute_hidden;
  200. extern int __strncasecmp (__const char *__s1, __const char *__s2, size_t __n) attribute_hidden;
  201. /* sources are built w/ _GNU_SOURCE, this gets undefined */
  202. extern int __xpg_strerror_r_internal (int __errnum, char *__buf, size_t __buflen) attribute_hidden;
  203. extern char *__glibc_strerror_r_internal (int __errnum, char *__buf, size_t __buflen) attribute_hidden;
  204. /* #include <unistd.h> */
  205. extern ssize_t __read(int __fd, void *__buf, size_t __nbytes) attribute_hidden;
  206. extern ssize_t __write(int __fd, __const void *__buf, size_t __n) attribute_hidden;
  207. extern int __close(int __fd) attribute_hidden;
  208. extern __pid_t __getpid (void) attribute_hidden;
  209. extern void _exit_internal (int __status) __attribute__ ((__noreturn__)) attribute_hidden;
  210. #ifndef __USE_FILE_OFFSET64
  211. extern int __lockf (int __fd, int __cmd, __off_t __len) attribute_hidden;
  212. extern __off_t __lseek (int __fd, __off_t __offset, int __whence) __THROW attribute_hidden;
  213. #else
  214. # ifdef __REDIRECT
  215. extern int __REDIRECT (__lockf, (int __fd, int __cmd, __off64_t __len),
  216. __lockf64) attribute_hidden;
  217. extern __off64_t __REDIRECT (__lseek,
  218. (int __fd, __off64_t __offset, int __whence),
  219. __lseek64) attribute_hidden;
  220. # else
  221. # define __lockf __lockf64
  222. # define __lseek __lseek64
  223. # endif
  224. #endif
  225. #ifdef __USE_LARGEFILE64
  226. extern int __lockf64 (int __fd, int __cmd, __off64_t __len) attribute_hidden;
  227. extern __off64_t __lseek64 (int __fd, __off64_t __offset, int __whence) __THROW attribute_hidden;
  228. #endif
  229. /* #include <stdio.h> */
  230. extern void __perror (__const char *__s) attribute_hidden;
  231. extern int __printf (__const char *__restrict __format, ...) attribute_hidden;
  232. extern int __sprintf (char *__restrict __s,
  233. __const char *__restrict __format, ...) attribute_hidden;
  234. /* hack */
  235. #define abort __abort
  236. #define fprintf __fprintf
  237. #define fclose __fclose
  238. #ifndef __USE_FILE_OFFSET64
  239. #define fopen __fopen
  240. #else
  241. #define fopen __fopen64
  242. #endif
  243. #ifdef __USE_LARGEFILE64
  244. #define fopen64 __fopen64
  245. #endif
  246. /* #include <stdlib.h> */
  247. extern char *__getenv (__const char *__name) attribute_hidden;
  248. extern void __exit (int __status) __THROW __attribute__ ((__noreturn__)) attribute_hidden;
  249. /* #include <signal.h> */
  250. extern int __sigprocmask (int __how, __const __sigset_t *__restrict __set,
  251. __sigset_t *__restrict __oset) attribute_hidden;
  252. /* #include <sys/ioctl.h> */
  253. extern int __ioctl (int __fd, unsigned long int __request, ...) attribute_hidden;
  254. /* #include <sys/socket.h> */
  255. extern int __socket (int __domain, int __type, int __protocol) attribute_hidden;
  256. /* #include <sys/stat.h> */
  257. #ifndef __USE_FILE_OFFSET64
  258. struct stat;
  259. extern int __stat (__const char *__restrict __file,
  260. struct stat *__restrict __buf) __THROW __nonnull ((1, 2)) attribute_hidden;
  261. extern int __fstat (int __fd, struct stat *__buf) __THROW __nonnull ((2)) attribute_hidden;
  262. extern int __lstat (__const char *__restrict __file,
  263. struct stat *__restrict __buf) __THROW __nonnull ((1, 2)) attribute_hidden;
  264. #else
  265. # ifdef __REDIRECT_NTH
  266. extern int __REDIRECT_NTH (__stat, (__const char *__restrict __file,
  267. struct stat *__restrict __buf), __stat64)
  268. __nonnull ((1, 2)) attribute_hidden;
  269. extern int __REDIRECT_NTH (__fstat, (int __fd, struct stat *__buf), __fstat64)
  270. __nonnull ((2)) attribute_hidden;
  271. extern int __REDIRECT_NTH (__lstat,
  272. (__const char *__restrict __file,
  273. struct stat *__restrict __buf), __lstat64)
  274. __nonnull ((1, 2)) attribute_hidden;
  275. # else
  276. # define __stat __stat64
  277. # define __fstat __fstat64
  278. # define __lstat __lstat64
  279. # endif
  280. #endif
  281. #ifdef __USE_LARGEFILE64
  282. struct stat64;
  283. extern int __stat64 (__const char *__restrict __file,
  284. struct stat64 *__restrict __buf) __THROW __nonnull ((1, 2)) attribute_hidden;
  285. extern int __fstat64 (int __fd, struct stat64 *__buf) __THROW __nonnull ((2)) attribute_hidden;
  286. extern int __lstat64 (__const char *__restrict __file,
  287. struct stat64 *__restrict __buf)
  288. __THROW __nonnull ((1, 2)) attribute_hidden;
  289. #endif
  290. /* #include <sys/statfs.h> */
  291. #ifndef __USE_FILE_OFFSET64
  292. struct statfs;
  293. extern int __statfs (__const char *__file, struct statfs *__buf)
  294. __THROW __nonnull ((1, 2)) attribute_hidden;
  295. extern int __fstatfs (int __fildes, struct statfs *__buf)
  296. __THROW __nonnull ((2)) attribute_hidden;
  297. #else
  298. # ifdef __REDIRECT
  299. extern int __REDIRECT (__statfs,
  300. (__const char *__file, struct statfs *__buf),
  301. __statfs64) __nonnull ((1, 2)) attribute_hidden;
  302. extern int __REDIRECT (__fstatfs, (int __fildes, struct statfs *__buf),
  303. __fstatfs64) __nonnull ((2)) attribute_hidden;
  304. # else
  305. # define __statfs __statfs64
  306. # endif
  307. #endif
  308. #ifdef __USE_LARGEFILE64
  309. struct statfs64;
  310. extern int __statfs64 (__const char *__file, struct statfs64 *__buf)
  311. __THROW __nonnull ((1, 2)) attribute_hidden;
  312. extern int __fstatfs64 (int __fildes, struct statfs64 *__buf)
  313. __THROW __nonnull ((2)) attribute_hidden;
  314. #endif
  315. # if 0 /* undoable here */
  316. /* #include <dirent.h> */
  317. typedef struct __dirstream DIR;
  318. extern DIR *__opendir (__const char *__name) attribute_hidden;
  319. extern int __closedir (DIR *__dirp) attribute_hidden;
  320. /* #include <stdio.h> */
  321. extern int __vfprintf (FILE *__restrict __s, __const char *__restrict __format,
  322. __gnuc_va_list __arg) attribute_hidden;
  323. extern int __fprintf (FILE *__restrict __stream,
  324. __const char *__restrict __format, ...) attribute_hidden;
  325. extern int __fclose (FILE *__stream) attribute_hidden;
  326. #ifndef __USE_FILE_OFFSET64
  327. extern FILE *__fopen (__const char *__restrict __filename,
  328. __const char *__restrict __modes) attribute_hidden;
  329. #else
  330. # ifdef __REDIRECT
  331. extern FILE *__REDIRECT (__fopen, (__const char *__restrict __filename,
  332. __const char *__restrict __modes), __fopen64) attribute_hidden;
  333. # else
  334. # define __fopen __fopen64
  335. # endif
  336. #endif
  337. #ifdef __USE_LARGEFILE64
  338. extern FILE *__fopen64 (__const char *__restrict __filename,
  339. __const char *__restrict __modes) attribute_hidden;
  340. #endif
  341. /* #include <sys/time.h> */
  342. # define __need_timeval
  343. # include <bits/time.h>
  344. extern int __gettimeofday(struct timeval *__restrict __tv, *__restrict __timezone__ptr_t __tz) attribute_hidden;
  345. # endif
  346. /* #include <pthread.h> */
  347. # ifndef __UCLIBC_HAS_THREADS__
  348. # define __pthread_mutex_init(mutex, mutexattr) ((void)0)
  349. # define __pthread_mutex_lock(mutex) ((void)0)
  350. # define __pthread_mutex_trylock(mutex) ((void)0)
  351. # define __pthread_mutex_unlock(mutex) ((void)0)
  352. # endif
  353. # endif /* IS_IN_libc */
  354. #endif /* __ASSEMBLER__ */
  355. #endif /* _LIBC_INTERNAL_H */