Skip to content

Commit

Permalink
Add comments explaining changes to upstream source files.
Browse files Browse the repository at this point in the history
Add at least a one-line comment on every
`#ifdef __wasilibc_unmodified_upstream` briefly indicating what its
purpose is.

While here, reenable some of the code that was previously disabled when
getenv wasn't supported, as getenv is now supported.
  • Loading branch information
sunfishcode committed Apr 5, 2019
1 parent 685d014 commit e5f14be
Show file tree
Hide file tree
Showing 57 changed files with 163 additions and 177 deletions.
4 changes: 2 additions & 2 deletions libc-top-half/musl/include/alltypes.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ TYPEDEF unsigned long wctype_t;
TYPEDEF void * timer_t;
TYPEDEF int clockid_t;
TYPEDEF long clock_t;
#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
STRUCT timeval { time_t tv_sec; suseconds_t tv_usec; };
STRUCT timespec { time_t tv_sec; long tv_nsec; };
#else
Expand Down Expand Up @@ -70,7 +70,7 @@ TYPEDEF struct __locale_struct * locale_t;

TYPEDEF struct __sigset_t { unsigned long __bits[128/sizeof(long)]; } sigset_t;

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
STRUCT iovec { void *iov_base; size_t iov_len; };
#else
#include <__struct_iovec.h>
Expand Down
4 changes: 2 additions & 2 deletions libc-top-half/musl/include/arpa/inet.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ uint16_t htons(uint16_t);
uint32_t ntohl(uint32_t);
uint16_t ntohs(uint16_t);

#ifdef __wasilibc_unmodified_upstream /* inet_addr */
#ifdef __wasilibc_unmodified_upstream /* WASI has no inet_addr */
in_addr_t inet_addr (const char *);
in_addr_t inet_network (const char *);
char *inet_ntoa (struct in_addr);
Expand All @@ -22,7 +22,7 @@ int inet_pton (int, const char *__restrict, void *__restrict);
const char *inet_ntop (int, const void *__restrict, char *__restrict, socklen_t);

