mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-05 10:48:29 +00:00
Make improvements
- More timspec_*() and timeval_*() APIs have been introduced. - The copyfd() function is now simplified thanks to POSIX rules. - More Cosmo-specific APIs have been moved behind the COSMO define. - The setitimer() polyfill for Windows NT is now much higher quality. - Fixed build error for MODE=aarch64 due to -mstringop-strategy=loop. - This change introduces `make MODE=nox87 toolchain` which makes it possible to build programs using your cosmocc toolchain that don't have legacy fpu instructions. This is useful, for example, if you want to have a ~22kb tinier blink virtual machine.
This commit is contained in:
parent
8dc11afcf6
commit
c3440d040c
132 changed files with 539 additions and 587 deletions
|
@ -1,82 +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/fmt/conv.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/gc.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "libc/x/xasprintf.h"
|
||||
|
||||
float b32;
|
||||
double b64;
|
||||
long double b80;
|
||||
uint32_t u32;
|
||||
uint64_t u64;
|
||||
int128_t x;
|
||||
|
||||
void int2float(const char *s) {
|
||||
x = strtoi128(s, NULL, 0);
|
||||
if ((0 <= x && x <= UINT32_MAX) && !_startswith(s, "-") &&
|
||||
(!_endswith(s, "l") && !_endswith(s, "L"))) {
|
||||
u32 = x;
|
||||
memcpy(&b32, &u32, 4);
|
||||
s = _gc(xdtoa(b32));
|
||||
if (!strchr(s, '.')) s = _gc(xasprintf("%s.", s));
|
||||
s = _gc(xasprintf("%sf", s));
|
||||
puts(s);
|
||||
} else if ((0 <= x && x <= UINT64_MAX) && !_startswith(s, "-")) {
|
||||
u64 = x;
|
||||
memcpy(&b64, &u64, 8);
|
||||
s = _gc(xdtoa(b64));
|
||||
if (!strchr(s, '.')) s = _gc(xasprintf("%s.", s));
|
||||
puts(s);
|
||||
} else if ((INT32_MIN <= x && x <= 0) &&
|
||||
(!_endswith(s, "l") && !_endswith(s, "L"))) {
|
||||
u32 = ABS(x);
|
||||
memcpy(&b32, &u32, 4);
|
||||
b32 = -b32;
|
||||
s = _gc(xdtoa(b32));
|
||||
if (!strchr(s, '.')) s = _gc(xasprintf("%s.", s));
|
||||
s = _gc(xasprintf("%sf", s));
|
||||
puts(s);
|
||||
} else if (INT64_MIN <= x && x <= 0) {
|
||||
u64 = ABS(x);
|
||||
memcpy(&b64, &u64, 8);
|
||||
b64 = -b64;
|
||||
s = _gc(xdtoa(b64));
|
||||
if (!strchr(s, '.')) s = _gc(xasprintf("%s.", s));
|
||||
puts(s);
|
||||
} else {
|
||||
memcpy(&b80, &x, 16);
|
||||
s = _gc(xdtoa(b80));
|
||||
if (!strchr(s, '.')) s = _gc(xasprintf("%s.", s));
|
||||
s = _gc(xasprintf("%sL", s));
|
||||
puts(s);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i;
|
||||
for (i = 1; i < argc; ++i) {
|
||||
int2float(argv[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -21,7 +21,6 @@
|
|||
#include "libc/dce.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/mem/copyfd.internal.h"
|
||||
#include "libc/nt/dll.h"
|
||||
#include "libc/nt/enum/filetype.h"
|
||||
#include "libc/nt/enum/startf.h"
|
||||
|
@ -58,7 +57,7 @@ int NextBestThing(void) {
|
|||
int64_t fd = open("/proc/self/maps", O_RDONLY);
|
||||
posix_fadvise(fd, 0, 0, MADV_SEQUENTIAL);
|
||||
ssize_t wrote;
|
||||
while ((wrote = _copyfd(fd, 1, -1)) != -1) {
|
||||
while ((wrote = copyfd(fd, 1, -1)) != -1) {
|
||||
if (wrote == 0) break;
|
||||
}
|
||||
close(fd);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue