Make Cosmopolitan ANSI C89 compatible

You can now use cosmopolitan.h with an ANSI C89 compiler like MSVC. The
Cosmopolitan codebase itself won't support being compiled that way. But
you can build objects that link against Cosmopolitan using any compiler
and you can furthermore use tools like IntelliSense that can't even GNU

See also #40
This commit is contained in:
Justine Tunney 2021-02-03 17:48:59 -08:00
parent 46085797b6
commit a8d7195777
34 changed files with 262 additions and 9561 deletions

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_BITS_SAFEMACROS_H_
#define COSMOPOLITAN_LIBC_BITS_SAFEMACROS_H_
#ifndef __STRICT_ANSI__
#include "libc/macros.h"
#include "libc/runtime/runtime.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
@ -83,5 +82,4 @@ uint64_t(unsignedsubtract)(uint64_t, uint64_t) pureconst;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* !ANSI */
#endif /* COSMOPOLITAN_LIBC_BITS_SAFEMACROS_H_ */

View file

@ -6,137 +6,137 @@
* @see libc/sysv/consts.sh for numbers
*/
#define EPERM EPERM // operation not permitted
#define ENOENT ENOENT // no such file or directory
#define ESRCH ESRCH // no such process
#define EINTR EINTR // interrupted system call
#define EIO EIO // input/output error
#define ENXIO ENXIO // no such device or address
#define E2BIG E2BIG // argument list too long
#define ENOEXEC ENOEXEC // exec format error
#define EBADF EBADF // bad file descriptor
#define ECHILD ECHILD // no child processes
#define EAGAIN EAGAIN // resource temporarily unavailable
#define ENOMEM ENOMEM // not enough space
#define EACCES EACCES // permission denied
#define EFAULT EFAULT // bad address
#define ENOTBLK ENOTBLK // block device required
#define EBUSY EBUSY // device or resource busy
#define EEXIST EEXIST // file exists
#define EXDEV EXDEV // improper link
#define ENODEV ENODEV // no such device
#define ENOTDIR ENOTDIR // not a directory
#define EISDIR EISDIR // is a directory
#define EINVAL EINVAL // invalid argument
#define ENFILE ENFILE // too many open files in system
#define EMFILE EMFILE // too many open files
#define ENOTTY ENOTTY // inappropriate I/O control op
#define ETXTBSY ETXTBSY // text file busy
#define EFBIG EFBIG // file too large
#define ENOSPC ENOSPC // no space left on device
#define ESPIPE ESPIPE // invalid seek
#define EROFS EROFS // read-only filesystem
#define EMLINK EMLINK // too many links
#define EPIPE EPIPE // broken pipe
#define EDOM EDOM // argument out of function domain
#define ERANGE ERANGE // result too large
#define EDEADLK EDEADLK // resource deadlock avoided
#define ENAMETOOLONG ENAMETOOLONG // filename too long
#define ENOLCK ENOLCK // no locks available
#define ENOSYS ENOSYS // system call not implemented
#define ENOTEMPTY ENOTEMPTY // directory not empty
#define ELOOP ELOOP // too many levels of symbolic links
#define ENOMSG ENOMSG // no message of the desired type
#define EIDRM EIDRM // identifier removed
#define ECHRNG ECHRNG // channel number out of range
#define EL2NSYNC EL2NSYNC // level 2 not synchronized
#define EL3HLT EL3HLT // level 3 halted
#define EL3RST EL3RST // level 3 halted
#define ELNRNG ELNRNG // link number out of range
#define EUNATCH EUNATCH // protocol driver not attached
#define ENOCSI ENOCSI // no csi structure available
#define EL2HLT EL2HLT // level 2 halted
#define EBADE EBADE // invalid exchange
#define EBADR EBADR // invalid request descriptor
#define EXFULL EXFULL // exchange full
#define ENOANO ENOANO // no anode
#define EBADRQC EBADRQC // invalid request code
#define EBADSLT EBADSLT // invalid slot
#define ENOSTR ENOSTR // no string
#define ENODATA ENODATA // no data
#define ETIME ETIME // timer expired
#define ENOSR ENOSR // out of streams resources
#define ENONET ENONET // no network
#define ENOPKG ENOPKG // package not installed
#define EREMOTE EREMOTE // object is remote
#define ENOLINK ENOLINK // link severed
#define EADV EADV // todo
#define ESRMNT ESRMNT // todo
#define ECOMM ECOMM // communication error on send
#define EPROTO EPROTO // protocol error
#define EMULTIHOP EMULTIHOP // multihop attempted
#define EDOTDOT EDOTDOT // todo
#define EBADMSG EBADMSG // bad message
#define EOVERFLOW EOVERFLOW // value too large for type
#define ENOTUNIQ ENOTUNIQ // name not unique on network
#define EBADFD EBADFD // fd in bad *state* (cf. EBADF)
#define EREMCHG EREMCHG // remote address changed
#define ELIBACC ELIBACC // cannot access dso
#define ELIBBAD ELIBBAD // corrupted shared library
#define ELIBSCN ELIBSCN // a.out section corrupted
#define ELIBMAX ELIBMAX // too many shared libraries
#define ELIBEXEC ELIBEXEC // cannot exec a dso directly
#define EILSEQ EILSEQ // invalid wide character
#define ERESTART ERESTART // please restart syscall
#define ESTRPIPE ESTRPIPE // streams pipe error
#define EUSERS EUSERS // too many users
#define ENOTSOCK ENOTSOCK // not a socket
#define EDESTADDRREQ EDESTADDRREQ // dest address needed
#define EMSGSIZE EMSGSIZE // message too long
#define EPROTOTYPE EPROTOTYPE // protocol wrong for socket
#define ENOPROTOOPT ENOPROTOOPT // protocol not available
#define EPROTONOSUPPORT EPROTONOSUPPORT // protocol not supported
#define ESOCKTNOSUPPORT ESOCKTNOSUPPORT // socket type not supported
#define EOPNOTSUPP EOPNOTSUPP // operation not supported on socket
#define EPFNOSUPPORT EPFNOSUPPORT // protocol family not supported
#define EAFNOSUPPORT EAFNOSUPPORT // address family not supported
#define EADDRINUSE EADDRINUSE // address already in use
#define EADDRNOTAVAIL EADDRNOTAVAIL // address not available
#define ENETDOWN ENETDOWN // network is down
#define ENETUNREACH ENETUNREACH // network unreachable
#define ENETRESET ENETRESET // connection aborted by network
#define ECONNABORTED ECONNABORTED // connection aborted
#define ECONNRESET ECONNRESET // connection reset
#define ENOBUFS ENOBUFS // no buffer space available
#define EISCONN EISCONN // socket is connected
#define ENOTCONN ENOTCONN // the socket is not connected
#define ESHUTDOWN ESHUTDOWN // no send after endpoint shutdown
#define ETOOMANYREFS ETOOMANYREFS // too many refs
#define ETIMEDOUT ETIMEDOUT // connection timed out
#define ECONNREFUSED ECONNREFUSED // connection refused
#define EHOSTDOWN EHOSTDOWN // host is down
#define EHOSTUNREACH EHOSTUNREACH // host is unreachable
#define EALREADY EALREADY // connection already in progress
#define EINPROGRESS EINPROGRESS // operation in progress
#define ESTALE ESTALE // stale file handle
#define EUCLEAN EUCLEAN // structure needs cleaning
#define ENOTNAM ENOTNAM // todo
#define ENAVAIL ENAVAIL // todo
#define EISNAM EISNAM // is a named type file
#define EREMOTEIO EREMOTEIO // remote i/o error
#define EDQUOT EDQUOT // disk quota exceeded
#define ENOMEDIUM ENOMEDIUM // no medium found
#define EMEDIUMTYPE EMEDIUMTYPE // wrong medium type
#define ECANCELED ECANCELED // operation canceled
#define ENOKEY ENOKEY // required key not available
#define EKEYEXPIRED EKEYEXPIRED // key has expired
#define EKEYREVOKED EKEYREVOKED // key has been revoked
#define EKEYREJECTED EKEYREJECTED // key was rejected by service
#define EOWNERDEAD EOWNERDEAD // owner died
#define ENOTRECOVERABLE ENOTRECOVERABLE // state not recoverable
#define ERFKILL ERFKILL // can't op b/c RF-kill
#define EHWPOISON EHWPOISON // mempage has h/w error
#define EWOULDBLOCK EAGAIN // poll fd and try again
#define EPERM EPERM /* operation not permitted */
#define ENOENT ENOENT /* no such file or directory */
#define ESRCH ESRCH /* no such process */
#define EINTR EINTR /* interrupted system call */
#define EIO EIO /* input/output error */
#define ENXIO ENXIO /* no such device or address */
#define E2BIG E2BIG /* argument list too long */
#define ENOEXEC ENOEXEC /* exec format error */
#define EBADF EBADF /* bad file descriptor */
#define ECHILD ECHILD /* no child processes */
#define EAGAIN EAGAIN /* resource temporarily unavailable */
#define ENOMEM ENOMEM /* not enough space */
#define EACCES EACCES /* permission denied */
#define EFAULT EFAULT /* bad address */
#define ENOTBLK ENOTBLK /* block device required */
#define EBUSY EBUSY /* device or resource busy */
#define EEXIST EEXIST /* file exists */
#define EXDEV EXDEV /* improper link */
#define ENODEV ENODEV /* no such device */
#define ENOTDIR ENOTDIR /* not a directory */
#define EISDIR EISDIR /* is a directory */
#define EINVAL EINVAL /* invalid argument */
#define ENFILE ENFILE /* too many open files in system */
#define EMFILE EMFILE /* too many open files */
#define ENOTTY ENOTTY /* inappropriate I/O control op */
#define ETXTBSY ETXTBSY /* text file busy */
#define EFBIG EFBIG /* file too large */
#define ENOSPC ENOSPC /* no space left on device */
#define ESPIPE ESPIPE /* invalid seek */
#define EROFS EROFS /* read-only filesystem */
#define EMLINK EMLINK /* too many links */
#define EPIPE EPIPE /* broken pipe */
#define EDOM EDOM /* argument out of function domain */
#define ERANGE ERANGE /* result too large */
#define EDEADLK EDEADLK /* resource deadlock avoided */
#define ENAMETOOLONG ENAMETOOLONG /* filename too long */
#define ENOLCK ENOLCK /* no locks available */
#define ENOSYS ENOSYS /* system call not implemented */
#define ENOTEMPTY ENOTEMPTY /* directory not empty */
#define ELOOP ELOOP /* too many levels of symbolic links */
#define ENOMSG ENOMSG /* no message of the desired type */
#define EIDRM EIDRM /* identifier removed */
#define ECHRNG ECHRNG /* channel number out of range */
#define EL2NSYNC EL2NSYNC /* level 2 not synchronized */
#define EL3HLT EL3HLT /* level 3 halted */
#define EL3RST EL3RST /* level 3 halted */
#define ELNRNG ELNRNG /* link number out of range */
#define EUNATCH EUNATCH /* protocol driver not attached */
#define ENOCSI ENOCSI /* no csi structure available */
#define EL2HLT EL2HLT /* level 2 halted */
#define EBADE EBADE /* invalid exchange */
#define EBADR EBADR /* invalid request descriptor */
#define EXFULL EXFULL /* exchange full */
#define ENOANO ENOANO /* no anode */
#define EBADRQC EBADRQC /* invalid request code */
#define EBADSLT EBADSLT /* invalid slot */
#define ENOSTR ENOSTR /* no string */
#define ENODATA ENODATA /* no data */
#define ETIME ETIME /* timer expired */
#define ENOSR ENOSR /* out of streams resources */
#define ENONET ENONET /* no network */
#define ENOPKG ENOPKG /* package not installed */
#define EREMOTE EREMOTE /* object is remote */
#define ENOLINK ENOLINK /* link severed */
#define EADV EADV /* todo */
#define ESRMNT ESRMNT /* todo */
#define ECOMM ECOMM /* communication error on send */
#define EPROTO EPROTO /* protocol error */
#define EMULTIHOP EMULTIHOP /* multihop attempted */
#define EDOTDOT EDOTDOT /* todo */
#define EBADMSG EBADMSG /* bad message */
#define EOVERFLOW EOVERFLOW /* value too large for type */
#define ENOTUNIQ ENOTUNIQ /* name not unique on network */
#define EBADFD EBADFD /* fd in bad *state* (cf. EBADF) */
#define EREMCHG EREMCHG /* remote address changed */
#define ELIBACC ELIBACC /* cannot access dso */
#define ELIBBAD ELIBBAD /* corrupted shared library */
#define ELIBSCN ELIBSCN /* a.out section corrupted */
#define ELIBMAX ELIBMAX /* too many shared libraries */
#define ELIBEXEC ELIBEXEC /* cannot exec a dso directly */
#define EILSEQ EILSEQ /* invalid wide character */
#define ERESTART ERESTART /* please restart syscall */
#define ESTRPIPE ESTRPIPE /* streams pipe error */
#define EUSERS EUSERS /* too many users */
#define ENOTSOCK ENOTSOCK /* not a socket */
#define EDESTADDRREQ EDESTADDRREQ /* dest address needed */
#define EMSGSIZE EMSGSIZE /* message too long */
#define EPROTOTYPE EPROTOTYPE /* protocol wrong for socket */
#define ENOPROTOOPT ENOPROTOOPT /* protocol not available */
#define EPROTONOSUPPORT EPROTONOSUPPORT /* protocol not supported */
#define ESOCKTNOSUPPORT ESOCKTNOSUPPORT /* socket type not supported */
#define EOPNOTSUPP EOPNOTSUPP /* operation not supported on socket */
#define EPFNOSUPPORT EPFNOSUPPORT /* protocol family not supported */
#define EAFNOSUPPORT EAFNOSUPPORT /* address family not supported */
#define EADDRINUSE EADDRINUSE /* address already in use */
#define EADDRNOTAVAIL EADDRNOTAVAIL /* address not available */
#define ENETDOWN ENETDOWN /* network is down */
#define ENETUNREACH ENETUNREACH /* network unreachable */
#define ENETRESET ENETRESET /* connection aborted by network */
#define ECONNABORTED ECONNABORTED /* connection aborted */
#define ECONNRESET ECONNRESET /* connection reset */
#define ENOBUFS ENOBUFS /* no buffer space available */
#define EISCONN EISCONN /* socket is connected */
#define ENOTCONN ENOTCONN /* the socket is not connected */
#define ESHUTDOWN ESHUTDOWN /* no send after endpoint shutdown */
#define ETOOMANYREFS ETOOMANYREFS /* too many refs */
#define ETIMEDOUT ETIMEDOUT /* connection timed out */
#define ECONNREFUSED ECONNREFUSED /* connection refused */
#define EHOSTDOWN EHOSTDOWN /* host is down */
#define EHOSTUNREACH EHOSTUNREACH /* host is unreachable */
#define EALREADY EALREADY /* connection already in progress */
#define EINPROGRESS EINPROGRESS /* operation in progress */
#define ESTALE ESTALE /* stale file handle */
#define EUCLEAN EUCLEAN /* structure needs cleaning */
#define ENOTNAM ENOTNAM /* todo */
#define ENAVAIL ENAVAIL /* todo */
#define EISNAM EISNAM /* is a named type file */
#define EREMOTEIO EREMOTEIO /* remote i/o error */
#define EDQUOT EDQUOT /* disk quota exceeded */
#define ENOMEDIUM ENOMEDIUM /* no medium found */
#define EMEDIUMTYPE EMEDIUMTYPE /* wrong medium type */
#define ECANCELED ECANCELED /* operation canceled */
#define ENOKEY ENOKEY /* required key not available */
#define EKEYEXPIRED EKEYEXPIRED /* key has expired */
#define EKEYREVOKED EKEYREVOKED /* key has been revoked */
#define EKEYREJECTED EKEYREJECTED /* key was rejected by service */
#define EOWNERDEAD EOWNERDEAD /* owner died */
#define ENOTRECOVERABLE ENOTRECOVERABLE /* state not recoverable */
#define ERFKILL ERFKILL /* can't op b/c RF-kill */
#define EHWPOISON EHWPOISON /* mempage has h/w error */
#define EWOULDBLOCK EAGAIN /* poll fd and try again */
#define ENOTSUP ENOTSUP
#if !(__ASSEMBLER__ + __LINKER__ + 0)

View file

@ -26,7 +26,6 @@ int sscanf(const char *, const char *, ...) scanfesque(2);
int vsscanf(const char *, const char *, va_list);
int vcscanf(int (*)(void *), int (*)(int, void *), void *, const char *,
va_list);
char *strerror(int) returnsnonnull nothrow nocallback;
int strerror_r(int, char *, size_t) nothrow nocallback;
int palandprintf(void *, void *, const char *, va_list) hidden;
char *itoa(int, char *, int) compatfn;

View file

@ -3,8 +3,10 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#ifndef __STRICT_ANSI__
int sleb128(const void *, size_t, int128_t);
int unsleb128(const void *, size_t, int128_t *);
#endif /* ANSI */
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -61,23 +61,44 @@
*/
#pragma GCC diagnostic ignored "-Wformat-security"
#endif /* __GNUC__ + 0 < 6 */
#else
#define PFLINK(FMT) FMT
#define SFLINK(FMT) FMT
asm(".section .yoink\n\t"
"nop\tntoa(%rip)\n\t"
"nop\tftoa(%rip)\n\t"
"nop\tkCp437(%rip)\n\t"
"nop\tstrerror(%rip)\n\t"
"nop\tstrnwidth(%rip)\n\t"
"nop\tstrnwidth16(%rip)\n\t"
"nop\twcsnwidth(%rip)\n\t"
"nop\tmalloc(%rip)\n\t"
"nop\tcalloc(%rip)\n\t"
"nop\tfree_s(%rip)\n\t"
"nop\t__grow(%rip)\n\t"
".previous");
#ifdef __GNUC__
__asm__(".section .yoink\n\t"
"nop\tntoa(%rip)\n\t"
"nop\tftoa(%rip)\n\t"
"nop\tkCp437(%rip)\n\t"
"nop\tstrerror(%rip)\n\t"
"nop\tstrnwidth(%rip)\n\t"
"nop\tstrnwidth16(%rip)\n\t"
"nop\twcsnwidth(%rip)\n\t"
"nop\tmalloc(%rip)\n\t"
"nop\tcalloc(%rip)\n\t"
"nop\tfree_s(%rip)\n\t"
"nop\t__grow(%rip)\n\t"
".previous");
#else
#include "libc/fmt/palandprintf.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/unicode/unicode.h"
static long __pflink(long x) {
x |= kCp437[0];
x |= ntoa(0, 0, 0, 0, 0, 0, 0, 0, 0);
x |= ftoa(0, 0, 0, 0, 0, 0);
x |= strnwidth(0, 0);
x |= strnwidth16(0, 0);
x |= wcsnwidth(0, 0);
x |= malloc(0);
x |= __grow(0, 0, 0, 0);
x |= (intptr_t)strerror(0);
x |= (intptr_t)calloc(0, 0);
free_s(0);
return x;
}
#endif
#endif /* __STRICT_ANSI__ */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_FMT_PFLINK_H_ */

