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.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 #ifndef _LIBC_INTERNAL_H
20 #define _LIBC_INTERNAL_H 1
25 /* GCC understands weak symbols and aliases; use its interface where
26 possible, instead of embedded assembly language. */
28 /* Define ALIASNAME as a strong alias for NAME. */
29 # define strong_alias(name, aliasname) _strong_alias(name, aliasname)
30 # define _strong_alias(name, aliasname) \
31 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
33 /* This comes between the return type and function name in
34 a function definition to make that definition weak. */
35 # define weak_function __attribute__ ((weak))
36 # define weak_const_function __attribute__ ((weak, __const__))
38 /* Define ALIASNAME as a weak alias for NAME.
39 If weak aliases are not available, this defines a strong alias. */
40 # define weak_alias(name, aliasname) _weak_alias (name, aliasname)
41 # define _weak_alias(name, aliasname) \
42 extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
44 /* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */
45 # define weak_extern(symbol) _weak_extern (weak symbol)
46 # define _weak_extern(expr) _Pragma (#expr)
48 #else /* __ASSEMBLER__ */
50 #ifdef __SYMBOL_PREFIX
51 # define C_SYMBOL_NAME(name) _##name
53 # define C_SYMBOL_NAME(name) name
56 # define strong_alias(name, aliasname) \
57 .global C_SYMBOL_NAME (aliasname) ; \
58 .set C_SYMBOL_NAME(aliasname),C_SYMBOL_NAME(name)
60 # define weak_alias(name, aliasname) \
61 .weak C_SYMBOL_NAME(aliasname) ; \
62 C_SYMBOL_NAME(aliasname) = C_SYMBOL_NAME(name)
64 # define weak_extern(symbol) \
65 .weak C_SYMBOL_NAME(symbol)
67 #endif /* __ASSEMBLER__ */
69 /* When a reference to SYMBOL is encountered, the linker will emit a
70 warning message MSG. */
73 /* We want the .gnu.warning.SYMBOL section to be unallocated. */
74 # define __make_section_unallocated(section_string) \
75 asm (".section " section_string "\n\t.previous");
77 /* Tacking on "\n\t#" to the section name makes gcc put it's bogus
78 section attributes on what looks like a comment to the assembler. */
79 # define __sec_comment "\n\t#"
81 # define link_warning(symbol, msg)
83 # define link_warning(symbol, msg) \
84 __make_section_unallocated (".gnu.warning." #symbol) \
85 static const char __evoke_link_warning_##symbol[] \
86 __attribute__ ((used, section (".gnu.warning." #symbol __sec_comment))) \
89 #else /* __HAVE_ELF__ */
90 # define link_warning(symbol, msg) \
91 asm (".stabs \"" msg "\",30,0,0,0\n\t" \
92 ".stabs \"" __C_SYMBOL_PREFIX__ #symbol "\",1,0,0,0\n");
93 #endif /* __HAVE_ELF__ */
96 /* If we do not have the __attribute__ ((weak)) syntax, there is no way we
97 can define functions as weak symbols. The compiler will emit a `.globl'
98 directive for the function symbol, and a `.weak' directive in addition
99 will produce an error from the assembler. */
100 # define weak_function /* empty */
101 # define weak_const_function /* empty */
104 /* On some platforms we can make internal function calls (i.e., calls of
105 functions not exported) a bit faster by using a different calling
107 #if 0 /*def __i386__*/
108 # define internal_function __attribute__ ((regparm (3), stdcall))
110 #ifndef internal_function
111 # define internal_function /* empty */
115 # define IS_IN_libc 1
118 /* Prepare for the case that `__builtin_expect' is not available. */
119 #if __GNUC__ == 2 && __GNUC_MINOR__ < 96
120 # define __builtin_expect(x, expected_value) (x)
123 # define likely(x) __builtin_expect((!!(x)),1)
126 # define unlikely(x) __builtin_expect((!!(x)),0)
128 #ifndef __LINUX_COMPILER_H
129 # define __LINUX_COMPILER_H
132 # define __cast__(_to)
135 #define attribute_unused __attribute__ ((unused))
137 /* Arrange to hide uClibc internals */
138 #if __GNUC_PREREQ (3, 3)
139 # define attribute_hidden __attribute__ ((visibility ("hidden")))
141 # define attribute_hidden
144 #ifndef __ASSEMBLER__
145 # define hidden_strong_alias(name, aliasname) _hidden_strong_alias(name, aliasname)
146 # define _hidden_strong_alias(name, aliasname) \
147 extern __typeof (name) aliasname __attribute__ ((alias (#name))) attribute_hidden;
149 # define hidden_weak_alias(name, aliasname) _hidden_weak_alias (name, aliasname)
150 # define _hidden_weak_alias(name, aliasname) \
151 extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))) attribute_hidden;
152 #else /* __ASSEMBLER__ */
153 # define hidden_strong_alias(name, aliasname) \
154 .global C_SYMBOL_NAME (aliasname) ; \
155 .hidden C_SYMBOL_NAME (aliasname) ; \
156 .set C_SYMBOL_NAME(aliasname),C_SYMBOL_NAME(name)
158 # define hidden_weak_alias(name, aliasname) \
159 .weak C_SYMBOL_NAME(aliasname) ; \
160 .hidden C_SYMBOL_NAME(aliasname) ; \
161 C_SYMBOL_NAME(aliasname) = C_SYMBOL_NAME(name)
162 #endif /* __ASSEMBLER__ */
164 #ifdef __UCLIBC_BUILD_RELRO__
165 # define attribute_relro __attribute__ ((section (".data.rel.ro")))
167 # define attribute_relro
171 # define attribute_noreturn __attribute__ ((__noreturn__))
173 # define attribute_noreturn
176 #ifdef __UCLIBC_HAS_THREADS_NATIVE__
177 # define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
180 /* Pull in things like __attribute_used__ */
181 #include <sys/cdefs.h>
183 /* --- this is added to integrate linuxthreads */
184 #define __USE_UNIX98 1
186 #ifndef __ASSEMBLER__
189 # define __UC(N) __ ## N
190 # define __UC_ALIAS(N) strong_alias( __ ## N , N )
191 # if defined __UCLIBC_HAS_XLOCALE__ && defined __UCLIBC_DO_XLOCALE
192 # define __UCXL(N) __ ## N ## _l
193 # define __UCXL_ALIAS(N) strong_alias ( __ ## N ## _l , N ## _l )
195 # define __UCXL(N) __UC(N)
196 # define __UCXL_ALIAS(N) __UC_ALIAS(N)
199 # define __need_size_t
200 # ifdef __UCLIBC_HAS_WCHAR__
201 # define __need_wchar_t
202 # define __need_wint_t
206 # include <bits/types.h>
208 # ifndef __ssize_t_defined
209 typedef __ssize_t ssize_t;
210 # define __ssize_t_defined
213 # include <bits/sigset.h>
215 /* prototypes for internal use, please keep these in sync w/ updated headers */
216 /* #include <fcntl.h> */
217 #ifndef __USE_FILE_OFFSET64
218 extern int __open (__const char *__file, int __oflag, ...) __nonnull ((1)) attribute_hidden;
219 extern int __fcntl (int __fd, int __cmd, ...) attribute_hidden;
222 extern int __REDIRECT (__open, (__const char *__file, int __oflag, ...), __open64)
223 __nonnull ((1)) attribute_hidden;
224 extern int __REDIRECT (__fcntl, (int __fd, int __cmd, ...), __fcntl64) attribute_hidden;
226 # define __open __open64
227 # define __fcntl __fcntl64
230 #ifdef __USE_LARGEFILE64
231 extern int __open64 (__const char *__file, int __oflag, ...) __nonnull ((1)) attribute_hidden;
232 extern int __fcntl64 (int __fd, int __cmd, ...) attribute_hidden;
235 /* #include <string.h> */
236 extern int __memcmp (__const void *__s1, __const void *__s2, size_t __n) attribute_hidden;
237 extern void *__memcpy (void *__restrict __dest,
238 __const void *__restrict __src, size_t __n) attribute_hidden;
239 extern void *__memmove (void *__dest, __const void *__src, size_t __n) attribute_hidden;
240 extern void *__memset (void *__s, int __c, size_t __n) attribute_hidden;
241 extern char *__strcpy (char *__restrict __dest, __const char *__restrict __src) attribute_hidden;
242 extern size_t __strlen (__const char *__s) attribute_hidden;
243 extern int __strcmp (__const char *__s1, __const char *__s2) attribute_hidden;
244 extern char *__strcat (char *__restrict __dest, __const char *__restrict __src) attribute_hidden;
245 extern char *__strncpy (char *__restrict __dest,
246 __const char *__restrict __src, size_t __n) attribute_hidden;
247 extern char *__strchr (__const char *__s, int __c) attribute_hidden;
248 extern char *__strrchr (__const char *__s, int __c) attribute_hidden;
249 extern int __strncmp (__const char *__s1, __const char *__s2, size_t __n) attribute_hidden;
250 extern char *__strdup (__const char *__s) attribute_hidden;
251 extern int __strcasecmp (__const char *__s1, __const char *__s2) attribute_hidden;
252 extern int __strncasecmp (__const char *__s1, __const char *__s2, size_t __n) attribute_hidden;
253 extern void *__rawmemchr (__const void *__s, int __c) __THROW __attribute_pure__ __nonnull ((1)) attribute_hidden;
254 extern size_t __strspn (__const char *__s, __const char *__accept)
255 __THROW __attribute_pure__ __nonnull ((1, 2)) attribute_hidden;
256 extern char *__strpbrk (__const char *__s, __const char *__accept)
257 __THROW __attribute_pure__ __nonnull ((1, 2)) attribute_hidden;
258 extern size_t __strnlen (__const char *__string, size_t __maxlen)
259 __THROW __attribute_pure__ __nonnull ((1)) attribute_hidden;
260 extern char *__strtok_r (char *__restrict __s, __const char *__restrict __delim,
261 char **__restrict __save_ptr) __THROW __nonnull ((2, 3)) attribute_hidden;
263 /* sources are built w/ _GNU_SOURCE, this gets undefined */
264 extern int __xpg_strerror_r_internal (int __errnum, char *__buf, size_t __buflen) attribute_hidden;
265 extern char *__glibc_strerror_r_internal (int __errnum, char *__buf, size_t __buflen) attribute_hidden;
268 extern int __tolower (int __c) __THROW attribute_hidden;
269 extern int __toupper (int __c) __THROW attribute_hidden;
271 #ifdef __UCLIBC_HAS_WCHAR__
273 extern size_t __wcslen (__const wchar_t *__s) __THROW __attribute_pure__ attribute_hidden;
274 extern wchar_t *__wcscpy (wchar_t *__restrict __dest, __const wchar_t *__restrict __src) __THROW attribute_hidden;
275 extern size_t __wcsspn (__const wchar_t *__wcs, __const wchar_t *__accept)
276 __THROW __attribute_pure__ attribute_hidden;
277 extern wchar_t *__wcspbrk (__const wchar_t *__wcs, __const wchar_t *__accept)
278 __THROW __attribute_pure__ attribute_hidden;
280 extern wint_t __towlower (wint_t __wc) __THROW attribute_hidden;
283 /* #include <unistd.h> */
284 extern ssize_t __read(int __fd, void *__buf, size_t __nbytes) attribute_hidden;
285 extern ssize_t __write(int __fd, __const void *__buf, size_t __n) attribute_hidden;
286 extern int __close(int __fd) attribute_hidden;
287 extern __pid_t __getpid (void) attribute_hidden;
288 extern void _exit_internal (int __status) __attribute__ ((__noreturn__)) attribute_hidden;
289 #ifndef __USE_FILE_OFFSET64
290 extern int __lockf (int __fd, int __cmd, __off_t __len) attribute_hidden;
291 extern __off_t __lseek (int __fd, __off_t __offset, int __whence) __THROW attribute_hidden;
294 extern int __REDIRECT (__lockf, (int __fd, int __cmd, __off64_t __len),
295 __lockf64) attribute_hidden;
296 extern __off64_t __REDIRECT (__lseek,
297 (int __fd, __off64_t __offset, int __whence),
298 __lseek64) attribute_hidden;
300 # define __lockf __lockf64
301 # define __lseek __lseek64
304 #ifdef __USE_LARGEFILE64
305 extern int __lockf64 (int __fd, int __cmd, __off64_t __len) attribute_hidden;
306 extern __off64_t __lseek64 (int __fd, __off64_t __offset, int __whence) __THROW attribute_hidden;
309 /* #include <stdio.h> */
310 extern void __perror (__const char *__s) attribute_hidden;
311 extern int __printf (__const char *__restrict __format, ...) attribute_hidden;
312 extern int __sprintf (char *__restrict __s,
313 __const char *__restrict __format, ...) attribute_hidden;
316 #define abort __abort
317 #define fprintf __fprintf
318 #define fclose __fclose
319 #ifndef __USE_FILE_OFFSET64
320 #define fopen __fopen
322 #define fopen __fopen64
324 #ifdef __USE_LARGEFILE64
325 #define fopen64 __fopen64
328 /* #include <stdlib.h> */
329 extern char *__getenv (__const char *__name) attribute_hidden;
330 extern void __exit (int __status) __THROW __attribute__ ((__noreturn__)) attribute_hidden;
332 /* #include <signal.h> */
333 extern int __sigprocmask (int __how, __const __sigset_t *__restrict __set,
334 __sigset_t *__restrict __oset) attribute_hidden;
336 /* #include <sys/ioctl.h> */
337 extern int __ioctl (int __fd, unsigned long int __request, ...) attribute_hidden;
339 /* #include <sys/socket.h> */
340 extern int __socket (int __domain, int __type, int __protocol) attribute_hidden;
342 /* #include <sys/stat.h> */
343 #ifndef __USE_FILE_OFFSET64
345 extern int __stat (__const char *__restrict __file,
346 struct stat *__restrict __buf) __THROW __nonnull ((1, 2)) attribute_hidden;
347 extern int __fstat (int __fd, struct stat *__buf) __THROW __nonnull ((2)) attribute_hidden;
348 extern int __lstat (__const char *__restrict __file,
349 struct stat *__restrict __buf) __THROW __nonnull ((1, 2)) attribute_hidden;
351 # ifdef __REDIRECT_NTH
352 extern int __REDIRECT_NTH (__stat, (__const char *__restrict __file,
353 struct stat *__restrict __buf), __stat64)
354 __nonnull ((1, 2)) attribute_hidden;
355 extern int __REDIRECT_NTH (__fstat, (int __fd, struct stat *__buf), __fstat64)
356 __nonnull ((2)) attribute_hidden;
357 extern int __REDIRECT_NTH (__lstat,
358 (__const char *__restrict __file,
359 struct stat *__restrict __buf), __lstat64)
360 __nonnull ((1, 2)) attribute_hidden;
362 # define __stat __stat64
363 # define __fstat __fstat64
364 # define __lstat __lstat64
367 #ifdef __USE_LARGEFILE64
369 extern int __stat64 (__const char *__restrict __file,
370 struct stat64 *__restrict __buf) __THROW __nonnull ((1, 2)) attribute_hidden;
371 extern int __fstat64 (int __fd, struct stat64 *__buf) __THROW __nonnull ((2)) attribute_hidden;
372 extern int __lstat64 (__const char *__restrict __file,
373 struct stat64 *__restrict __buf)
374 __THROW __nonnull ((1, 2)) attribute_hidden;
377 /* #include <sys/statfs.h> */
378 #ifndef __USE_FILE_OFFSET64
380 extern int __statfs (__const char *__file, struct statfs *__buf)
381 __THROW __nonnull ((1, 2)) attribute_hidden;
382 extern int __fstatfs (int __fildes, struct statfs *__buf)
383 __THROW __nonnull ((2)) attribute_hidden;
386 extern int __REDIRECT (__statfs,
387 (__const char *__file, struct statfs *__buf),
388 __statfs64) __nonnull ((1, 2)) attribute_hidden;
389 extern int __REDIRECT (__fstatfs, (int __fildes, struct statfs *__buf),
390 __fstatfs64) __nonnull ((2)) attribute_hidden;
392 # define __statfs __statfs64
395 #ifdef __USE_LARGEFILE64
397 extern int __statfs64 (__const char *__file, struct statfs64 *__buf)
398 __THROW __nonnull ((1, 2)) attribute_hidden;
399 extern int __fstatfs64 (int __fildes, struct statfs64 *__buf)
400 __THROW __nonnull ((2)) attribute_hidden;
403 # if 0 /* undoable here */
404 /* #include <dirent.h> */
405 typedef struct __dirstream DIR;
406 extern DIR *__opendir (__const char *__name) attribute_hidden;
407 extern int __closedir (DIR *__dirp) attribute_hidden;
409 /* #include <stdio.h> */
410 extern int __vfprintf (FILE *__restrict __s, __const char *__restrict __format,
411 __gnuc_va_list __arg) attribute_hidden;
412 extern int __fprintf (FILE *__restrict __stream,
413 __const char *__restrict __format, ...) attribute_hidden;
414 extern int __fclose (FILE *__stream) attribute_hidden;
416 #ifndef __USE_FILE_OFFSET64
417 extern FILE *__fopen (__const char *__restrict __filename,
418 __const char *__restrict __modes) attribute_hidden;
421 extern FILE *__REDIRECT (__fopen, (__const char *__restrict __filename,
422 __const char *__restrict __modes), __fopen64) attribute_hidden;
424 # define __fopen __fopen64
427 #ifdef __USE_LARGEFILE64
428 extern FILE *__fopen64 (__const char *__restrict __filename,
429 __const char *__restrict __modes) attribute_hidden;
432 /* #include <sys/time.h> */
433 # define __need_timeval
434 # include <bits/time.h>
435 extern int __gettimeofday(struct timeval *__restrict __tv, *__restrict __timezone__ptr_t __tz) attribute_hidden;
438 /* #include <pthread.h> */
439 # ifndef __UCLIBC_HAS_THREADS__
440 # define __pthread_mutex_init(mutex, mutexattr) ((void)0)
441 # define __pthread_mutex_lock(mutex) ((void)0)
442 # define __pthread_mutex_trylock(mutex) ((void)0)
443 # define __pthread_mutex_unlock(mutex) ((void)0)
446 /* internal access to program name */
447 extern const char *__uclibc_progname attribute_hidden;
449 # endif /* IS_IN_libc */
451 /* #include <alloca.h> */
452 #include <bits/stackinfo.h>
453 #if _STACK_GROWS_DOWN
454 # define extend_alloca(buf, len, newlen) \
455 (__typeof (buf)) ({ size_t __newlen = (newlen); \
456 char *__newbuf = alloca (__newlen); \
457 if (__newbuf + __newlen == (char *) buf) \
462 #elif _STACK_GROWS_UP
463 # define extend_alloca(buf, len, newlen) \
464 (__typeof (buf)) ({ size_t __newlen = (newlen); \
465 char *__newbuf = alloca (__newlen); \
466 char *__buf = (buf); \
467 if (__buf + __newlen == __newbuf) \
476 # warning unknown stack
477 # define extend_alloca(buf, len, newlen) \
478 alloca (((len) = (newlen)))
481 #endif /* __ASSEMBLER__ */
483 #endif /* _LIBC_INTERNAL_H */