Avoid redefining macros defined by the system

In particular, OpenBSD already defines __GNUC_PREREQ__, __BEGIN_DECLS,
and __warn_references. Hiding the definitions behind #ifndef guards
avoids warnings when building.
This commit is contained in:
Alex Arslan 2018-04-06 14:41:06 -07:00
parent 48c6c2c2ac
commit 72bfab46a0
No known key found for this signature in database
GPG Key ID: EC409F3AF54AD659
2 changed files with 12 additions and 0 deletions

View File

@ -78,12 +78,14 @@
/*
* Macro to test if we're using a specific version of gcc or later.
*/
#ifndef __GNUC_PREREQ__
#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
#define __GNUC_PREREQ__(ma, mi) \
(__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))
#else
#define __GNUC_PREREQ__(ma, mi) 0
#endif
#endif /* __GNUC_PREREQ__ */
/*
* Compiler-dependent macro to help declare pure (no side effects) functions.

View File

@ -1,6 +1,7 @@
#ifndef _CDEFS_COMPAT_H_
#define _CDEFS_COMPAT_H_
#if !defined(__BEGIN_DECLS)
#if defined(__cplusplus)
#define __BEGIN_DECLS extern "C" {
#define __END_DECLS }
@ -8,6 +9,7 @@
#define __BEGIN_DECLS
#define __END_DECLS
#endif
#endif /* !defined(__BEGIN_DECLS) */
#ifdef __GNUC__
#ifndef __strong_reference
@ -25,18 +27,22 @@
#define __weak_reference(sym,alias) \
__asm__(".weak " #alias); \
__asm__(".equ " #alias ", " #sym)
#ifndef __warn_references
#define __warn_references(sym,msg) \
__asm__(".section .gnu.warning." #sym); \
__asm__(".asciz \"" msg "\""); \
__asm__(".previous")
#endif /* __warn_references */
#else
#define __weak_reference(sym,alias) \
__asm__(".weak alias"); \
__asm__(".equ alias, sym")
#ifndef __warn_references
#define __warn_references(sym,msg) \
__asm__(".section .gnu.warning.sym"); \
__asm__(".asciz \"msg\""); \
__asm__(".previous")
#endif /* __warn_references */
#endif /* __STDC__ */
#elif defined(__clang__) /* CLANG */
#ifdef __STDC__
@ -53,16 +59,20 @@
#define __weak_reference(sym,alias) \
__asm__(".stabs \"_" #alias "\",11,0,0,0"); \
__asm__(".stabs \"_" #sym "\",1,0,0,0")
#ifndef __warn_references
#define __warn_references(sym,msg) \
__asm__(".stabs \"" msg "\",30,0,0,0"); \
__asm__(".stabs \"_" #sym "\",1,0,0,0")
#endif /* __warn_references */
#else
#define __weak_reference(sym,alias) \
__asm__(".stabs \"_/**/alias\",11,0,0,0"); \
__asm__(".stabs \"_/**/sym\",1,0,0,0")
#ifndef __warn_references
#define __warn_references(sym,msg) \
__asm__(".stabs msg,30,0,0,0"); \
__asm__(".stabs \"_/**/sym\",1,0,0,0")
#endif /* __warn_references */
#endif /* __STDC__ */
#endif /* __ELF__ */
#endif /* __weak_reference */