Make ANSI mode closer to being ANSI

This commit is contained in:
Justine Tunney 2021-02-03 17:14:17 -08:00
parent 28135b7a20
commit 46085797b6
23 changed files with 352 additions and 92 deletions

View file

@ -6,7 +6,7 @@
/**
* Divides integer in half w/ rounding.
*/
#define HALF(X) (((X) + 1) / (2 / TYPE_INTEGRAL(typeof(X))))
#define HALF(X) (((X) + 1) / 2)
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_DSP_CORE_HALF_H_ */

View file

@ -13,17 +13,17 @@ extern const uint8_t kReverseBits[256];
uint32_t gray(uint32_t) pureconst;
uint32_t ungray(uint32_t) pureconst;
uint8_t bitreverse8(uint8_t) libcesque pureconst;
uint16_t bitreverse16(uint16_t) libcesque pureconst;
uint32_t bitreverse32(uint32_t) libcesque pureconst;
uint64_t bitreverse64(uint64_t) libcesque pureconst;
unsigned long roundup2pow(unsigned long) libcesque pureconst;
unsigned long roundup2log(unsigned long) libcesque pureconst;
unsigned long rounddown2pow(unsigned long) libcesque pureconst;
unsigned long hamming(unsigned long, unsigned long) pureconst;
intptr_t lockxchg(void *, void *, size_t);
bool cmpxchg(void *, intptr_t, intptr_t, size_t);
bool lockcmpxchg(void *, intptr_t, intptr_t, size_t);
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § bits » no assembly required
@ -70,38 +70,6 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
(uint64_t)((unsigned char *)(S))[6] << 010 | \
(uint64_t)((unsigned char *)(S))[7] << 000)
#define read16le(S) \
({ \
unsigned char *Str = (unsigned char *)(S); \
READ16LE(Str); \
})
#define read32le(S) \
({ \
unsigned char *Str = (unsigned char *)(S); \
READ32LE(Str); \
})
#define read64le(S) \
({ \
unsigned char *Str = (unsigned char *)(S); \
READ64LE(Str); \
})
#define read16be(S) \
({ \
unsigned char *Str = (unsigned char *)(S); \
READ16BE(Str); \
})
#define read32be(S) \
({ \
unsigned char *Str = (unsigned char *)(S); \
READ32BE(Str); \
})
#define read64be(S) \
({ \
unsigned char *Str = (unsigned char *)(S); \
READ64BE(Str); \
})
#define WRITE16LE(P, V) \
do { \
uint8_t *Ple = (uint8_t *)(P); \
@ -165,6 +133,7 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § bits » some assembly required
*/
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
/*
* Constraints for virtual machine flags.
@ -271,13 +240,6 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
*(LOCALVAR); \
})
/**
* Compares and exchanges.
*
* @param IFTHING is uint𝑘_t[hasatleast 1] where 𝑘 {8,16,32,64}
* @return true if value was exchanged, otherwise false
* @see lockcmpxchg()
*/
#define cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
({ \
bool DidIt; \
@ -291,13 +253,6 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
DidIt; \
})
/**
* Compares and exchanges w/ one operation.
*
* @param IFTHING is uint𝑘_t[hasatleast 1] where 𝑘 {8,16,32,64}
* @return true if value was exchanged, otherwise false
* @see lockcmpxchg()
*/
#define lockcmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
({ \
bool DidIt; \
@ -402,6 +357,14 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
OldBit; \
})
#else
#define cmpxchg(MEM, CMP, VAL) \
cmpxchg(MEM, (intptr_t)(CMP), (intptr_t)(VAL), sizeof(*(MEM)))
#define lockcmpxchg(MEM, CMP, VAL) \
lockcmpxchg(MEM, (intptr_t)(CMP), (intptr_t)(VAL), sizeof(*(MEM)))
#define lockxchg(MEM, VAR) \
lockxchg(MEM, VAR, sizeof(*(MEM)) / (sizeof(*(MEM)) == sizeof(*(VAR))))
#endif /* __GNUC__ && !__STRICT_ANSI__ */
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_BITS_H_ */

47
libc/bits/cmpxchg.c Normal file
View file

@ -0,0 +1,47 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2021 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or 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.
*/
#include "libc/bits/bits.h"
/**
* Compares and exchanges.
*
* @param ifthing is uint𝑘_t[hasatleast 1] where 𝑘 {8,16,32,64}
* @param size is automatically supplied by macro wrapper
* @return true if value was exchanged, otherwise false
* @see lockcmpxchg()
*/
bool(cmpxchg)(void *ifthing, intptr_t isequaltome, intptr_t replaceitwithme,
size_t size) {
switch (size) {
case 1:
return cmpxchg((int8_t *)ifthing, (int8_t)isequaltome,
(int8_t)replaceitwithme);
case 2:
return cmpxchg((int16_t *)ifthing, (int16_t)isequaltome,
(int16_t)replaceitwithme);
case 4:
return cmpxchg((int32_t *)ifthing, (int32_t)isequaltome,
(int32_t)replaceitwithme);
case 8:
return cmpxchg((int64_t *)ifthing, (int64_t)isequaltome,
(int64_t)replaceitwithme);
default:
return false;
}
}

47
libc/bits/lockcmpxchg.c Normal file
View file

@ -0,0 +1,47 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2021 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or 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.
*/
#include "libc/bits/bits.h"
/**
* Compares and exchanges w/ lock prefix.
*
* @param ifthing is uint𝑘_t[hasatleast 1] where 𝑘 {8,16,32,64}
* @param size is automatically supplied by macro wrapper
* @return true if value was exchanged, otherwise false
* @see cmpxchg()
*/
bool(lockcmpxchg)(void *ifthing, intptr_t isequaltome, intptr_t replaceitwithme,
size_t size) {
switch (size) {
case 1:
return lockcmpxchg((int8_t *)ifthing, (int8_t)isequaltome,
(int8_t)replaceitwithme);
case 2:
return lockcmpxchg((int16_t *)ifthing, (int16_t)isequaltome,
(int16_t)replaceitwithme);
case 4:
return lockcmpxchg((int32_t *)ifthing, (int32_t)isequaltome,
(int32_t)replaceitwithme);
case 8:
return lockcmpxchg((int64_t *)ifthing, (int64_t)isequaltome,
(int64_t)replaceitwithme);
default:
return false;
}
}

42
libc/bits/lockxchg.c Normal file
View file

@ -0,0 +1,42 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2021 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or 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.
*/
#include "libc/bits/bits.h"
/**
* Compares and exchanges w/ lock prefix.
*
* @param memory is uint𝑘_t[hasatleast 1] where 𝑘 {8,16,32,64}
* @param size is automatically supplied by macro wrapper
* @return true if value was exchanged, otherwise false
* @see xchg()
*/
intptr_t(lockxchg)(void *memory, void *localvar, size_t size) {
switch (size) {
case 1:
return lockxchg((int8_t *)memory, (int8_t *)localvar);
case 2:
return lockxchg((int16_t *)memory, (int16_t *)localvar);
case 4:
return lockxchg((int32_t *)memory, (int32_t *)localvar);
case 8:
return lockxchg((int64_t *)memory, (int64_t *)localvar);
default:
return false;
}
}

View file

@ -1,6 +1,7 @@
#ifndef COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_
#define COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
/**
* Reads scalar from memory, offset by segment.
@ -19,5 +20,6 @@
Pk; \
})
#endif /* __GNUC__ && !__STRICT_ANSI__ */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_ */

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_INTERNAL_H_
#ifndef __STRICT_ANSI__
#include "libc/calls/calls.h"
#include "libc/calls/struct/iovec.h"
#include "libc/calls/struct/itimerval.h"
@ -307,5 +306,4 @@ ssize_t writev$serial(struct Fd *, const struct iovec *, int) hidden;
#undef u64
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* !ANSI */
#endif /* COSMOPOLITAN_LIBC_CALLS_INTERNAL_H_ */

View file

@ -52,12 +52,12 @@ int serializednsheader(uint8_t *buf, size_t size,
int deserializednsheader(struct DnsHeader *header, const uint8_t *buf,
size_t size) {
if (size < 12) return ebadmsg();
header->id = read16be(buf + 0);
header->id = READ16BE(buf + 0);
header->bf1 = buf[2];
header->bf2 = buf[3];
header->qdcount = read16be(buf + 4);
header->ancount = read16be(buf + 6);
header->nscount = read16be(buf + 8);
header->arcount = read16be(buf + 10);
header->qdcount = READ16BE(buf + 4);
header->ancount = READ16BE(buf + 6);
header->nscount = READ16BE(buf + 8);
header->arcount = READ16BE(buf + 10);
return 12;
}

View file

@ -94,7 +94,7 @@ int resolvedns(const struct ResolvConf *resolvconf, int af, const char *name,
rtype = READ16BE(p), p += 2;
rclass = READ16BE(p), p += 2;
/* ttl */ p += 4;
rdlength = read16be(p), p += 2;
rdlength = READ16BE(p), p += 2;
if (p + rdlength <= pe && rdlength == 4 &&
(rtype == DNS_TYPE_A && rclass == DNS_CLASS_IN)) {
res = 1;

View file

@ -10,10 +10,6 @@
#define COSMOPOLITAN_CXX_USING_
#endif
#ifdef __STRICT_ANSI__
#define asm __asm__
#endif
#ifndef __ia16__
#define __far
#endif
@ -758,28 +754,45 @@ typedef uint64_t uintmax_t;
#endif /* ANSI */
#endif /* -w */
#ifdef __STRICT_ANSI__
#define DebugBreak() asm("int3")
#else
#define DebugBreak() (void)0
#endif
#ifdef __STRICT_ANSI__
#define VEIL(CONSTRAINT, EXPRESSION) \
({ \
autotype(EXPRESSION) VeiledValue = (EXPRESSION); \
asm("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
VeiledValue; \
})
#else
#define VEIL(CONSTRAINT, EXPRESSION) (EXPRESSION)
#endif
#ifdef __STRICT_ANSI__
#define CONCEAL(CONSTRAINT, EXPRESSION) \
({ \
autotype(EXPRESSION) VeiledValue = (EXPRESSION); \
asm volatile("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
VeiledValue; \
})
#else
#define CONCEAL(CONSTRAINT, EXPRESSION) (EXPRESSION)
#endif
#ifdef __STRICT_ANSI__
#define EXPROPRIATE(EXPRESSION) \
({ \
asm volatile("" ::"g"(EXPRESSION) : "memory"); \
0; \
})
#else
#define EXPROPRIATE(EXPRESSION) (EXPRESSION)
#endif
#ifdef __STRICT_ANSI__
#define YOINK(SYMBOL) \
do { \
_Static_assert(!__builtin_types_compatible_p(typeof(SYMBOL), char[]), \
@ -790,11 +803,18 @@ typedef uint64_t uintmax_t;
: /* no outputs */ \
: "X"(SYMBOL)); \
} while (0)
#else
#define YOINK(SYMBOL) (void)0
#endif
#ifdef __STRICT_ANSI__
#define STATIC_YOINK(SYMBOLSTR) \
asm(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous")
#else
#define STATIC_YOINK(SYMBOLSTR)
#endif
#if !defined(IM_FEELING_NAUGHTY) && !defined(__STRICT_ANSI__)
#if !defined(IM_FEELING_NAUGHTY)
#define STATIC_YOINK_SOURCE(PATH) STATIC_YOINK(PATH)
#else
#define STATIC_YOINK_SOURCE(PATH)

View file

@ -34,6 +34,13 @@
#define __x86__ 1
#endif
#ifdef _MSC_VER
#define __STRICT_ANSI__
#ifndef __STDC__
#define __STDC__
#endif
#endif
#ifndef __has_attribute
#define __has_attribute(x) 0
#endif

View file

@ -26,8 +26,8 @@
/ To protect their legacy, all 19 functions have been implemented
/ in just 17 bytes.
/
/ @see READ32LE(), READ32BE(), etc.
/ @asyncsignalsafe
/ @see read32le(), read32be(), etc.
bswap_64:
htobe64:

View file

@ -27,7 +27,7 @@ COSMOPOLITAN_C_START_
cosmopolitan § lz4 » frames
*/
#define LZ4_MAGIC(FRAME) read32le(FRAME)
#define LZ4_MAGIC(FRAME) READ32LE(FRAME)
#define LZ4_FRAME_VERSION(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 6) & 0b11)
#define LZ4_FRAME_BLOCKINDEPENDENCE(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 5) & 1)
#define LZ4_FRAME_BLOCKCHECKSUMFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 4) & 1)
@ -40,10 +40,10 @@ COSMOPOLITAN_C_START_
#define LZ4_FRAME_RESERVED2(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 7) & 1)
#define LZ4_FRAME_RESERVED3(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 0) & 0b1111)
#define LZ4_FRAME_BLOCKCONTENTSIZE(FRAME) \
(LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ? read64le((FRAME) + 4 + 1 + 1) : 0)
(LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ? READ64LE((FRAME) + 4 + 1 + 1) : 0)
#define LZ4_FRAME_DICTIONARYID(FRAME) \
(LZ4_FRAME_DICTIONARYIDFLAG(FRAME) \
? read32le(((FRAME) + 4 + 1 + 1 + \
? READ32LE(((FRAME) + 4 + 1 + 1 + \
8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME))) \
: 0)
#define LZ4_FRAME_HEADERCHECKSUM(FRAME) \
@ -60,9 +60,9 @@ COSMOPOLITAN_C_START_
*/
#define LZ4_BLOCK_DATA(block) (block + sizeof(uint32_t))
#define LZ4_BLOCK_DATASIZE(block) (read32le(block) & 0x7fffffff)
#define LZ4_BLOCK_ISEOF(block) (read32le(block) == LZ4_EOF)
#define LZ4_BLOCK_ISCOMPRESSED(block) ((read32le(block) & 0x80000000) == 0)
#define LZ4_BLOCK_DATASIZE(block) (READ32LE(block) & 0x7fffffff)
#define LZ4_BLOCK_ISEOF(block) (READ32LE(block) == LZ4_EOF)
#define LZ4_BLOCK_ISCOMPRESSED(block) ((READ32LE(block) & 0x80000000) == 0)
#define LZ4_BLOCK_SIZE(frame, block) \
(sizeof(uint32_t) + LZ4_BLOCK_DATASIZE(block) + \
(LZ4_FRAME_BLOCKCHECKSUMFLAG(frame) ? sizeof(uint8_t) : 0))

View file

@ -3,6 +3,7 @@
#include "libc/bits/segmentation.h"
#include "libc/nt/struct/peb.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
/*
* These macros address directly into NT's TEB a.k.a. TIB
@ -22,5 +23,6 @@
#define _NtGetRpc() gs((void **)(0x50))
#define _NtGetTls() gs((void **)(0x58))
#endif /* __GNUC__ && !__STRICT_ANSI__ */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_NT_TEB_H_ */

View file

@ -31,7 +31,7 @@ textstartup static void g_rando32_init() {
for (; *auxvp; auxvp += 2) {
if (*auxvp == AT_RANDOM) {
uint8_t(*sysrandseed)[16] = (uint8_t(*)[16])auxvp[1];
if (sysrandseed) g_rando32 ^= read32le(&(*sysrandseed)[8]);
if (sysrandseed) g_rando32 ^= READ32LE(&(*sysrandseed)[8]);
return;
}
}

View file

@ -31,7 +31,7 @@ textstartup static void g_rando64_init() {
for (; auxvp[0]; auxvp += 2) {
if (auxvp[0] == AT_RANDOM) {
uint8_t(*sysrandseed)[16] = (uint8_t(*)[16])auxvp[1];
if (sysrandseed) g_rando64 ^= read64le(&(*sysrandseed)[0]);
if (sysrandseed) g_rando64 ^= READ64LE(&(*sysrandseed)[0]);
return;
}
}

View file

@ -118,7 +118,7 @@ forceinline void sockaddr2bsd(void *saddr) {
uint16_t fam;
if (saddr) {
p = saddr;
fam = read16le(p);
fam = READ16LE(p);
p[0] = sizeof(struct sockaddr_in$bsd);
p[1] = fam;
}

View file

@ -45,7 +45,7 @@ textstartup void *lz4cpy(void *dest, const void *blockdata, size_t blocksize) {
}
repmovsb(&op, &ip, length);
if (ip >= ipe) break;
offset = read16le(ip);
offset = READ16LE(ip);
matchlen = token & fifteen;
ip += 2;
if (matchlen == fifteen) {

View file

@ -21,15 +21,146 @@
* @see libc/sysv/errfuns.inc (for implementation)
*/
intptr_t einval(void) relegated;
intptr_t eperm(void) relegated;
intptr_t enoent(void) relegated;
intptr_t esrch(void) relegated;
intptr_t eintr(void) relegated;
intptr_t eio(void) relegated;
intptr_t enxio(void) relegated;
intptr_t e2big(void) relegated;
intptr_t enoexec(void) relegated;
intptr_t ebadf(void) relegated;
intptr_t echild(void) relegated;
intptr_t eagain(void) relegated;
intptr_t enomem(void) relegated;
intptr_t eacces(void) relegated;
intptr_t efault(void) relegated;
intptr_t enotblk(void) relegated;
intptr_t ebusy(void) relegated;
intptr_t eexist(void) relegated;
intptr_t exdev(void) relegated;
intptr_t enodev(void) relegated;
intptr_t enotdir(void) relegated;
intptr_t eisdir(void) relegated;
intptr_t enfile(void) relegated;
intptr_t emfile(void) relegated;
intptr_t enotty(void) relegated;
intptr_t enotsup(void) relegated;
intptr_t etxtbsy(void) relegated;
intptr_t efbig(void) relegated;
intptr_t enospc(void) relegated;
intptr_t espipe(void) relegated;
intptr_t erofs(void) relegated;
intptr_t emlink(void) relegated;
intptr_t epipe(void) relegated;
intptr_t edom(void) relegated;
intptr_t erange(void) relegated;
intptr_t edeadlk(void) relegated;
intptr_t enametoolong(void) relegated;
intptr_t enolck(void) relegated;
intptr_t enosys(void) relegated;
intptr_t enotempty(void) relegated;
intptr_t eloop(void) relegated;
intptr_t enomsg(void) relegated;
intptr_t eidrm(void) relegated;
intptr_t echrng(void) relegated;
intptr_t el2nsync(void) relegated;
intptr_t el3hlt(void) relegated;
intptr_t el3rst(void) relegated;
intptr_t elnrng(void) relegated;
intptr_t eunatch(void) relegated;
intptr_t enocsi(void) relegated;
intptr_t el2hlt(void) relegated;
intptr_t ebade(void) relegated;
intptr_t ebadr(void) relegated;
intptr_t exfull(void) relegated;
intptr_t enoano(void) relegated;
intptr_t ebadrqc(void) relegated;
intptr_t ebadslt(void) relegated;
intptr_t enostr(void) relegated;
intptr_t enodata(void) relegated;
intptr_t etime(void) relegated;
intptr_t enosr(void) relegated;
intptr_t enonet(void) relegated;
intptr_t enopkg(void) relegated;
intptr_t eremote(void) relegated;
intptr_t enolink(void) relegated;
intptr_t eadv(void) relegated;
intptr_t esrmnt(void) relegated;
intptr_t ecomm(void) relegated;
intptr_t eproto(void) relegated;
intptr_t emultihop(void) relegated;
intptr_t edotdot(void) relegated;
intptr_t ebadmsg(void) relegated;
intptr_t eoverflow(void) relegated;
intptr_t enotuniq(void) relegated;
intptr_t ebadfd(void) relegated;
intptr_t eremchg(void) relegated;
intptr_t elibacc(void) relegated;
intptr_t elibbad(void) relegated;
intptr_t elibscn(void) relegated;
intptr_t elibmax(void) relegated;
intptr_t elibexec(void) relegated;
intptr_t eilseq(void) relegated;
intptr_t erestart(void) relegated;
intptr_t estrpipe(void) relegated;
intptr_t eusers(void) relegated;
intptr_t enotsock(void) relegated;
intptr_t edestaddrreq(void) relegated;
intptr_t emsgsize(void) relegated;
intptr_t eprototype(void) relegated;
intptr_t enoprotoopt(void) relegated;
intptr_t eprotonosupport(void) relegated;
intptr_t esocktnosupport(void) relegated;
intptr_t eopnotsupp(void) relegated;
intptr_t epfnosupport(void) relegated;
intptr_t eafnosupport(void) relegated;
intptr_t eaddrinuse(void) relegated;
intptr_t eaddrnotavail(void) relegated;
intptr_t enetdown(void) relegated;
intptr_t enetunreach(void) relegated;
intptr_t enetreset(void) relegated;
intptr_t econnaborted(void) relegated;
intptr_t econnreset(void) relegated;
intptr_t enobufs(void) relegated;
intptr_t eisconn(void) relegated;
intptr_t enotconn(void) relegated;
intptr_t eshutdown(void) relegated;
intptr_t etoomanyrefs(void) relegated;
intptr_t etimedout(void) relegated;
intptr_t econnrefused(void) relegated;
intptr_t ehostdown(void) relegated;
intptr_t ehostunreach(void) relegated;
intptr_t ealready(void) relegated;
intptr_t einprogress(void) relegated;
intptr_t estale(void) relegated;
intptr_t euclean(void) relegated;
intptr_t enotnam(void) relegated;
intptr_t enavail(void) relegated;
intptr_t eisnam(void) relegated;
intptr_t eremoteio(void) relegated;
intptr_t edquot(void) relegated;
intptr_t enomedium(void) relegated;
intptr_t emediumtype(void) relegated;
intptr_t ecanceled(void) relegated;
intptr_t enokey(void) relegated;
intptr_t ekeyexpired(void) relegated;
intptr_t ekeyrevoked(void) relegated;
intptr_t ekeyrejected(void) relegated;
intptr_t eownerdead(void) relegated;
intptr_t enotrecoverable(void) relegated;
intptr_t erfkill(void) relegated;
intptr_t ehwpoison(void) relegated;
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define __ERRFUN(FUNC) \
({ \
intptr_t NegOne; \
asm("call\t" FUNC : "=a"(NegOne), "=m"(errno)); \
NegOne; \
})
int einval(void) relegated;
#define einval() __ERRFUN("einval")
#define eperm() __ERRFUN("eperm")
#define enoent() __ERRFUN("enoent")
#define esrch() __ERRFUN("esrch")
@ -160,6 +291,7 @@ int einval(void) relegated;
#define enotrecoverable() __ERRFUN("enotrecoverable")
#define erfkill() __ERRFUN("erfkill")
#define ehwpoison() __ERRFUN("ehwpoison")
#endif
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SYSV_ERRFUNS_H_ */

View file

@ -367,7 +367,7 @@ int ReadResponse(void) {
goto drop;
case kRunitStderr:
CHECK_GE(n, 4);
size = read32be(p), p += 4, n -= 4;
size = READ32BE(p), p += 4, n -= 4;
while (size) {
if (n) {
CHECK_NE(-1, (rc = write(STDERR_FILENO, p, min(n, size))));

View file

@ -263,12 +263,12 @@ void HandleClient(void) {
got = recv(g_clifd, (p = &g_buf[0]), sizeof(g_buf), 0);
CHECK_GE(got, kMinMsgSize);
CHECK_LE(got, sizeof(g_buf));
CHECK_EQ(RUNITD_MAGIC, read32be(p));
CHECK_EQ(RUNITD_MAGIC, READ32BE(p));
p += 4, got -= 4;
CHECK_EQ(kRunitExecute, *p++);
got--;
namesize = read32be(p), p += 4, got -= 4;
filesize = read32be(p), p += 4, got -= 4;
namesize = READ32BE(p), p += 4, got -= 4;
filesize = READ32BE(p), p += 4, got -= 4;
CHECK_GE(got, namesize);
CHECK_LE(namesize, kMaxNameSize);
CHECK_LE(filesize, kMaxFileSize);

View file

@ -100,7 +100,7 @@ static void Print(void) {
arsize = atoi((char *)(data + 8 + 48));
CHECK_LE(4, arsize);
CHECK_LE(8 + 60 + arsize, size);
entries = read32be(data + 8 + 60);
entries = READ32BE(data + 8 + 60);
CHECK_LE(4 + entries * 4 + 1, arsize);
printf("\t# %'s\n", path);
PrintString(data, 8, "file signature");
@ -110,7 +110,7 @@ static void Print(void) {
printf("\t.long\t%u\t\t\t# %s\n", entries, "symbol table entries");
table = 8 + 60 + 4;
for (i = 0; i < entries; ++i) {
printf("\t.long\t%#x\t\t\t\t# %u\n", read32be(data + table + i * 4), i);
printf("\t.long\t%#x\t\t\t\t# %u\n", READ32BE(data + table + i * 4), i);
}
symbols = table + entries * 4;
symbolslen = arsize - (4 + entries * 4);

View file

@ -94,22 +94,22 @@ void showcompressmethod(uint16_t compressmethod) {
void showextrantfs(uint8_t *ntfs) {
struct timespec mtime, atime, ctime;
mtime = FileTimeToTimeSpec(
(struct NtFileTime){read32le(ntfs + 8), read32le(ntfs + 12)});
(struct NtFileTime){READ32LE(ntfs + 8), READ32LE(ntfs + 12)});
atime = FileTimeToTimeSpec(
(struct NtFileTime){read32le(ntfs + 16), read32le(ntfs + 20)});
(struct NtFileTime){READ32LE(ntfs + 16), READ32LE(ntfs + 20)});
ctime = FileTimeToTimeSpec(
(struct NtFileTime){read32le(ntfs + 24), read32le(ntfs + 28)});
show(".long", gc(xasprintf("%d", read32le(ntfs))), "ntfs reserved");
show(".short", gc(xasprintf("0x%04x", read16le(ntfs + 4))),
(struct NtFileTime){READ32LE(ntfs + 24), READ32LE(ntfs + 28)});
show(".long", gc(xasprintf("%d", READ32LE(ntfs))), "ntfs reserved");
show(".short", gc(xasprintf("0x%04x", READ16LE(ntfs + 4))),
"ntfs attribute tag value #1");
show(".short", gc(xasprintf("%hu", read16le(ntfs + 6))),
show(".short", gc(xasprintf("%hu", READ16LE(ntfs + 6))),
"ntfs attribute tag size");
show(".quad", gc(xasprintf("%lu", read64le(ntfs + 8))),
show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 8))),
gc(xasprintf("%s (%s)", "ntfs last modified time",
gc(xiso8601(&mtime)))));
show(".quad", gc(xasprintf("%lu", read64le(ntfs + 16))),
show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 16))),
gc(xasprintf("%s (%s)", "ntfs last access time", gc(xiso8601(&atime)))));
show(".quad", gc(xasprintf("%lu", read64le(ntfs + 24))),
show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 24))),
gc(xasprintf("%s (%s)", "ntfs creation time", gc(xiso8601(&ctime)))));
}