printf unification: floating point.
The only remaining differences between vfprintf.cpp and vfwprintf.cpp
after this are the wide/narrow conversions for %c, %m, and %s. I've used
"chars" and "bytes" for the named constants for the directions because
(a) I find -1 and 1 pretty confusing and (b) although "narrow" is the
obvious opposite of "wide", only Windows actually moved to wide
characters, so "narrow" (aka "multibyte", and probably "utf8") is the
default/normal case. Even though C confuses bytes and characters via its
`char` type, "bytes" versus "chars" seems like the appropriate
terminology (and it's what Java/Python use).
Also improve the swprintf tests assertion so failures are readable.
Test: treehugger
Change-Id: Ife8f70f65ec28d96058a7d68df353945524835d2
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index 645aefa..f18cd81 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -773,7 +773,7 @@
char* fgets_unlocked(char* buf, int n, FILE* fp) {
if (n <= 0) __fortify_fatal("fgets: buffer size %d <= 0", n);
- _SET_ORIENTATION(fp, -1);
+ _SET_ORIENTATION(fp, ORIENT_BYTES);
char* s = buf;
n--; // Leave space for NUL.
@@ -903,7 +903,7 @@
errno = EBADF;
return EOF;
}
- _SET_ORIENTATION(fp, -1);
+ _SET_ORIENTATION(fp, ORIENT_BYTES);
if (--fp->_w >= 0 || (fp->_w >= fp->_lbfsize && c != '\n')) {
return (*fp->_p++ = c);
}
@@ -1098,7 +1098,7 @@
size_t total = desired_total;
if (total == 0) return 0;
- _SET_ORIENTATION(fp, -1);
+ _SET_ORIENTATION(fp, ORIENT_BYTES);
// TODO: how can this ever happen?!
if (fp->_r < 0) fp->_r = 0;
@@ -1165,7 +1165,7 @@
__siov iov = { .iov_base = const_cast<void*>(buf), .iov_len = n };
__suio uio = { .uio_iov = &iov, .uio_iovcnt = 1, .uio_resid = n };
- _SET_ORIENTATION(fp, -1);
+ _SET_ORIENTATION(fp, ORIENT_BYTES);
// The usual case is success (__sfvwrite returns 0); skip the divide if this happens,
// since divides are generally slow.