diff options
Diffstat (limited to 'lib/libc/stdio')
| -rw-r--r-- | lib/libc/stdio/perror.c | 6 | ||||
| -rw-r--r-- | lib/libc/stdio/remove.c | 2 | ||||
| -rw-r--r-- | lib/libc/stdio/rename.c | 1 | ||||
| -rw-r--r-- | lib/libc/stdio/renameat.c | 1 | ||||
| -rw-r--r-- | lib/libc/stdio/vfprintf.c | 39 |
5 files changed, 38 insertions, 11 deletions
diff --git a/lib/libc/stdio/perror.c b/lib/libc/stdio/perror.c index ad314038..02e14a42 100644 --- a/lib/libc/stdio/perror.c +++ b/lib/libc/stdio/perror.c @@ -8,19 +8,21 @@ void perror(const char *s) { + char *errstr; struct iovec iov[4]; - char *errstr = strerror(errno); - if (s != NULL && *s != '\0') { iov[0].iov_base = (void *)s; iov[0].iov_len = strlen(s); + iov[1].iov_base = ": "; iov[1].iov_len = 2; } + errstr = strerror(errno); iov[s != NULL && *s != '\0' ? 2 : 0].iov_base = errstr; iov[s != NULL && *s != '\0' ? 2 : 0].iov_len = strlen(errstr); + iov[s != NULL && *s != '\0' ? 3 : 1].iov_base = "\n"; iov[s != NULL && *s != '\0' ? 3 : 1].iov_len = 1; diff --git a/lib/libc/stdio/remove.c b/lib/libc/stdio/remove.c index 9afd47b4..8cb9c298 100644 --- a/lib/libc/stdio/remove.c +++ b/lib/libc/stdio/remove.c @@ -1,4 +1,4 @@ -#include "errno.h" // for EISDIR, errno +#include "errno.h" // for EISDIR, errno #include <fcntl.h> // for AT_FDCWD, AT_REMOVEDIR #include <stdio.h> // for remove diff --git a/lib/libc/stdio/rename.c b/lib/libc/stdio/rename.c index 52426ab0..17f09df5 100644 --- a/lib/libc/stdio/rename.c +++ b/lib/libc/stdio/rename.c @@ -1,6 +1,5 @@ - #include <stdio.h> // for rename #include <syscall.h> // for __syscall_2, syscall diff --git a/lib/libc/stdio/renameat.c b/lib/libc/stdio/renameat.c index c7e9a683..b82323ef 100644 --- a/lib/libc/stdio/renameat.c +++ b/lib/libc/stdio/renameat.c @@ -1,6 +1,5 @@ - #include <syscall.h> // for __syscall_4, syscall int renameat(int oldfd, const char *old, int newfd, const char *new) diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index 126c1193..06609046 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -1,13 +1,40 @@ -#include <ctype.h> // for isdigit -#include <errno.h> // for EINVAL, errno -#include <math.h> // for frexp, isinf, isnan -#include <stdarg.h> // for va_arg -#include <stddef.h> // for NULL, ptrdiff_t +#include <ctype.h> // for isdigit +#include <errno.h> // for EINVAL, errno +#include <math.h> // for isinf, isnan +#include <stdarg.h> // for va_arg +#include <stddef.h> // for NULL, ptrdiff_t +#include <stdint.h> #include <stdint.h> // for uintptr_t, intmax_t, uintmax_t #include <stdio.h> // for fwrite, fputc, vfprintf, FILE, va_list #include <string.h> // for memmove, strlcpy, strlen #include <sys/types.h> // for size_t, ssize_t +static double __frexp(double x, int *e) +{ + union { + double d; + uint64_t i; + } y = { x }; + uint64_t ee = y.i >> 52 & 0x7ff; + + if (!ee) { + if (x) { + x = __frexp(x * 0x1p64, e); + *e -= 64; + } else + *e = 0; + return x; + } + if (ee == 0x7ff) { + return x; + } + + *e = (int)ee - 0x3fe; + y.i &= 0x800fffffffffffffull; + y.i |= 0x3fe0000000000000ull; + return y.d; +} + extern char *dtoa(double, int mode, int ndigits, int *decpt, int *sign, char **rve); extern void freedtoa(char *s); @@ -615,7 +642,7 @@ int vfprintf(FILE *restrict stream, const char *restrict format, va_list ap) } int exp; - double mant = frexp(val, &exp); + double mant = __frexp(val, &exp); mant *= 2.0; exp--; |