View file

@ -601,7 +601,13 @@ typedef uint64_t uintmax_t;
#endif
#ifndef unreachable
#if defined(__GNUC__) && !defined(__STRICT_ANSI)
#define unreachable __builtin_unreachable()
#else
#define unreachable \
do { \
} while (1)
#endif
#endif
#define donothing \
@ -754,13 +760,13 @@ typedef uint64_t uintmax_t;
#endif /* ANSI */
#endif /* -w */
#ifdef __STRICT_ANSI__
#ifndef __STRICT_ANSI__
#define DebugBreak() asm("int3")
#else
#define DebugBreak() (void)0
#endif
#ifdef __STRICT_ANSI__
#ifndef __STRICT_ANSI__
#define VEIL(CONSTRAINT, EXPRESSION) \
({ \
autotype(EXPRESSION) VeiledValue = (EXPRESSION); \
@ -771,7 +777,7 @@ typedef uint64_t uintmax_t;
#define VEIL(CONSTRAINT, EXPRESSION) (EXPRESSION)
#endif
#ifdef __STRICT_ANSI__
#ifndef __STRICT_ANSI__
#define CONCEAL(CONSTRAINT, EXPRESSION) \
({ \
autotype(EXPRESSION) VeiledValue = (EXPRESSION); \
@ -782,7 +788,7 @@ typedef uint64_t uintmax_t;
#define CONCEAL(CONSTRAINT, EXPRESSION) (EXPRESSION)
#endif
#ifdef __STRICT_ANSI__
#ifndef __STRICT_ANSI__
#define EXPROPRIATE(EXPRESSION) \
({ \
asm volatile("" ::"g"(EXPRESSION) : "memory"); \
@ -792,7 +798,7 @@ typedef uint64_t uintmax_t;
#define EXPROPRIATE(EXPRESSION) (EXPRESSION)
#endif
#ifdef __STRICT_ANSI__
#ifndef __STRICT_ANSI__
#define YOINK(SYMBOL) \
do { \
_Static_assert(!__builtin_types_compatible_p(typeof(SYMBOL), char[]), \
@ -807,7 +813,7 @@ typedef uint64_t uintmax_t;
#define YOINK(SYMBOL) (void)0
#endif
#ifdef __STRICT_ANSI__
#ifndef __STRICT_ANSI__
#define STATIC_YOINK(SYMBOLSTR) \
asm(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous")
#else

View file

@ -20,6 +20,7 @@
#include "libc/fmt/fmt.h"
#include "libc/log/log.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
void __logerrno(const char *file, int line, const char *form) {
flogf(kLogWarn, file, line, NULL, PFLINK("%s → %s"), form, strerror(errno));

View file

@ -22,6 +22,7 @@
#include "libc/log/log.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
/**
* Writes error messages to standard error.

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/mem.h"
#include "libc/mem/fmt.h"
/**
* Formats string, allocating needed memory.

18
libc/mem/fmt.h Normal file
View file

@ -0,0 +1,18 @@
#ifndef COSMOPOLITAN_LIBC_MEM_FMT_H_
#define COSMOPOLITAN_LIBC_MEM_FMT_H_
#include "libc/fmt/pflink.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int asprintf(char **, const char *, ...) printfesque(2)
paramsnonnull((1, 2)) libcesque;
int vasprintf(char **, const char *, va_list) paramsnonnull() libcesque;
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define asprintf(SP, FMT, ...) (asprintf)(SP, PFLINK(FMT), ##__VA_ARGS__)
#define vasprintf(SP, FMT, VA) (vasprintf)(SP, PFLINK(FMT), VA)
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_MEM_FMT_H_ */

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_MEM_MEM_H_
#define COSMOPOLITAN_LIBC_MEM_MEM_H_
#include "libc/fmt/pflink.h"
#define M_TRIM_THRESHOLD (-1)
#define M_GRANULARITY (-2)
@ -34,10 +33,6 @@ size_t malloc_usable_size(const void *);
void **independent_calloc(size_t, size_t, void **);
void **independent_comalloc(size_t, size_t *, void **);
int asprintf(char **, const char *, ...) printfesque(2)
paramsnonnull((1, 2)) libcesque;
int vasprintf(char **, const char *, va_list) paramsnonnull() libcesque;
wchar_t *wcsdup(const wchar_t *) strlenesque nodiscard;
struct mallinfo {
@ -63,15 +58,6 @@ size_t malloc_set_footprint_limit(size_t);
void malloc_inspect_all(void (*handler)(void *, void *, size_t, void *),
void *);
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § dynamic memory » optimizations
*/
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define asprintf(SP, FMT, ...) (asprintf)(SP, PFLINK(FMT), ##__VA_ARGS__)
#define vasprintf(SP, FMT, VA) (vasprintf)(SP, PFLINK(FMT), VA)
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_MEM_MEM_H_ */

View file

@ -59,8 +59,8 @@ uint32_t SleepEx(uint32_t dwMilliseconds, bool32 bAlertable);
void GetSystemTime(struct NtSystemTime *lpSystemTime);
bool32 SystemTimeToFileTime(const struct NtSystemTime *lpSystemTime,
struct NtFileTime *lpFileTime);
void GetSystemTimeAsFileTime(struct NtFileTime *); // win8+
void GetSystemTimePreciseAsFileTime(struct NtFileTime *); // win8+
void GetSystemTimeAsFileTime(struct NtFileTime *); /* win8+ */
void GetSystemTimePreciseAsFileTime(struct NtFileTime *); /* win8+ */
uint32_t WaitForSingleObject(int64_t hHandle, uint32_t dwMilliseconds);
uint32_t WaitForMultipleObjects(uint32_t nCount, const int64_t *lpHandles,

View file

@ -25,6 +25,7 @@ LIBC_RAND_A_CHECKS = \
LIBC_RAND_A_DIRECTDEPS = \
LIBC_CALLS \
LIBC_INTRIN \
LIBC_NEXGEN32E \
LIBC_NT_KERNEL32 \
LIBC_STR \

View file

@ -7,8 +7,8 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define _kAutomapStart 0x0000100080000000 // asan can't spread its poison here
#define _kAutomapSize 0x00000fff80000000
#define _kAutomapStart 0x0000100080000000 /* asan can't spread its poison */
#define _kAutomapSize 0x00000fff80000000 /* beyond the above mem address */
#define _kFixedmapStart 0x0000200000000000
/*

View file

@ -10,19 +10,19 @@ COSMOPOLITAN_C_START_
*/
typedef struct FILE {
uint8_t bufmode; // 0x00 _IOFBF, etc. (ignored if fd=-1)
bool noclose; // 0x01 for fake dup()
uint32_t iomode; // 0x04 O_RDONLY, etc. (ignored if fd=-1)
int32_t state; // 0x08 0=OK, -1=EOF, >0=errno
int fd; // 0x0c ≥0=fd, -1=closed|buffer
uint32_t beg; // 0x10
uint32_t end; // 0x14
uint8_t *buf; // 0x18
uint32_t size; // 0x20
uint32_t nofree; // 0x24
int (*reader)(struct FILE *); // 0x28
int (*writer)(struct FILE *); // 0x30
int pid; // 0x34
uint8_t bufmode; /* 0x00 _IOFBF, etc. (ignored if fd=-1) */
bool noclose; /* 0x01 for fake dup() */
uint32_t iomode; /* 0x04 O_RDONLY, etc. (ignored if fd=-1) */
int32_t state; /* 0x08 0=OK, -1=EOF, >0=errno */
int fd; /* 0x0c ≥0=fd, -1=closed|buffer */
uint32_t beg; /* 0x10 */
uint32_t end; /* 0x14 */
uint8_t *buf; /* 0x18 */
uint32_t size; /* 0x20 */
uint32_t nofree; /* 0x24 */
int (*reader)(struct FILE *); /* 0x28 */
int (*writer)(struct FILE *); /* 0x30 */
int pid; /* 0x34 */
} FILE;
extern FILE *stdin;

View file

@ -181,6 +181,7 @@ compatfn wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t) memcpyesque;
int timingsafe_memcmp(const void *, const void *, size_t);
void *memmem(const void *, size_t, const void *, size_t)
paramsnonnull() nothrow nocallback nosideeffect;
char *strerror(int) returnsnonnull nothrow nocallback;
char *tinystrstr(const char *, const char *) strlenesque;
char16_t *tinystrstr16(const char16_t *, const char16_t *) strlenesque;

View file

@ -26,6 +26,7 @@
#include "libc/nt/runtime.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
testonly void testlib_showerror(const char *file, int line, const char *func,

View file

@ -20,6 +20,7 @@
#include "libc/calls/struct/timeval.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/mem/fmt.h"
#include "libc/mem/mem.h"
#include "libc/sysv/consts/clock.h"
#include "libc/time/struct/tm.h"

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/log/log.h"
#include "libc/mem/fmt.h"
#include "libc/mem/mem.h"
#include "libc/x/x.h"