aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTheo Buehler <tb@openbsd.org>2026-04-19 12:07:09 +0200
committerTheo Buehler <tb@openbsd.org>2026-04-19 12:23:39 +0200
commit47003a364c2f62482a0f8e8f9090269937384099 (patch)
tree52cd6d87e6cc9008f83523153d3407d5b3589013 /include
parent87b017d54d7e5e9010d7126eefdad900425bce01 (diff)
downloadportable-47003a364c2f62482a0f8e8f9090269937384099.tar.gz
portable-47003a364c2f62482a0f8e8f9090269937384099.tar.bz2
portable-47003a364c2f62482a0f8e8f9090269937384099.zip
Allow building on AIX
From @AIIleG in #1116 Fixes #1116
Diffstat (limited to 'include')
-rw-r--r--include/compat/endian.h67
-rw-r--r--include/compat/syslog.h20
2 files changed, 87 insertions, 0 deletions
diff --git a/include/compat/endian.h b/include/compat/endian.h
index af3664d..89c83fc 100644
--- a/include/compat/endian.h
+++ b/include/compat/endian.h
@@ -158,4 +158,71 @@
158#define htobe64(x) BE_64(x) 158#define htobe64(x) BE_64(x)
159#endif 159#endif
160 160
161#ifdef _AIX /* AIX is always big endian */
162#include <stdint.h>
163#include <sys/types.h>
164
165static inline uint64_t htole64(uint64_t x) {
166#ifdef __BYTE_ORDER__
167#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
168 return x;
169#else
170 return ((uint64_t)x << 56) |
171 (((uint64_t)x & 0xFF00ULL) << 40) |
172 (((uint64_t)x & 0xFF0000ULL) << 24) |
173 (((uint64_t)x & 0xFF000000ULL) << 8) |
174 (((uint64_t)x & 0xFF00000000ULL) >> 8) |
175 (((uint64_t)x & 0xFF0000000000ULL) >> 24) |
176 (((uint64_t)x & 0xFF000000000000ULL) >> 40) |
177 ((uint64_t)x >> 56);
178#endif
179#else
180 /* Fallback for systems without __BYTE_ORDER__ */
181 union {
182 uint64_t u64;
183 unsigned char bytes[8];
184 } val;
185 val.u64 = x;
186 return ((uint64_t)val.bytes[0] << 56) |
187 ((uint64_t)val.bytes[1] << 48) |
188 ((uint64_t)val.bytes[2] << 40) |
189 ((uint64_t)val.bytes[3] << 32) |
190 ((uint64_t)val.bytes[4] << 24) |
191 ((uint64_t)val.bytes[5] << 16) |
192 ((uint64_t)val.bytes[6] << 8) |
193 (uint64_t)val.bytes[7];
194#endif
195}
196
197#define be64toh(x) (x)
198#define be32toh(x) (x)
199#define be16toh(x) (x)
200#define le32toh(x) \
201 ((((x) & 0xff) << 24) | \
202 (((x) & 0xff00) << 8) | \
203 (((x) & 0xff0000) >> 8) | \
204 (((x) & 0xff000000) >> 24))
205#define le64toh(x) \
206 ((((x) & 0x00000000000000ffL) << 56) | \
207 (((x) & 0x000000000000ff00L) << 40) | \
208 (((x) & 0x0000000000ff0000L) << 24) | \
209 (((x) & 0x00000000ff000000L) << 8) | \
210 (((x) & 0x000000ff00000000L) >> 8) | \
211 (((x) & 0x0000ff0000000000L) >> 24) | \
212 (((x) & 0x00ff000000000000L) >> 40) | \
213 (((x) & 0xff00000000000000L) >> 56))
214#ifndef htobe64
215#define htobe64(x) be64toh(x)
216#endif
217#ifndef htobe32
218#define htobe32(x) be32toh(x)
219#endif
220#ifndef htobe16
221#define htobe16(x) be16toh(x)
222#endif
223#ifndef htole32
224#define htole32(x) le32toh(x)
225#endif
226#endif
227
161#endif 228#endif
diff --git a/include/compat/syslog.h b/include/compat/syslog.h
index c7a2608..3528eb3 100644
--- a/include/compat/syslog.h
+++ b/include/compat/syslog.h
@@ -36,3 +36,23 @@ void vsyslog_r(int, struct syslog_data *, const char *, va_list);
36#endif 36#endif
37 37
38#endif 38#endif
39
40#ifdef _AIX
41#ifdef HAVE_SYSLOG
42#include <stdlib.h>
43void vsyslog(int facility_priority, const char *format, va_list arglist) {
44 char *msg = NULL;
45 vasprintf(&msg, format, arglist);
46
47 if (!msg)
48 return;
49
50 syslog(facility_priority, "%s", msg);
51 free(msg);
52}
53#endif /* HAVE_SYSLOG */
54
55void vsyslog_r(int pri, struct syslog_data *data, const char *fmt, va_list ap) {
56 vsyslog(pri, fmt, ap);
57}
58#endif /* AIX */