Debian Codegraph @

compat.h

raw symbols SCIP
1 /*-
2 * Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
3 * 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018,
4 * 2019, 2020
5 * mirabilos <[email protected]>
6 * Copyright © 2018
7 * mirabilos <[email protected]>
8 *
9 * Provided that these terms and disclaimer and all copyright notices
10 * are retained or reproduced in an accompanying document, permission
11 * is granted to deal in this work without restriction, including un‐
12 * limited rights to use, publicly perform, distribute, sell, modify,
13 * merge, give away, or sublicence.
14 *
15 * This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
16 * the utmost extent permitted by applicable law, neither express nor
17 * implied; without malicious intent or gross negligence. In no event
18 * may a licensor, author or contributor be held liable for indirect,
19 * direct, other damage, loss, or other issues arising in any way out
20 * of dealing in the work, even if advised of the possibility of such
21 * damage or existence of a defect, except proven that it results out
22 * of said person’s immediate fault when using the work as intended.
23 */
24
25 #ifdef MKSH_USE_AUTOCONF_H
26 /* things that “should” have been on the command line */
27 #include "autoconf.h"
28 #undef MKSH_USE_AUTOCONF_H
29 #endif
30
31 #ifndef PAX_COMPAT_H
32 #define PAX_COMPAT_H
33 #undef MBSDPORT_H
34
35 #ifdef __MirBSD__
36 #include <sys/param.h>
37 #else
38 #include <sys/types.h>
39 #endif
40 #if HAVE_SYS_MKDEV_H
41 #include <sys/mkdev.h>
42 #endif
43 #if HAVE_SYS_SYSMACROS_H
44 #include <sys/sysmacros.h>
45 #endif
46 #if HAVE_STDINT_H
47 #include <stdint.h>
48 #endif
49
50 #include ".linked/mbsdcc.h"
51
52 #undef __attribute__
53 #if HAVE_ATTRIBUTE_BOUNDED
54 #define MKSH_A_BOUNDED(x,y,z) __attribute__((__bounded__(x, y, z)))
55 #else
56 #define MKSH_A_BOUNDED(x,y,z) /* nothing */
57 #endif
58 #if HAVE_ATTRIBUTE_FORMAT
59 #define MKSH_A_FORMAT(x,y,z) __attribute__((__format__(x, y, z)))
60 #else
61 #define MKSH_A_FORMAT(x,y,z) /* nothing */
62 #endif
63 #if HAVE_ATTRIBUTE_NONNULL
64 #define MKSH_A_NONNULL(x) __attribute__((__nonnull__(x)))
65 #else
66 #define MKSH_A_NONNULL(x) /* nothing */
67 #endif
68 #if HAVE_ATTRIBUTE_NORETURN
69 #define MKSH_A_NORETURN __attribute__((__noreturn__))
70 #else
71 #define MKSH_A_NORETURN /* nothing */
72 #endif
73 #if HAVE_ATTRIBUTE_PURE
74 #define MKSH_A_PURE __attribute__((__pure__))
75 #else
76 #define MKSH_A_PURE /* nothing */
77 #endif
78 #if HAVE_ATTRIBUTE_UNUSED
79 #define MKSH_A_UNUSED __attribute__((__unused__))
80 #else
81 #define MKSH_A_UNUSED /* nothing */
82 #endif
83 #if HAVE_ATTRIBUTE_USED
84 #define MKSH_A_USED __attribute__((__used__))
85 #else
86 #define MKSH_A_USED /* nothing */
87 #endif
88
89 #if defined(MirBSD) && (MirBSD >= 0x09A1) && \
90 defined(__ELF__) && defined(__GNUC__) && \
91 !defined(__llvm__) && !defined(__NWCC__)
92 /*
93 * We got usable __IDSTRING __COPYRIGHT __RCSID __SCCSID macros
94 * which work for all cases; no need to redefine them using the
95 * "portable" macros from below when we might have the "better"
96 * gcc+ELF specific macros or other system dependent ones.
97 */
98 #else
99 #undef __IDSTRING
100 #undef __IDSTRING_CONCAT
101 #undef __IDSTRING_EXPAND
102 #undef __COPYRIGHT
103 #undef __RCSID
104 #undef __SCCSID
105 #define __IDSTRING_CONCAT(l,p) __LINTED__ ## l ## _ ## p
106 #define __IDSTRING_EXPAND(l,p) __IDSTRING_CONCAT(l,p)
107 #ifdef MKSH_DONT_EMIT_IDSTRING
108 #define __IDSTRING(prefix,string) /* nothing */
109 #else
110 #define __IDSTRING(prefix,string) \
111 static const char __IDSTRING_EXPAND(__LINE__,prefix) [] \
112 MKSH_A_USED = "@(""#)" #prefix ": " string
113 #endif
114 #define __COPYRIGHT(x) __IDSTRING(copyright,x)
115 #define __RCSID(x) __IDSTRING(rcsid,x)
116 #define __SCCSID(x) __IDSTRING(sccsid,x)
117 #endif
118
119 #ifdef EXTERN
120 __IDSTRING(rcsid_compat_h, "$MirOS: src/bin/pax/compat.h,v 1.15 2024/08/17 23:33:51 tg Exp $");
121 __IDSTRING(rcsid_mbsdcc_h, SYSKERN_MBSDCC_H);
122 #endif
123
124 /* possibly missing types */
125
126 #if !HAVE_CAN_INTTYPES
127 #if !HAVE_CAN_UCBINTS
128 typedef signed int int32_t;
129 typedef unsigned int uint32_t;
130 #else
131 typedef u_int32_t uint32_t;
132 #endif
133 #endif
134
135 #if !HAVE_CAN_ULONG
136 typedef unsigned long u_long;
137 #endif
138
139 /* boolean type (no <stdbool.h> deliberately) */
140 typedef unsigned char Wahr;
141 #define Ja 1U
142 #define Nee 0U
143 #define isWahr(cond) ((cond) ? Ja : Nee)
144
145 /* missing macros / header bug workarounds */
146
147 #if !defined(LLONG_MIN) && defined(LONG_LONG_MIN)
148 #define LLONG_MIN LONG_LONG_MIN
149 #define LLONG_MAX LONG_LONG_MAX
150 #define ULLONG_MAX ULONG_LONG_MAX
151 #endif
152
153 /* macros dealing with types differing across systems */
154
155 #if HAVE_OFFT_LONG
156 #define OT_FMT "lu"
157 #else
158 #define OT_FMT "llu"
159 #endif
160
161 /* macros dealing with struct stat.sb_[acm]time */
162
163 #if HAVE_ST_MTIMENSEC
164 #define st_timecmp(x,sbpa,sbpb,op) ( \
165 ((sbpa)->st_ ## x ## time == (sbpb)->st_ ## x ## time) ? \
166 ((sbpa)->st_ ## x ## timensec op (sbpb)->st_ ## x ## timensec) : \
167 ((sbpa)->st_ ## x ## time op (sbpb)->st_ ## x ## time) \
168 )
169 #define st_timecpy(x,sbpd,sbps) do { \
170 (sbpd)->st_ ## x ## time = (sbps)->st_ ## x ## time; \
171 (sbpd)->st_ ## x ## timensec = (sbps)->st_ ## x ## timensec; \
172 } while (/* CONSTCOND */ 0)
173 #define st_timexp(x,ts,sbp) do { \
174 (ts)->tv_sec = (sbp)->st_ ## x ## time; \
175 (ts)->tv_nsec = (sbp)->st_ ## x ## timensec; \
176 } while (/* CONSTCOND */ 0)
177 #else
178 #define st_timecmp(x,sbpa,sbpb,op) \
179 ((sbpa)->st_ ## x ## time op (sbpb)->st_ ## x ## time)
180 #define st_timecpy(x,sbpd,sbps) do { \
181 (sbpd)->st_ ## x ## time = (sbps)->st_ ## x ## time; \
182 } while (/* CONSTCOND */ 0)
183 #define st_timexp(x,ts,sbp) do { \
184 (ts)->tv_sec = (sbp)->st_ ## x ## time; \
185 (ts)->tv_nsec = 0; \
186 } while (/* CONSTCOND */ 0)
187 #endif
188
189 /* compat.c */
190
191 #define BO__TWO 0x01 /* (internal use only) */
192 #define BO_CLEXEC 0x02 /* set close-on-exec flag or warn */
193 #define BO_MAYBE_DIR 0x04 /* add O_DIRECTORY if defined */
194 #define binopen2(feat,path,flags) binopen3((feat) | BO__TWO, (path), (flags), 0)
195 int binopen3(int, const char *, int, mode_t)
196 MKSH_A_NONNULL(2);
197
198 ssize_t dwrite(int, const void *, size_t)
199 MKSH_A_BOUNDED(__buffer__, 2, 3);
200
201 /* exclude system replacement functions in early link check */
202 #ifndef MIRTOCONF_EARLY
203
204 #if !HAVE_DPRINTF
205 /* replacement only as powerful as needed for this */
206 void dprintf(int, const char *, ...)
207 MKSH_A_NONNULL(2)
208 MKSH_A_FORMAT(__printf__, 2, 3);
209 #endif
210
211 #if !HAVE_REALLOCARRAY
212 void *reallocarray(void *, size_t, size_t);
213 #endif
214
215 #if !HAVE_STRLCPY
216 size_t strlcat(char *, const char *, size_t)
217 MKSH_A_BOUNDED(__string__, 1, 3);
218 size_t strlcpy(char *, const char *, size_t)
219 MKSH_A_BOUNDED(__string__, 1, 3);
220 #endif
221
222 #if !HAVE_STRMODE
223 void strmode(mode_t, char *);
224 #endif
225
226 #if !HAVE_STRTONUM
227 long long strtonum(const char *, long long, long long, const char **);
228 #endif
229
230 #endif /* !MIRTOCONF_EARLY */
231
232 #endif