mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-30 08:18:30 +00:00
Replace COSMO define with _COSMO_SOURCE
This change might cause ABI breakages for /opt/cosmos. It's needed to help us better conform to header declaration practices.
This commit is contained in:
parent
a033b65a33
commit
c776a32f75
238 changed files with 858 additions and 1069 deletions
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio_ext.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio_ext.h"
|
||||
|
||||
void __fseterr(FILE *f) {
|
||||
|
|
|
@ -43,7 +43,7 @@ FILE *__stdio_alloc(void) {
|
|||
f = kmalloc(sizeof(FILE));
|
||||
}
|
||||
if (f) {
|
||||
((pthread_mutex_t *)f->lock)->_type = PTHREAD_MUTEX_RECURSIVE;
|
||||
f->lock._type = PTHREAD_MUTEX_RECURSIVE;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/struct/dirent.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
int alphasort(const struct dirent **a, const struct dirent **b) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_STDIO_APPEND_H_
|
||||
#define COSMOPOLITAN_LIBC_STDIO_APPEND_H_
|
||||
#ifdef COSMO
|
||||
#ifdef _COSMO_SOURCE
|
||||
|
||||
#define APPEND_COOKIE 21578
|
||||
|
||||
|
@ -34,5 +34,5 @@ ssize_t kvappendf(char **, const char *, va_list);
|
|||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMO */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
#endif /* COSMOPOLITAN_LIBC_STDIO_APPEND_H_ */
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio_ext.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,7 +43,7 @@ static void __stdio_fork_prepare(void) {
|
|||
__fflush_lock();
|
||||
for (int i = 0; i < __fflush.handles.i; ++i) {
|
||||
if ((f = __fflush.handles.p[i])) {
|
||||
pthread_mutex_lock((pthread_mutex_t *)f->lock);
|
||||
pthread_mutex_lock(&f->lock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ static void __stdio_fork_parent(void) {
|
|||
FILE *f;
|
||||
for (int i = __fflush.handles.i; i--;) {
|
||||
if ((f = __fflush.handles.p[i])) {
|
||||
pthread_mutex_unlock((pthread_mutex_t *)f->lock);
|
||||
pthread_mutex_unlock(&f->lock);
|
||||
}
|
||||
}
|
||||
__fflush_unlock();
|
||||
|
@ -60,12 +60,10 @@ static void __stdio_fork_parent(void) {
|
|||
|
||||
static void __stdio_fork_child(void) {
|
||||
FILE *f;
|
||||
pthread_mutex_t *m;
|
||||
for (int i = __fflush.handles.i; i--;) {
|
||||
if ((f = __fflush.handles.p[i])) {
|
||||
m = (pthread_mutex_t *)f->lock;
|
||||
bzero(m, sizeof(*m));
|
||||
m->_type = PTHREAD_MUTEX_RECURSIVE;
|
||||
bzero(&f->lock, sizeof(f->lock));
|
||||
f->lock._type = PTHREAD_MUTEX_RECURSIVE;
|
||||
}
|
||||
}
|
||||
pthread_mutex_init(&__fflush_lock_obj, 0);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/lock.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
|
@ -23,7 +24,7 @@
|
|||
* Retrieves line from stream, e.g.
|
||||
*
|
||||
* char *line;
|
||||
* while ((line = _chomp(fgetln(stdin, 0)))) {
|
||||
* while ((line = chomp(fgetln(stdin, 0)))) {
|
||||
* printf("%s\n", line);
|
||||
* }
|
||||
*
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
*
|
||||
* This function is similar to getline() except it'll truncate lines
|
||||
* exceeding size. The line ending marker is included and may be removed
|
||||
* using _chomp().
|
||||
* using chomp().
|
||||
*
|
||||
* When reading from the console on Windows in `ICANON` mode, the
|
||||
* returned line will end with `\r\n` rather than `\n`.
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
|
@ -27,7 +28,7 @@
|
|||
*
|
||||
* This function is similar to getline() except it'll truncate lines
|
||||
* exceeding size. The line ending marker is included and may be removed
|
||||
* using _chomp().
|
||||
* using chomp().
|
||||
*
|
||||
* @param s is output buffer
|
||||
* @param size is capacity of s
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/thompike.h"
|
||||
#include "libc/str/tpdecodecb.internal.h"
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
*
|
||||
* This function is similar to getline() except it'll truncate lines
|
||||
* exceeding size. The line ending marker is included and may be removed
|
||||
* using _chomp().
|
||||
* using chomp().
|
||||
*
|
||||
* @param s is is nul-terminated string that's non-null
|
||||
* @param size is byte length of `s`
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
*
|
||||
* This function is similar to getline() except it'll truncate lines
|
||||
* exceeding size. The line ending marker is included and may be removed
|
||||
* using _chomp().
|
||||
* using chomp().
|
||||
*
|
||||
* @param s is is nul-terminated string that's non-null
|
||||
* @param size is byte length of `s`
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio_ext.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/lock.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/thread/thread.h"
|
||||
|
@ -24,5 +25,5 @@
|
|||
* Acquires reentrant lock on stdio object, blocking if needed.
|
||||
*/
|
||||
void(flockfile)(FILE *f) {
|
||||
pthread_mutex_lock((pthread_mutex_t *)f->lock);
|
||||
pthread_mutex_lock(&f->lock);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/stdio/fflush.internal.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/lock.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/stdio/stdio_ext.h"
|
||||
|
|
|
@ -358,14 +358,14 @@ static int __fmt_stoa_byte(out_f out, void *a, uint64_t c) {
|
|||
|
||||
static int __fmt_stoa_wide(out_f out, void *a, uint64_t w) {
|
||||
char buf[8];
|
||||
if (!isascii(w)) w = _tpenc(w);
|
||||
if (!isascii(w)) w = tpenc(w);
|
||||
WRITE64LE(buf, w);
|
||||
return out(buf, a, w ? (_bsr(w) >> 3) + 1 : 1);
|
||||
}
|
||||
|
||||
static int __fmt_stoa_bing(out_f out, void *a, uint64_t w) {
|
||||
char buf[8];
|
||||
w = _tpenc(kCp437[w & 0xFF]);
|
||||
w = tpenc(kCp437[w & 0xFF]);
|
||||
WRITE64LE(buf, w);
|
||||
return out(buf, a, w ? (_bsr(w) >> 3) + 1 : 1);
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ static int __fmt_stoa_quoted(out_f out, void *a, uint64_t w) {
|
|||
if (isascii(w)) {
|
||||
w = __fmt_cescapec(w);
|
||||
} else {
|
||||
w = _tpenc(w);
|
||||
w = tpenc(w);
|
||||
}
|
||||
WRITE64LE(buf, w);
|
||||
return out(buf, a, w ? (_bsr(w) >> 3) + 1 : 1);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio_ext.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
wint_t fputwc_unlocked(wchar_t wc, FILE *f) {
|
||||
uint64_t w;
|
||||
if (wc != -1) {
|
||||
w = _tpenc(wc);
|
||||
w = tpenc(wc);
|
||||
do {
|
||||
if (fputc_unlocked(w, f) == -1) {
|
||||
return -1;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio_ext.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio_ext.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/lock.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/consts/f.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/lock.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/thread/thread.h"
|
||||
|
@ -26,5 +27,5 @@
|
|||
* @return 0 on success, or non-zero if another thread owns the lock
|
||||
*/
|
||||
int(ftrylockfile)(FILE *f) {
|
||||
return pthread_mutex_trylock((pthread_mutex_t *)f->lock);
|
||||
return pthread_mutex_trylock(&f->lock);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/lock.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/thread/thread.h"
|
||||
|
@ -24,5 +25,5 @@
|
|||
* Releases lock on stdio object.
|
||||
*/
|
||||
void(funlockfile)(FILE *f) {
|
||||
pthread_mutex_unlock((pthread_mutex_t *)f->lock);
|
||||
pthread_mutex_unlock(&f->lock);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio_ext.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "libc/fmt/conv.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/stdckdint.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio_ext.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
* char *line = NULL;
|
||||
* size_t linesize = 0;
|
||||
* while (getdelim(&line, &linesize, '\n', stdin) > 0) {
|
||||
* _chomp(line);
|
||||
* chomp(line);
|
||||
* printf("%s\n", line);
|
||||
* }
|
||||
* free(line);
|
||||
|
@ -38,7 +38,7 @@
|
|||
* or -1 w/ errno on EOF or error; see ferror() and feof()
|
||||
* @note this function will ignore EINTR if it occurs mid-line
|
||||
* @raises EBADF if stream isn't open for reading
|
||||
* @see fgetln(), getline(), _chomp(), gettok_r()
|
||||
* @see fgetln(), getline(), chomp(), gettok_r()
|
||||
*/
|
||||
ssize_t getdelim(char **s, size_t *n, int delim, FILE *f) {
|
||||
ssize_t rc;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
|
|
|
@ -24,14 +24,14 @@
|
|||
* char *line = NULL;
|
||||
* size_t linesize = 0;
|
||||
* while (getline(&line, &linesize, stdin) > 0) {
|
||||
* _chomp(line);
|
||||
* chomp(line);
|
||||
* printf("%s\n", line);
|
||||
* }
|
||||
* free(line);
|
||||
*
|
||||
* This function delegates to getdelim(), which provides further
|
||||
* documentation. Concerning lines, please note the \n or \r\n are
|
||||
* included in results, and can be removed with _chomp().
|
||||
* included in results, and can be removed with chomp().
|
||||
*
|
||||
* When reading from the console on Windows in `ICANON` mode, the
|
||||
* returned line will end with `\r\n` rather than `\n`.
|
||||
|
|
|
@ -1,12 +1,31 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_STDIO_INTERNAL_H_
|
||||
#define COSMOPOLITAN_LIBC_STDIO_INTERNAL_H_
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/thread/thread.h"
|
||||
|
||||
#define PUSHBACK 12
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct FILE {
|
||||
uint8_t bufmode; /* 0x00 _IOFBF, etc. (ignored if fd=-1) */
|
||||
bool noclose; /* 0x01 for fake dup() todo delete! */
|
||||
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 */
|
||||
char *buf; /* 0x18 */
|
||||
uint32_t size; /* 0x20 */
|
||||
uint32_t nofree; /* 0x24 */
|
||||
int pid; /* 0x28 */
|
||||
char *getln; /* 0x30 */
|
||||
pthread_mutex_t lock; /* 0x38 */
|
||||
struct FILE *next; /* 0x48 */
|
||||
char mem[BUFSIZ]; /* 0x50 */
|
||||
};
|
||||
|
||||
extern uint64_t g_rando;
|
||||
|
||||
int __fflush_impl(FILE *);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_LCG_H_
|
||||
#define COSMOPOLITAN_LIBC_LCG_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
#ifdef COSMO
|
||||
#ifdef _COSMO_SOURCE
|
||||
|
||||
forceinline uint64_t KnuthLinearCongruentialGenerator(uint64_t prev[1]) {
|
||||
/* Knuth, D.E., "The Art of Computer Programming," Vol 2,
|
||||
|
@ -11,6 +11,6 @@ forceinline uint64_t KnuthLinearCongruentialGenerator(uint64_t prev[1]) {
|
|||
return prev[0]; /* be sure to shift! */
|
||||
}
|
||||
|
||||
#endif /* COSMO */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_LCG_H_ */
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/rusage.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ char *setstate(char *);
|
|||
long random(void);
|
||||
void srandom(unsigned);
|
||||
|
||||
#ifdef COSMO
|
||||
#ifdef _COSMO_SOURCE
|
||||
#define vigna __vigna
|
||||
#define vigna_r __vigna_r
|
||||
#define rngset __rngset
|
||||
|
@ -43,7 +43,7 @@ void *rngset(void *, size_t, uint64_t (*)(void), size_t);
|
|||
void rt_init(int);
|
||||
void rt_add(void *, int);
|
||||
void rt_end(double *, double *, double *, double *, double *);
|
||||
#endif /* COSMO */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/lock.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/lock.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
|
|
@ -37,6 +37,6 @@ __attribute__((__constructor__)) static void __stderr_init(void) {
|
|||
stderr->iomode = O_WRONLY;
|
||||
stderr->buf = stderr->mem;
|
||||
stderr->size = sizeof(stderr->mem);
|
||||
((pthread_mutex_t *)stderr->lock)->_type = PTHREAD_MUTEX_RECURSIVE;
|
||||
stderr->lock._type = PTHREAD_MUTEX_RECURSIVE;
|
||||
__fflush_register(stderr);
|
||||
}
|
||||
|
|
|
@ -36,6 +36,6 @@ __attribute__((__constructor__)) static void __stdin_init(void) {
|
|||
stdin->iomode = O_RDONLY;
|
||||
stdin->buf = stdin->mem;
|
||||
stdin->size = sizeof(stdin->mem);
|
||||
((pthread_mutex_t *)stdin->lock)->_type = PTHREAD_MUTEX_RECURSIVE;
|
||||
stdin->lock._type = PTHREAD_MUTEX_RECURSIVE;
|
||||
__fflush_register(stdin);
|
||||
}
|
||||
|
|
|
@ -13,23 +13,8 @@ COSMOPOLITAN_C_START_
|
|||
│ cosmopolitan § standard i/o ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
typedef struct FILE {
|
||||
uint8_t bufmode; /* 0x00 _IOFBF, etc. (ignored if fd=-1) */
|
||||
char noclose; /* 0x01 for fake dup() todo delete! */
|
||||
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 */
|
||||
char *buf; /* 0x18 */
|
||||
uint32_t size; /* 0x20 */
|
||||
uint32_t nofree; /* 0x24 */
|
||||
int pid; /* 0x28 */
|
||||
char *getln; /* 0x30 */
|
||||
char lock[16]; /* 0x38 */
|
||||
struct FILE *next; /* 0x48 */
|
||||
char mem[BUFSIZ]; /* 0x50 */
|
||||
} FILE;
|
||||
struct FILE;
|
||||
typedef struct FILE FILE;
|
||||
|
||||
extern FILE *stdin;
|
||||
extern FILE *stdout;
|
||||
|
|
|
@ -38,7 +38,7 @@ __attribute__((__constructor__)) static void __stdout_init(void) {
|
|||
stdout->iomode = O_WRONLY;
|
||||
stdout->buf = stdout->mem;
|
||||
stdout->size = sizeof(stdout->mem);
|
||||
((pthread_mutex_t *)stdout->lock)->_type = PTHREAD_MUTEX_RECURSIVE;
|
||||
stdout->lock._type = PTHREAD_MUTEX_RECURSIVE;
|
||||
|
||||
/*
|
||||
* Unlike other C libraries we don't bother calling fstat() to check
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
|
@ -28,7 +29,7 @@ wint_t ungetwc_unlocked(wint_t c, FILE *f) {
|
|||
uint64_t w;
|
||||
if (c == -1) return -1;
|
||||
n = 0;
|
||||
w = _tpenc(c);
|
||||
w = tpenc(c);
|
||||
do {
|
||||
b[n++] = w;
|
||||
} while ((w >>= 8));
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/stdckdint.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_RAND_XORSHIFT_H_
|
||||
#define COSMOPOLITAN_LIBC_RAND_XORSHIFT_H_
|
||||
#ifdef COSMO
|
||||
#ifdef _COSMO_SOURCE
|
||||
|
||||
#define kMarsagliaXorshift64Seed 88172645463325252
|
||||
#define kMarsagliaXorshift32Seed 2463534242
|
||||
|
@ -13,5 +13,5 @@ uint64_t MarsagliaXorshift64(uint64_t[hasatleast 1]);
|
|||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMO */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
#endif /* COSMOPOLITAN_LIBC_RAND_XORSHIFT_H_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue