libc-internal.h 14 KB

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