Reduce header complexity

- Remove most __ASSEMBLER__ __LINKER__ ifdefs
- Rename libc/intrin/bits.h to libc/serialize.h
- Block pthread cancelation in fchmodat() polyfill
- Remove `clang-format off` statements in third_party
This commit is contained in:
Justine Tunney 2023-11-28 14:24:28 -08:00
parent 96f979dfc5
commit fa20edc44d
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
3057 changed files with 410 additions and 4398 deletions

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_ALG_H_
#define COSMOPOLITAN_LIBC_SOCK_ALG_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct sockaddr_alg {
@ -25,5 +24,4 @@ struct af_alg_iv {
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_ALG_H_ */

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_WEPOLL_H_
#define COSMOPOLITAN_LIBC_SOCK_WEPOLL_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#include "libc/calls/struct/sigset.h"
@ -23,5 +22,4 @@ int epoll_wait(int, struct epoll_event *, int, int);
int epoll_pwait(int, struct epoll_event *, int, int, const sigset_t *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_WEPOLL_H_ */

View file

@ -20,7 +20,7 @@
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/dce.h"
#include "libc/intrin/bits.h"
#include "libc/serialize.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/nt/errors.h"

View file

@ -1,11 +1,9 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_GOODSOCKET_H_
#define COSMOPOLITAN_LIBC_SOCK_GOODSOCKET_H_
#include "libc/calls/struct/timeval.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int GoodSocket(int, int, int, bool, const struct timeval *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_GOODSOCKET_H_ */

View file

@ -1,7 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_IFADDRS_H_
#define COSMOPOLITAN_LIBC_SOCK_IFADDRS_H_
#include "libc/sock/struct/sockaddr.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct ifaddrs {
@ -21,5 +20,4 @@ void freeifaddrs(struct ifaddrs *);
int getifaddrs(struct ifaddrs **);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_IFADDRS_H_ */

View file

@ -56,7 +56,11 @@ static int inet_pton_inet6_impl(const char *src, uint8_t *dst) {
if (zeroFound) {
return 0;
}
res = resTemp << (4 * digitsLeft);
if (digitsLeft == 32) {
res = 0;
} else {
res = resTemp << (4 * digitsLeft);
}
resTemp = 0;
digitsLeft -= 4;
zeroFound = true;

View file

@ -8,7 +8,6 @@
#include "libc/sock/select.h"
#include "libc/sock/sock.h"
#include "libc/sock/struct/sockaddr.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define kNtFdRead 1
@ -83,5 +82,4 @@ int64_t GetNtBaseSocket(int64_t);
int sys_close_epoll(int);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_INTERNAL_H_ */

View file

@ -5,7 +5,6 @@
#include "libc/sysv/consts/af.h"
#include "libc/sysv/consts/inaddr.h"
#include "libc/sysv/errfuns.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/**
@ -65,6 +64,5 @@ forceinline bool ispublicip(int sin_family, void *sin_addr) {
}
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* !ANSI */
#endif /* COSMOPOLITAN_LIBC_SOCK_IPCLASSIFY_H_ */

View file

@ -7,7 +7,6 @@
#define FD_SETSIZE 1024 /* it's 64 on windows */
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
typedef struct fd_set {
@ -25,5 +24,4 @@ int pselect(int, fd_set *, fd_set *, fd_set *, const struct timespec *,
const sigset_t *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_SELECT_H_ */

View file

@ -2,12 +2,10 @@
#define COSMOPOLITAN_LIBC_SOCK_SELECT_INTERNAL_H_
#include "libc/mem/alloca.h"
#include "libc/sock/select.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
const char *DescribeFdSet(char[100], ssize_t, int, fd_set *);
#define DescribeFdSet(x, y, z) DescribeFdSet(alloca(100), x, y, z)
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_SELECT_INTERNAL_H_ */

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_SENDFILE_INTERNAL_H_
#define COSMOPOLITAN_LIBC_SOCK_SENDFILE_INTERNAL_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int sys_sendfile_xnu(int32_t infd, int32_t outfd, int64_t offset,
@ -12,5 +11,4 @@ int sys_sendfile_freebsd(int32_t infd, int32_t outfd, int64_t offset,
int64_t *out_opt_sbytes, int32_t flags);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_SENDFILE_INTERNAL_H_ */

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_SOCK_H_
#define COSMOPOLITAN_LIBC_SOCK_SOCK_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define INET_ADDRSTRLEN 22
@ -35,5 +34,4 @@ int socketpair(int, int, int, int[2]);
int sockatmark(int);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_SOCK_H_ */

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_STRUCT_ARPHDR_H_
#define COSMOPOLITAN_LIBC_SOCK_STRUCT_ARPHDR_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct arphdr {
@ -12,5 +11,4 @@ struct arphdr {
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_STRUCT_ARPHDR_H_ */

View file

@ -1,7 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_STRUCT_ARPREQ_H_
#define COSMOPOLITAN_LIBC_SOCK_STRUCT_ARPREQ_H_
#include "libc/sock/struct/sockaddr.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct arpreq {
@ -13,5 +12,4 @@ struct arpreq {
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_STRUCT_ARPREQ_H_ */

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_STRUCT_CMSGHDR_H_
#define COSMOPOLITAN_LIBC_SOCK_STRUCT_CMSGHDR_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define CMSG_DATA(cmsg) ((unsigned char *)(((struct cmsghdr *)(cmsg)) + 1))
@ -38,5 +37,4 @@ struct cmsghdr { /* linux abi */
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_STRUCT_CMSGHDR_H_ */

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_STRUCT_CMSGHDR_INTERNAL_H_
#define COSMOPOLITAN_LIBC_SOCK_STRUCT_CMSGHDR_INTERNAL_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct cmsghdr_bsd {
@ -10,5 +9,4 @@ struct cmsghdr_bsd {
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_STRUCT_CMSGHDR_INTERNAL_H_ */

View file

@ -3,7 +3,6 @@
#define ETH_ALEN 6
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct ether_addr {
@ -17,5 +16,4 @@ struct ether_header {
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_STRUCT_ETHER_HEADER_H_ */

View file

@ -1,7 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_STRUCT_IFCONF_H_
#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IFCONF_H_
#include "libc/sock/struct/ifreq.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/*
@ -24,5 +23,4 @@ struct ifconf {
#define ifc_req ifc_ifcu.ifcu_req /* array of structures */
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_STRUCT_IFCONF_H_ */

View file

@ -1,7 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_STRUCT_IFREQ_H_
#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IFREQ_H_
#include "libc/sock/struct/sockaddr.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define IF_NAMESIZE 16
@ -29,5 +28,4 @@ struct ifreq {
#define ifr_flags ifr_ifru.ifru_flags /* flags */
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_STRUCT_IFREQ_H_ */

View file

@ -1,7 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_STRUCT_IN6_PKTINFO_H_
#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IN6_PKTINFO_H_
#include "libc/sock/struct/sockaddr6.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct in6_pktinfo {
@ -10,5 +9,4 @@ struct in6_pktinfo {
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_STRUCT_IN6_PKTINFO_H_ */

View file

@ -1,7 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_STRUCT_IN_PKTINFO_H_
#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IN_PKTINFO_H_
#include "libc/sock/struct/sockaddr.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct in_pktinfo {
@ -11,5 +10,4 @@ struct in_pktinfo {
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_STRUCT_IN_PKTINFO_H_ */

View file

@ -1,7 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_STRUCT_IP_MREQ_H_
#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IP_MREQ_H_
#include "libc/sock/struct/sockaddr.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct ip_mreq {
@ -10,5 +9,4 @@ struct ip_mreq {
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_STRUCT_IP_MREQ_H_ */

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_STRUCT_LINGER_H_
#define COSMOPOLITAN_LIBC_SOCK_STRUCT_LINGER_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct linger { /* Linux+XNU+BSD ABI */
@ -9,5 +8,4 @@ struct linger { /* Linux+XNU+BSD ABI */
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_STRUCT_LINGER_H_ */

View file

@ -1,7 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_STRUCT_MSGHDR_H_
#define COSMOPOLITAN_LIBC_SOCK_STRUCT_MSGHDR_H_
#include "libc/calls/struct/iovec.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct msghdr { /* Linux+NT ABI */
@ -18,5 +17,4 @@ ssize_t recvmsg(int, struct msghdr *, int);
ssize_t sendmsg(int, const struct msghdr *, int);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_STRUCT_MSGHDR_H_ */

View file

@ -1,7 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_STRUCT_MSGHDR_INTERNAL_H_
#define COSMOPOLITAN_LIBC_SOCK_STRUCT_MSGHDR_INTERNAL_H_
#include "libc/sock/struct/msghdr.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct msghdr_bsd {
@ -19,5 +18,4 @@ ssize_t sys_recvmsg(int, struct msghdr *, int);
bool __asan_is_valid_msghdr(const struct msghdr *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_STRUCT_MSGHDR_INTERNAL_H_ */

View file

@ -2,7 +2,6 @@
#define COSMOPOLITAN_LIBC_SOCK_STRUCT_POLLFD_H_
#include "libc/calls/struct/sigset.h"
#include "libc/calls/struct/timespec.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct pollfd {
@ -15,5 +14,4 @@ int poll(struct pollfd *, uint64_t, int32_t);
int ppoll(struct pollfd *, uint64_t, const struct timespec *, const sigset_t *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_STRUCT_POLLFD_H_ */

View file

@ -4,7 +4,6 @@
#include "libc/calls/struct/timespec.h"
#include "libc/mem/alloca.h"
#include "libc/sock/struct/pollfd.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int32_t sys_poll(struct pollfd *, uint64_t, signed);
@ -18,5 +17,4 @@ const char *DescribePollFds(char[300], ssize_t, struct pollfd *, size_t);
#define DescribePollFds(x, y, z) DescribePollFds(alloca(300), x, y, z)
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_STRUCT_POLLFD_INTERNAL_H_ */

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_STRUCT_SOCKADDR_H_
#define COSMOPOLITAN_LIBC_SOCK_STRUCT_SOCKADDR_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct sockaddr { /* Linux+NT ABI */
@ -46,5 +45,4 @@ ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *,
uint32_t);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_STRUCT_SOCKADDR_H_ */

View file

@ -3,7 +3,6 @@
#include "libc/mem/alloca.h"
#include "libc/sock/struct/sockaddr.h"
#include "libc/sock/struct/sockaddr6-bsd.internal.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct sockaddr_bsd {
@ -55,5 +54,4 @@ void sockaddr2linux(const union sockaddr_storage_bsd *, uint32_t,
union sockaddr_storage_linux *, uint32_t *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_STRUCT_SOCKADDR_INTERNAL_H_ */

View file

@ -1,7 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_STRUCT_SOCKADDR6_BSD_INTERNAL_H_
#define COSMOPOLITAN_LIBC_SOCK_STRUCT_SOCKADDR6_BSD_INTERNAL_H_
#include "libc/sock/struct/sockaddr6.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct sockaddr_in6_bsd {
@ -14,5 +13,4 @@ struct sockaddr_in6_bsd {
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_STRUCT_SOCKADDR6_BSD_INTERNAL_H_ */

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SOCKADDR6_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SOCKADDR6_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
struct in6_addr {
union {
@ -18,5 +17,4 @@ struct sockaddr_in6 { /* Linux+NT ABI */
uint32_t sin6_scope_id; /* rfc2553 */
};
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SOCKADDR6_H_ */

View file

@ -4,7 +4,6 @@
#include "libc/calls/struct/iovec.h"
#include "libc/nt/struct/overlapped.h"
#include "libc/sock/struct/sockaddr.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
void sys_connect_nt_cleanup(struct Fd *, bool);
@ -23,5 +22,4 @@ ssize_t sys_recvfrom_nt(int, const struct iovec *, size_t, uint32_t, void *,
uint32_t *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_SYSCALL_INTERNAL_H_ */

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_SYSLOG_H_
#define COSMOPOLITAN_LIBC_SOCK_SYSLOG_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int setlogmask(int);
@ -10,5 +9,4 @@ void closelog(void);
void vsyslog(int, const char *, va_list);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_SYSLOG_H_ */

View file

@ -1,11 +1,9 @@
#ifndef COSMOPOLITAN_LIBC_SOCK_WSAID_INTERNAL_H_
#define COSMOPOLITAN_LIBC_SOCK_WSAID_INTERNAL_H_
#include "libc/nt/struct/guid.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
void *__get_wsaid(const struct NtGuid *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SOCK_WSAID_INTERNAL_H_ */