Remove more nonstandard stuff from cosmopolitan.h

Fixes #61
This commit is contained in:
Justine Tunney 2021-02-28 23:42:35 -08:00
parent 5e069a64d4
commit d932948fb4
954 changed files with 1095 additions and 1342 deletions

View file

@ -20,7 +20,7 @@
#include "libc/calls/internal.h"
#include "libc/calls/struct/dirent.h"
#include "libc/dce.h"
#include "libc/macros.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/nt/enum/fileflagandattributes.h"
#include "libc/nt/enum/filetype.h"

View file

@ -37,7 +37,7 @@
int fclose(FILE *f) {
int rc;
if (!f) return 0;
_fflushunregister(f);
__fflush_unregister(f);
fflush(f);
if (!f->nofree) {
free_s(&f->buf);

View file

@ -42,7 +42,7 @@ FILE *fdopen(int fd, const char *mode) {
f->size = BUFSIZ;
if ((f->buf = valloc(f->size))) {
if ((f->iomode & O_ACCMODE) != O_RDONLY) {
_fflushregister(f);
__fflush_register(f);
}
return f;
}

View file

@ -20,7 +20,7 @@
#include "libc/bits/bits.h"
#include "libc/bits/pushpop.h"
#include "libc/calls/calls.h"
#include "libc/macros.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/fflush.internal.h"
@ -39,8 +39,8 @@ int fflush(FILE *f) {
int res, wrote;
res = 0;
if (!f) {
for (i = g_fflush.handles.i; i; --i) {
if ((f = g_fflush.handles.p[i - 1])) {
for (i = __fflush.handles.i; i; --i) {
if ((f = __fflush.handles.p[i - 1])) {
if ((wrote = fflush(f)) != -1) {
res += wrote;
} else {
@ -61,10 +61,10 @@ int fflush(FILE *f) {
return res;
}
textstartup int _fflushregister(FILE *f) {
textstartup int __fflush_register(FILE *f) {
size_t i;
struct StdioFlush *sf;
sf = &g_fflush;
sf = &__fflush;
if (!sf->handles.p) {
sf->handles.p = &sf->handles_initmem[0];
pushmov(&sf->handles.n, ARRAYLEN(sf->handles_initmem));
@ -79,10 +79,10 @@ textstartup int _fflushregister(FILE *f) {
return append(&sf->handles, &f);
}
void _fflushunregister(FILE *f) {
void __fflush_unregister(FILE *f) {
size_t i;
struct StdioFlush *sf;
sf = &g_fflush;
sf = &__fflush;
sf = pushpop(sf);
for (i = sf->handles.i; i; --i) {
if (sf->handles.p[i - 1] == f) {

View file

@ -14,7 +14,7 @@ struct StdioFlush {
FILE *handles_initmem[8];
};
extern struct StdioFlush g_fflush;
extern struct StdioFlush __fflush hidden;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -18,4 +18,4 @@
*/
#include "libc/stdio/fflush.internal.h"
struct StdioFlush g_fflush;
struct StdioFlush __fflush;

View file

@ -25,9 +25,9 @@
*/
void _flushlbf(void) {
int i;
for (i = 0; i < g_fflush.handles.i; ++i) {
if (g_fflush.handles.p[i]->bufmode == _IOLBF) {
fflush(g_fflush.handles.p[i]);
for (i = 0; i < __fflush.handles.i; ++i) {
if (__fflush.handles.p[i]->bufmode == _IOLBF) {
fflush(__fflush.handles.p[i]);
}
}
}

View file

@ -18,7 +18,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/macros.h"
#include "libc/macros.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
fseeko: jmp fseek

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
ftello: jmp ftell

View file

@ -1,21 +0,0 @@
/*-*- 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 2020 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/stdio/internal.h"
hidden FILE g_stdio[3];

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
#include "libc/notice.inc"
.source __FILE__

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
// Reads uint8_t from standard input.

View file

@ -18,7 +18,7 @@
*/
#include "libc/assert.h"
#include "libc/errno.h"
#include "libc/macros.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/stdio/internal.h"
#include "libc/stdio/stdio.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
getwc: jmp fgetwc

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
// Reads Thompson-Pike encoded varint from standard input.

View file

@ -4,13 +4,12 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
extern FILE g_stdio[3];
extern unsigned char g_stdinbuf[BUFSIZ];
extern unsigned char g_stdoutbuf[BUFSIZ];
extern unsigned char g_stderrbuf[BUFSIZ];
int _fflushregister(FILE *) hidden;
void _fflushunregister(FILE *) hidden;
int __fflush_register(FILE *) hidden;
void __fflush_unregister(FILE *) hidden;
int __freadbuf(FILE *) hidden;
int __fwritebuf(FILE *) hidden;

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
putc: jmp fputc

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
// Writes wide character to stream.

View file

@ -20,22 +20,22 @@
#include "libc/dce.h"
#include "libc/calls/calls.h"
#include "libc/sysv/consts/fileno.h"
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
.init.start 400,_init_g_stderr
ezlea g_stderr,ax
.init.start 400,_init_stderr
ezlea __stderr,ax
push $_IOLBF
pop (%rax) # f.fd
push STDERR_FILENO
pop 12(%rax)
mov O_WRONLY,%edx
mov %edx,4(%rax) # f.iomode
ezlea g_stderr_buf,cx
ezlea __stderr_buf,cx
mov %rcx,24(%rax) # f.buf
movl $BUFSIZ,32(%rax) # f.size
ezlea __fwritebuf,cx
mov %rcx,%rdx
mov %rdx,48(%rax) # f.writer
mov %rax,stderr(%rip)
.init.end 400,_init_g_stderr,globl,hidden
.init.end 400,_init_stderr,globl,hidden

View file

@ -19,18 +19,18 @@
#include "libc/stdio/internal.h"
#include "libc/stdio/stdio.h"
STATIC_YOINK("_init_g_stderr");
STATIC_YOINK("_init_stderr");
/**
* Pointer to standard error stream.
*/
FILE *stderr;
hidden FILE g_stderr;
hidden unsigned char g_stderr_buf[BUFSIZ];
hidden FILE __stderr;
hidden unsigned char __stderr_buf[BUFSIZ];
static textstartup void _init_g_stderr2() {
_fflushregister(stderr);
static textstartup void __stderr_init() {
__fflush_register(stderr);
}
const void *const g_stderr_ctor[] initarray = {_init_g_stderr2};
const void *const __stderr_ctor[] initarray = {__stderr_init};

View file

@ -20,18 +20,18 @@
#include "libc/dce.h"
#include "libc/calls/calls.h"
#include "libc/sysv/consts/fileno.h"
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
.init.start 400,_init_g_stdin
ezlea g_stdin,ax
.init.start 400,_init_stdin
ezlea __stdin,ax
mov O_RDONLY,%edx
mov %edx,4(%rax) # f.iomode
ezlea g_stdin_buf,cx
ezlea __stdin_buf,cx
mov %rcx,24(%rax) # f.buf
movl $BUFSIZ,32(%rax) # f.size
ezlea __freadbuf,cx
mov %rcx,%rdx
mov %rdx,40(%rax) # f.reader
mov %rax,stdin(%rip)
.init.end 400,_init_g_stdin,globl,hidden
.init.end 400,_init_stdin,globl,hidden

View file

@ -19,18 +19,18 @@
#include "libc/stdio/internal.h"
#include "libc/stdio/stdio.h"
STATIC_YOINK("_init_g_stdin");
STATIC_YOINK("_init_stdin");
/**
* Pointer to standard input stream.
*/
FILE *stdin;
hidden FILE g_stdin;
hidden unsigned char g_stdin_buf[BUFSIZ];
hidden FILE __stdin;
hidden unsigned char __stdin_buf[BUFSIZ];
static textstartup void g_stdin_init() {
_fflushregister(stdin);
static textstartup void __stdin_init() {
__fflush_register(stdin);
}
const void *const g_stdin_ctor[] initarray = {g_stdin_init};
const void *const __stdin_ctor[] initarray = {__stdin_init};

View file

@ -20,20 +20,20 @@
#include "libc/dce.h"
#include "libc/calls/calls.h"
#include "libc/sysv/consts/fileno.h"
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
.init.start 400,_init_g_stdout
ezlea g_stdout,ax
.init.start 400,_init_stdout
ezlea __stdout,ax
push STDOUT_FILENO
pop 12(%rax) # f.fd
mov O_WRONLY,%edx
mov %edx,4(%rax) # f.iomode
ezlea g_stdout_buf,cx
ezlea __stdout_buf,cx
mov %rcx,24(%rax) # f.buf
movl $BUFSIZ,32(%rax) # f.size
ezlea __fwritebuf,cx
mov %rcx,%rdx
mov %rdx,48(%rax) # f.writer
mov %rax,stdout(%rip)
.init.end 400,_init_g_stdout,globl,hidden
.init.end 400,_init_stdout,globl,hidden

View file

@ -22,24 +22,24 @@
#include "libc/stdio/internal.h"
#include "libc/stdio/stdio.h"
STATIC_YOINK("_init_g_stdout");
STATIC_YOINK("_init_stdout");
/**
* Pointer to standard output stream.
*/
FILE *stdout;
hidden FILE g_stdout;
hidden unsigned char g_stdout_buf[BUFSIZ];
hidden FILE __stdout;
hidden unsigned char __stdout_buf[BUFSIZ];
static textstartup void _init_g_stdout2() {
static textstartup void __stdout_init() {
struct FILE *sf;
sf = stdout;
asm("" : "+r"(sf));
if (IsWindows() || ischardev(pushpop(sf->fd))) {
sf->bufmode = _IOLBF;
}
_fflushregister(sf);
__fflush_register(sf);
}
const void *const g_stdout_ctor[] initarray = {_init_g_stdout2};
const void *const __stdout_ctor[] initarray = {__stdout_init};

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
clearerr_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
feof_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
ferror_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
fflush_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
fgetc_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
fgets_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
fgetwc_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
fgetws_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
fileno_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
fputc_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
fputs_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
fputwc_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
fputws_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
fread_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
fwrite_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
getc_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
getchar_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
getwc_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
getwchar_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
putc_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
putchar_unlocked:

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
putwc_unlocked:

View file

@ -17,7 +17,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
#include "libc/macros.internal.h"
.source __FILE__
putwchar_unlocked: