1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*
3  * Copyright (c) 1994-2009  Red Hat, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * 3. Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from this
18  * software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /* Provide support for both ANSI and non-ANSI environments.  */
34 
35 /* Some ANSI environments are "broken" in the sense that __STDC__ cannot be
36    relied upon to have it's intended meaning.  Therefore we must use our own
37    concoction: _HAVE_STDC.  Always use _HAVE_STDC instead of __STDC__ in newlib
38    sources!
39 
40    To get a strict ANSI C environment, define macro __STRICT_ANSI__.  This will
41    "comment out" the non-ANSI parts of the ANSI header files (non-ANSI header
42    files aren't affected).  */
43 
44 #ifndef _ANSIDECL_H_
45 #define _ANSIDECL_H_
46 
47 /*#include <newlib.h> */
48 /*#include <sys/config.h> */
49 
50 /*
51  * First try to figure out whether we really are in an ANSI C environment.
52  * This probably needs some work.  Perhaps sys/config.h can be
53  * prevailed upon to give us a clue.
54  */
55 
56 #ifdef __STDC__
57 #define _HAVE_STDC
58 #endif
59 
60 #ifdef _HAVE_STDC
61 #define _PTR    void *
62 #define _AND    ,
63 #define _NOARGS   void
64 #define _CONST    const
65 #define _VOLATILE volatile
66 #define _SIGNED   signed
67 #define _DOTS   , ...
68 #define _VOID void
69 #ifdef __CYGWIN__
70 #define _EXFUN(name, proto)   __cdecl name proto
71 #define _EXPARM(name, proto)    (* __cdecl name) proto
72 #else
73 #define _EXFUN(name, proto)   name proto
74 #define _EXPARM(name, proto)    (* name) proto
75 #endif
76 #define _DEFUN(name, arglist, args) name(args)
77 #define _DEFUN_VOID(name)   name(_NOARGS)
78 #define _CAST_VOID (void)
79 #ifndef _LONG_DOUBLE
80 #define _LONG_DOUBLE long double
81 #endif
82 #ifndef _PARAMS
83 #define _PARAMS(paramlist)    paramlist
84 #endif
85 #else
86 #define _PTR    char *
87 #define _AND    ;
88 #define _NOARGS
89 #define _CONST
90 #define _VOLATILE
91 #define _SIGNED
92 #define _DOTS
93 #define _VOID void
94 #define _EXFUN(name, proto)   name()
95 #define _DEFUN(name, arglist, args) name arglist args;
96 #define _DEFUN_VOID(name)   name()
97 #define _CAST_VOID
98 #define _LONG_DOUBLE double
99 #ifndef _PARAMS
100 #define _PARAMS(paramlist)    ()
101 #endif
102 #endif
103 
104 /* Support gcc's __attribute__ facility.  */
105 
106 #ifdef __GNUC__
107 #define _ATTRIBUTE(attrs) __attribute__ (attrs)
108 #else
109 #define _ATTRIBUTE(attrs)
110 #endif
111 
112 /*  ISO C++.  */
113 
114 #ifdef __cplusplus
115 #if !(defined(_BEGIN_STD_C) && defined(_END_STD_C))
116 #ifdef _HAVE_STD_CXX
117 #define _BEGIN_STD_C namespace std { extern "C" {
118 #define _END_STD_C  } }
119 #else
120 #define _BEGIN_STD_C extern "C" {
121 #define _END_STD_C  }
122 #endif
123 #endif
124 #else
125 #define _BEGIN_STD_C
126 #define _END_STD_C
127 #endif
128 
129 #endif /* _ANSIDECL_H_ */
130