cdefs.h 4.14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Copyright (c) 2011, 2012, 2013, 2015 Jonas 'Sortie' Termansen.
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * sys/cdefs.h
 * Declares internal macros for the C programming language.
 */
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

#ifndef INCLUDE_SYS_CDEFS_H
#define INCLUDE_SYS_CDEFS_H

#include <features.h>

/* Preprocessor trick to turn anything into a string. */
#define __STRINGIFY(x) #x

/* Issue warning when this is used, except in defines, where the warning is
   inserted whenever the macro is expanded. This can be used to deprecated
   macros - and it happens on preprocessor level - so it shouldn't change any
   semantics of any code that uses such a macro. The argument msg should be a
   string that contains the warning. */
#define __PRAGMA_WARNING(msg) _Pragma(__STRINGIFY(GCC warning msg))

/* Use the real restrict keyword if it is available. Not that this really
   matters as gcc uses __restrict and __restrict__ as aliases for restrict, but
   it will look nicer after preprocessing. */
#if __HAS_RESTRICT
#undef __restrict
#define __restrict restrict
#endif

/* Provide the restrict keyword if requested and unavailable. */
#if !__HAS_RESTRICT && __want_restrict
#define restrict __restrict
#undef __HAS_RESTRICT
#define __HAS_RESTRICT 2
#endif

50 51 52 53 54 55
/* Macro to declare a weak alias. */
#if defined(__is_sortix_libc)
#define weak_alias(old, new) \
	extern __typeof(old) new __attribute__((weak, alias(#old)))
#endif

56 57
#define __pure2 __attribute__((__const__))

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
/*
 * Compatibility macros to advertise to ports when features become available.
 * These macros are only for things that are not trivial to detect from a C
 * source file (such as by a standard macro).
 *
 * The feature foo should initially have an undef preprocessor statement of the
 * macro __SORTIX_HAS_FOO__ (or something like that). It should carry a TODO
 * comment stating:
 *
 * - What the feature is and when the macro should become defined.
 * - Which ports (if any) rely on this macro and will use the feature whenever
 *   the macro is defined.
 * - That the macro should be removed when the specific ports have been updated
 *   to no longer rely on the macro. If no ports used the feature in the first
 *   place, it should say to remove the macro when the feature is implemented.
 *
 * The undef statement should become a define statement when the feature is
 * implemented. As the each port is updated after that, the feature should
 * become unconditionally used in the port, and the port is removed from the
 * list here. Finally, when the list is empty, the macro is removed entirely.
 *
 * For instance, the TODO statement for the feature foo with the undef'd macro
 * __SORTIX_HAS_FOO__ might say:
 *
 *   "Define when foo is implemented. Remove when libbar, libqux, and libbaz are
 *    updated to not rely on this macro."
 *
 * Should a port become broken if a macro is defined here, the port should be
 * fixed (by either fixing it or disabling the feature in the port regardless
 * of the macro) before the macro is officially enabled here.
 */

/* TODO: Define when floating point formating is implemented. Remove when gawk
         is updated to not rely on this macro. */
#undef __SORTIX_HAS_FORMAT_FLOAT__

/* TODO: Define when floating point parsing is implemented. No ports are using
         this macro at this time. Remove when the feature is implemented. */
#undef __SORTIX_HAS_FLOAT_PARSE__

98 99 100 101
/* TODO: Define when restartable system calls are implemented. Remove when git
         is updated to not rely on this macro. */
#undef __SORTIX_HAS_RESTARTABLE_SYSCALLS__

102
#endif