int inet_aton (const char *, struct in_addr *);
#ifdef __wasilibc_unmodified_upstream /* inet_makeaddr */
#ifdef __wasilibc_unmodified_upstream /* WASI has no inet_makeaddr */
struct in_addr inet_makeaddr(in_addr_t, in_addr_t);
in_addr_t inet_lnaof(struct in_addr);
in_addr_t inet_netof(struct in_addr);
Expand Down
8 changes: 4 additions & 4 deletions libc-top-half/musl/include/dirent.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _DIRENT_H
#define _DIRENT_H

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
#else
#include <__header_dirent.h>
#endif
Expand All @@ -19,7 +19,7 @@ extern "C" {

#include <bits/alltypes.h>

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
typedef struct __dirstream DIR;
#else
#include <__typedef_DIR.h>
Expand All @@ -29,7 +29,7 @@ typedef struct __dirstream DIR;
#define _DIRENT_HAVE_D_OFF
#define _DIRENT_HAVE_D_TYPE

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
struct dirent {
ino_t d_ino;
off_t d_off;
Expand Down Expand Up @@ -62,7 +62,7 @@ long telldir(DIR *);
#endif

#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
#define DT_UNKNOWN 0
#define DT_FIFO 1
#define DT_CHR 2
Expand Down
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/errno.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern "C" {

#include <features.h>

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
#include <bits/errno.h>

#ifdef __GNUC__
Expand Down
4 changes: 2 additions & 2 deletions libc-top-half/musl/include/fcntl.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _FCNTL_H
#define _FCNTL_H

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
#else
#include <__header_fcntl.h>
#endif
Expand Down Expand Up @@ -40,7 +40,7 @@ int openat(int, const char *, int, ...);
int posix_fadvise(int, off_t, off_t, int);
int posix_fallocate(int, off_t, off_t);

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
#define O_SEARCH O_PATH
#define O_EXEC O_PATH

Expand Down
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/float.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
extern "C" {
#endif

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of FLT_ROUNDS */
int __flt_rounds(void);
#define FLT_ROUNDS (__flt_rounds())
#else
Expand Down
4 changes: 2 additions & 2 deletions libc-top-half/musl/include/ftw.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ struct FTW {
int level;
};

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */
int ftw(const char *, int (*)(const char *, const struct stat *, int), int);
#endif
int nftw(const char *, int (*)(const char *, const struct stat *, int, struct FTW *), int, int);

#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */
#define ftw64 ftw
#endif
#define nftw64 nftw
Expand Down
4 changes: 2 additions & 2 deletions libc-top-half/musl/include/limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#define SEM_VALUE_MAX 0x7fffffff
#define SEM_NSEMS_MAX 256
#define DELAYTIMER_MAX 0x7fffffff
#ifdef __wasilibc_unmodified_upstream /* mq */
#ifdef __wasilibc_unmodified_upstream /* WASI has no mq */
#define MQ_PRIO_MAX 32768
#endif
#define LOGIN_NAME_MAX 256
Expand Down Expand Up @@ -116,7 +116,7 @@
#define _POSIX_LOGIN_NAME_MAX 9
#define _POSIX_MAX_CANON 255
#define _POSIX_MAX_INPUT 255
#ifdef __wasilibc_unmodified_upstream /* mq */
#ifdef __wasilibc_unmodified_upstream /* WASI has no mq */
#define _POSIX_MQ_OPEN_MAX 8
#define _POSIX_MQ_PRIO_MAX 32
#endif
Expand Down
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/locale.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern "C" {

#include <features.h>

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */
#ifdef __cplusplus
#define NULL 0L
#else
Expand Down
12 changes: 6 additions & 6 deletions libc-top-half/musl/include/netinet/in.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ extern "C" {
#include <features.h>
#include <inttypes.h>
#include <sys/socket.h>
#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
#else
#include <__header_netinet_in.h>
#endif

typedef uint16_t in_port_t;
typedef uint32_t in_addr_t;
#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
struct in_addr { in_addr_t s_addr; };
#endif

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
struct sockaddr_in {
sa_family_t sin_family;
in_port_t sin_port;
Expand All @@ -28,7 +28,7 @@ struct sockaddr_in {
};
#endif

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
struct in6_addr {
union {
uint8_t __s6_addr[16];
Expand All @@ -41,7 +41,7 @@ struct in6_addr {
#define s6_addr32 __in6_union.__s6_addr32
#endif

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
struct sockaddr_in6 {
sa_family_t sin6_family;
in_port_t sin6_port;
Expand Down Expand Up @@ -83,7 +83,7 @@ uint16_t ntohs(uint16_t);

#define IPPORT_RESERVED 1024

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
#define IPPROTO_IP 0
#define IPPROTO_HOPOPTS 0
#define IPPROTO_ICMP 1
Expand Down
6 changes: 3 additions & 3 deletions libc-top-half/musl/include/poll.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern "C" {

#include <bits/poll.h>

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
#define POLLIN 0x001
#define POLLPRI 0x002
#define POLLOUT 0x004
Expand All @@ -30,13 +30,13 @@ extern "C" {
#include <__header_poll.h>
#endif

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
typedef unsigned long nfds_t;
#else
#include <__typedef_nfds_t.h>
#endif

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
struct pollfd {
int fd;
short events;
Expand Down
3 changes: 1 addition & 2 deletions libc-top-half/musl/include/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ extern "C" {
#define PTHREAD_PROCESS_SHARED 1


#ifdef __wasilibc_unmodified_upstream
#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
#define PTHREAD_MUTEX_INITIALIZER {{{0}}}
#define PTHREAD_RWLOCK_INITIALIZER {{{0}}}
#define PTHREAD_COND_INITIALIZER {{{0}}}
#else
/* TODO: Threads support. */
#define PTHREAD_MUTEX_INITIALIZER 0
#define PTHREAD_RWLOCK_INITIALIZER 0
#define PTHREAD_COND_INITIALIZER 0
Expand Down
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/setjmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern "C" {

#include <features.h>

#ifdef __wasilibc_unmodified_upstream /* setjmp */
#ifdef __wasilibc_unmodified_upstream /* WASI has no setjmp */
#include <bits/setjmp.h>

typedef struct __jmp_buf_tag {
Expand Down
12 changes: 6 additions & 6 deletions libc-top-half/musl/include/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ struct sigevent {
#define SIGEV_NONE 1
#define SIGEV_THREAD 2

#ifdef __wasilibc_unmodified_upstream /* realtime signals */
#ifdef __wasilibc_unmodified_upstream /* WASI has no realtime signals */
int __libc_current_sigrtmin(void);
int __libc_current_sigrtmax(void);

#define SIGRTMIN (__libc_current_sigrtmin())
#define SIGRTMAX (__libc_current_sigrtmax())
#endif

#ifdef __wasilibc_unmodified_upstream /* signals */
#ifdef __wasilibc_unmodified_upstream /* WASI has no signals */
int kill(pid_t, int);

int sigemptyset(sigset_t *);
Expand All @@ -219,14 +219,14 @@ int sigqueue(pid_t, int, union sigval);
int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict);
int pthread_kill(pthread_t, int);

#ifdef __wasilibc_unmodified_upstream /* signals */
#ifdef __wasilibc_unmodified_upstream /* WASI has no signals */
void psiginfo(const siginfo_t *, const char *);
void psignal(int, const char *);
#endif

#endif

#ifdef __wasilibc_unmodified_upstream /* signals */
#ifdef __wasilibc_unmodified_upstream /* WASI has no signals */
#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
int killpg(pid_t, int);
int sigaltstack(const stack_t *__restrict, stack_t *__restrict);
Expand Down Expand Up @@ -254,7 +254,7 @@ void (*sigset(int, void (*)(int)))(int);
#endif
#endif

#ifdef __wasilibc_unmodified_upstream /* signals */
#ifdef __wasilibc_unmodified_upstream /* WASI has no signals */
#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
#define NSIG _NSIG
typedef void (*sig_t)(int);
Expand All @@ -278,7 +278,7 @@ int sigandset(sigset_t *, const sigset_t *, const sigset_t *);

typedef int sig_atomic_t;

#ifdef __wasilibc_unmodified_upstream /* signals */
#ifdef __wasilibc_unmodified_upstream /* WASI has no signals */
void (*signal(int, void (*)(int)))(int);
#endif
int raise(int);
Expand Down
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/stdarg.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _STDARG_H
#define _STDARG_H

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use the compiler's stdarg.h */
#ifdef __cplusplus
extern "C" {
#endif
Expand Down
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/stddef.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use the compiler's stddef.h */
#ifndef _STDDEF_H
#define _STDDEF_H

Expand Down
12 changes: 6 additions & 6 deletions libc-top-half/musl/include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern "C" {

#include <bits/alltypes.h>

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */
#ifdef __cplusplus
#define NULL 0L
#else
Expand All @@ -35,7 +35,7 @@ extern "C" {
#undef EOF
#define EOF (-1)

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
#undef SEEK_SET
#undef SEEK_CUR
#undef SEEK_END
Expand All @@ -53,7 +53,7 @@ extern "C" {
#define BUFSIZ 1024
#define FILENAME_MAX 4096
#define FOPEN_MAX 1000
#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* WASI has no tmpnam */
#define TMP_MAX 10000
#define L_tmpnam 20
#endif
Expand Down Expand Up @@ -105,7 +105,7 @@ int putchar(int);

char *fgets(char *__restrict, int, FILE *__restrict);
#if __STDC_VERSION__ < 201112L
#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* gets is obsolete */
char *gets(char *);
#else
char *gets(char *) __attribute__((__deprecated__("gets is not defined on WASI")));
Expand Down Expand Up @@ -137,7 +137,7 @@ void perror(const char *);
int setvbuf(FILE *__restrict, char *__restrict, int, size_t);
void setbuf(FILE *__restrict, char *__restrict);

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* WASI has no tmpnam or tmpfile */
char *tmpnam(char *);
FILE *tmpfile(void);
#else
Expand Down Expand Up @@ -173,7 +173,7 @@ char *ctermid(char *);
#endif


#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* WASI has no tempnam */
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
|| defined(_BSD_SOURCE)
#define P_tmpdir "/tmp"
Expand Down
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern "C" {

#include <features.h>

#ifdef __wasilibc_unmodified_upstream
#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */
#ifdef __cplusplus
#define NULL 0L
#else
Expand Down
Loading

0 comments on commit e5f14be

Please sign in to comment.