mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 08:12:28 +00:00
Clean up more code
- Found some bugs in LLVM compiler-rt library - The useless LIBC_STUBS package is now deleted - Improve the overflow checking story even further - Get chibicc tests working in MODE=dbg mode again - The libc/isystem/ headers now have correctly named guards
This commit is contained in:
parent
afc58a8b41
commit
d7c79f43ef
294 changed files with 912 additions and 1208 deletions
|
@ -16,7 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/mem/fmt.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
* Formats string, allocating needed memory.
|
||||
|
@ -28,11 +28,11 @@
|
|||
* @see xasprintf() for a better API
|
||||
* @threadsafe
|
||||
*/
|
||||
int(asprintf)(char **strp, const char *fmt, ...) {
|
||||
int asprintf(char **strp, const char *fmt, ...) {
|
||||
int res;
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
res = (vasprintf)(strp, fmt, va);
|
||||
res = vasprintf(strp, fmt, va);
|
||||
va_end(va);
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -21,11 +21,11 @@
|
|||
/**
|
||||
* Formats string directly to file descriptor.
|
||||
*/
|
||||
int(dprintf)(int fd, const char *fmt, ...) {
|
||||
int dprintf(int fd, const char *fmt, ...) {
|
||||
int rc;
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
rc = (vdprintf)(fd, fmt, va);
|
||||
rc = vdprintf(fd, fmt, va);
|
||||
va_end(va);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -23,12 +23,12 @@
|
|||
* Formats and writes text to stream.
|
||||
* @see printf() for further documentation
|
||||
*/
|
||||
int(fprintf)(FILE *f, const char *fmt, ...) {
|
||||
int fprintf(FILE *f, const char *fmt, ...) {
|
||||
int rc;
|
||||
va_list va;
|
||||
flockfile(f);
|
||||
va_start(va, fmt);
|
||||
rc = (vfprintf_unlocked)(f, fmt, va);
|
||||
rc = vfprintf_unlocked(f, fmt, va);
|
||||
va_end(va);
|
||||
funlockfile(f);
|
||||
return rc;
|
||||
|
|
|
@ -22,11 +22,11 @@
|
|||
* Formats and writes text to stream.
|
||||
* @see printf() for further documentation
|
||||
*/
|
||||
int(fprintf_unlocked)(FILE *f, const char *fmt, ...) {
|
||||
int fprintf_unlocked(FILE *f, const char *fmt, ...) {
|
||||
int rc;
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
rc = (vfprintf_unlocked)(f, fmt, va);
|
||||
rc = vfprintf_unlocked(f, fmt, va);
|
||||
va_end(va);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -34,11 +34,11 @@
|
|||
*
|
||||
* @see libc/fmt/vcscanf.c
|
||||
*/
|
||||
int(fscanf)(FILE *stream, const char *fmt, ...) {
|
||||
int fscanf(FILE *stream, const char *fmt, ...) {
|
||||
int rc;
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
rc = (vcscanf)((int (*)(void *))fgetc, (void *)ungetc, stream, fmt, va);
|
||||
rc = __vcscanf((int (*)(void *))fgetc, (void *)ungetc, stream, fmt, va);
|
||||
va_end(va);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -57,11 +57,11 @@
|
|||
* @see __fmt() for intuitive reference documentation
|
||||
* @see {,v}{,s{,n},{,{,x}as},f,d}printf
|
||||
*/
|
||||
int(printf)(const char* fmt, ...) {
|
||||
int printf(const char* fmt, ...) {
|
||||
int rc;
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
rc = (vfprintf)(stdout, fmt, va);
|
||||
rc = vfprintf(stdout, fmt, va);
|
||||
va_end(va);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -23,11 +23,11 @@
|
|||
* Standard input decoder.
|
||||
* @see libc/fmt/vcscanf.h
|
||||
*/
|
||||
int(scanf)(const char *fmt, ...) {
|
||||
int scanf(const char *fmt, ...) {
|
||||
int rc;
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
rc = (vcscanf)((int (*)(void *))fgetc, NULL, stdin, fmt, va);
|
||||
rc = __vcscanf((int (*)(void *))fgetc, NULL, stdin, fmt, va);
|
||||
va_end(va);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -28,11 +28,11 @@
|
|||
* @asyncsignalsafe
|
||||
* @vforksafe
|
||||
*/
|
||||
int(snprintf)(char* buf, size_t count, const char* fmt, ...) {
|
||||
int snprintf(char* buf, size_t count, const char* fmt, ...) {
|
||||
int rc;
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
rc = (vsnprintf)(buf, count, fmt, va);
|
||||
rc = vsnprintf(buf, count, fmt, va);
|
||||
va_end(va);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -28,11 +28,11 @@
|
|||
* @asyncsignalsafe
|
||||
* @vforksafe
|
||||
*/
|
||||
int(sprintf)(char *buf, const char *fmt, ...) {
|
||||
int sprintf(char *buf, const char *fmt, ...) {
|
||||
int rc;
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
rc = (vsnprintf)(buf, INT_MAX, fmt, va);
|
||||
rc = vsnprintf(buf, INT_MAX, fmt, va);
|
||||
va_end(va);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -23,11 +23,11 @@
|
|||
* String decoder.
|
||||
* @see libc/fmt/vcscanf.h (for docs and implementation)
|
||||
*/
|
||||
int(sscanf)(const char *str, const char *fmt, ...) {
|
||||
int sscanf(const char *str, const char *fmt, ...) {
|
||||
int rc;
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
rc = (vsscanf)(str, fmt, va);
|
||||
rc = vsscanf(str, fmt, va);
|
||||
va_end(va);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef _STDIO_H
|
||||
#define _STDIO_H
|
||||
#ifndef COSMOPOLITAN_LIBC_STDIO_H_
|
||||
#define COSMOPOLITAN_LIBC_STDIO_H_
|
||||
|
||||
#define L_ctermid 20
|
||||
#define FILENAME_MAX PATH_MAX
|
||||
|
@ -125,6 +125,14 @@ int wprintf(const wchar_t *, ...);
|
|||
int wscanf(const wchar_t *, ...);
|
||||
int fwide(FILE *, int);
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § standard i/o » allocating ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
int asprintf(char **, const char *, ...) printfesque(2)
|
||||
paramsnonnull((1, 2)) libcesque;
|
||||
int vasprintf(char **, const char *, va_list) paramsnonnull() libcesque;
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § standard i/o » without mutexes ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
@ -163,4 +171,4 @@ int vfprintf_unlocked(FILE *, const char *, va_list)
|
|||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* _STDIO_H */
|
||||
#endif /* COSMOPOLITAN_LIBC_STDIO_H_ */
|
||||
|
|
|
@ -33,7 +33,6 @@ LIBC_STDIO_A_DIRECTDEPS = \
|
|||
LIBC_NT_KERNEL32 \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
LIBC_SYSV \
|
||||
LIBC_SYSV_CALLS \
|
||||
THIRD_PARTY_GDTOA
|
||||
|
|
|
@ -25,14 +25,14 @@
|
|||
* @see xasprintf() for a better API
|
||||
* @threadsafe
|
||||
*/
|
||||
int(vasprintf)(char **strp, const char *fmt, va_list va) {
|
||||
int vasprintf(char **strp, const char *fmt, va_list va) {
|
||||
va_list vb;
|
||||
size_t size;
|
||||
char *p, *p2;
|
||||
int wrote, rc = -1;
|
||||
if ((p = malloc((size = 512)))) {
|
||||
va_copy(vb, va);
|
||||
wrote = (vsnprintf)(p, size, fmt, va);
|
||||
wrote = vsnprintf(p, size, fmt, va);
|
||||
if (wrote < size) {
|
||||
if ((p2 = realloc(p, wrote + 1))) {
|
||||
p = p2;
|
||||
|
@ -42,7 +42,7 @@ int(vasprintf)(char **strp, const char *fmt, va_list va) {
|
|||
size = wrote + 1;
|
||||
if ((p2 = realloc(p, size))) {
|
||||
p = p2;
|
||||
wrote = (vsnprintf)(p, size, fmt, vb);
|
||||
wrote = vsnprintf(p, size, fmt, vb);
|
||||
_unassert(wrote == size - 1);
|
||||
rc = wrote;
|
||||
}
|
||||
|
|
|
@ -44,8 +44,11 @@
|
|||
* @param va points to the variadic argument state
|
||||
* @see libc/fmt/pflink.h (dynamic memory is not a requirement)
|
||||
*/
|
||||
int vcscanf(int callback(void *), int unget(int, void *), void *arg,
|
||||
const char *fmt, va_list va) {
|
||||
int __vcscanf(int callback(void *), //
|
||||
int unget(int, void *), //
|
||||
void *arg, //
|
||||
const char *fmt, //
|
||||
va_list va) {
|
||||
struct FreeMe {
|
||||
struct FreeMe *next;
|
||||
void *ptr;
|
||||
|
|
|
@ -58,7 +58,7 @@ static int vdprintf_putc(const char *s, struct VdprintfState *t, size_t n) {
|
|||
* @asyncsignalsafe
|
||||
* @vforksafe
|
||||
*/
|
||||
int(vdprintf)(int fd, const char *fmt, va_list va) {
|
||||
int vdprintf(int fd, const char *fmt, va_list va) {
|
||||
struct iovec iov[1];
|
||||
struct VdprintfState t;
|
||||
t.n = 0;
|
||||
|
|
|
@ -23,10 +23,10 @@
|
|||
* Formats and writes text to stream.
|
||||
* @see printf() for further documentation
|
||||
*/
|
||||
int(vfprintf)(FILE *f, const char *fmt, va_list va) {
|
||||
int vfprintf(FILE *f, const char *fmt, va_list va) {
|
||||
int rc;
|
||||
flockfile(f);
|
||||
rc = (vfprintf_unlocked)(f, fmt, va);
|
||||
rc = vfprintf_unlocked(f, fmt, va);
|
||||
funlockfile(f);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ static int vfprintfputchar(const char *s, struct state *t, size_t n) {
|
|||
* Formats and writes text to stream.
|
||||
* @see printf() for further documentation
|
||||
*/
|
||||
int(vfprintf_unlocked)(FILE *f, const char *fmt, va_list va) {
|
||||
int vfprintf_unlocked(FILE *f, const char *fmt, va_list va) {
|
||||
int rc;
|
||||
struct state st[1] = {{f, 0}};
|
||||
if ((rc = __fmt(vfprintfputchar, st, fmt, va)) != -1) {
|
||||
|
|
|
@ -23,6 +23,6 @@
|
|||
* Stream decoder.
|
||||
* @see libc/fmt/vcscanf.h
|
||||
*/
|
||||
int(vfscanf)(FILE *stream, const char *fmt, va_list ap) {
|
||||
return (vcscanf)((void *)fgetc, (void *)ungetc, stream, fmt, ap);
|
||||
int vfscanf(FILE *stream, const char *fmt, va_list ap) {
|
||||
return __vcscanf((void *)fgetc, (void *)ungetc, stream, fmt, ap);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,6 @@
|
|||
* Formats and writes text to stdout.
|
||||
* @see printf() for further documentation
|
||||
*/
|
||||
int(vprintf)(const char* fmt, va_list va) {
|
||||
return (vfprintf)(stdout, fmt, va);
|
||||
int vprintf(const char* fmt, va_list va) {
|
||||
return vfprintf(stdout, fmt, va);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,6 @@
|
|||
* String decoder.
|
||||
* @see libc/fmt/vcscanf.h
|
||||
*/
|
||||
int(vscanf)(const char *fmt, va_list ap) {
|
||||
return (vcscanf)((int (*)(void *))fgetc, (void *)ungetc, stdin, fmt, ap);
|
||||
int vscanf(const char *fmt, va_list ap) {
|
||||
return __vcscanf((int (*)(void *))fgetc, (void *)ungetc, stdin, fmt, ap);
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ static int vsnprintfputchar(const char *s, struct SprintfStr *t, size_t n) {
|
|||
* @asyncsignalsafe
|
||||
* @vforksafe
|
||||
*/
|
||||
int(vsnprintf)(char *buf, size_t size, const char *fmt, va_list va) {
|
||||
int vsnprintf(char *buf, size_t size, const char *fmt, va_list va) {
|
||||
struct SprintfStr str = {buf, 0, size};
|
||||
__fmt(vsnprintfputchar, &str, fmt, va);
|
||||
if (str.n) str.p[MIN(str.i, str.n - 1)] = '\0';
|
||||
|
|
|
@ -25,6 +25,6 @@
|
|||
* @see __fmt() and printf() for detailed documentation
|
||||
* @see vsnprintf() for modern alternative w/ buf size param
|
||||
*/
|
||||
int(vsprintf)(char *buf, const char *fmt, va_list va) {
|
||||
return (vsnprintf)(buf, INT_MAX, fmt, va);
|
||||
int vsprintf(char *buf, const char *fmt, va_list va) {
|
||||
return vsnprintf(buf, INT_MAX, fmt, va);
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ static int vsscanfcb(void *arg) {
|
|||
* needing vsscanf() won't need sscanf() too; and as such, there's
|
||||
* a small code size penalty to using both
|
||||
*/
|
||||
int(vsscanf)(const char *str, const char *fmt, va_list va) {
|
||||
int vsscanf(const char *str, const char *fmt, va_list va) {
|
||||
struct StringScannerState state = {(const unsigned char *)str, 0};
|
||||
return vcscanf(vsscanfcb, NULL, &state, fmt, va);
|
||||
return __vcscanf(vsscanfcb, NULL, &state, fmt, va);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue