Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2000)

Unified Diff: fusl/src/stdio/vsnprintf.c

Issue 1714623002: [fusl] clang-format fusl (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: headers too Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: fusl/src/stdio/vsnprintf.c
diff --git a/fusl/src/stdio/vsnprintf.c b/fusl/src/stdio/vsnprintf.c
index be2c44eb176d70a5d867b9f339dd58afe5953ec7..1e76b4e02fa6a8ecf3d16bb040b4350320797ffd 100644
--- a/fusl/src/stdio/vsnprintf.c
+++ b/fusl/src/stdio/vsnprintf.c
@@ -4,39 +4,43 @@
#include <errno.h>
#include <stdint.h>
-static size_t sn_write(FILE *f, const unsigned char *s, size_t l)
-{
- size_t k = f->wend - f->wpos;
- if (k > l) k = l;
- memcpy(f->wpos, s, k);
- f->wpos += k;
- /* pretend to succeed, but discard extra data */
- return l;
+static size_t sn_write(FILE* f, const unsigned char* s, size_t l) {
+ size_t k = f->wend - f->wpos;
+ if (k > l)
+ k = l;
+ memcpy(f->wpos, s, k);
+ f->wpos += k;
+ /* pretend to succeed, but discard extra data */
+ return l;
}
-int vsnprintf(char *restrict s, size_t n, const char *restrict fmt, va_list ap)
-{
- int r;
- char b;
- FILE f = { .lbf = EOF, .write = sn_write, .lock = -1 };
+int vsnprintf(char* restrict s,
+ size_t n,
+ const char* restrict fmt,
+ va_list ap) {
+ int r;
+ char b;
+ FILE f = {.lbf = EOF, .write = sn_write, .lock = -1};
- if (n-1 > INT_MAX-1) {
- if (n) {
- errno = EOVERFLOW;
- return -1;
- }
- s = &b;
- n = 1;
- }
+ if (n - 1 > INT_MAX - 1) {
+ if (n) {
+ errno = EOVERFLOW;
+ return -1;
+ }
+ s = &b;
+ n = 1;
+ }
- /* Ensure pointers don't wrap if "infinite" n is passed in */
- if (n > (char *)0+SIZE_MAX-s-1) n = (char *)0+SIZE_MAX-s-1;
- f.buf_size = n;
- f.buf = f.wpos = (void *)s;
- f.wbase = f.wend = (void *)(s+n);
- r = vfprintf(&f, fmt, ap);
+ /* Ensure pointers don't wrap if "infinite" n is passed in */
+ if (n > (char*)0 + SIZE_MAX - s - 1)
+ n = (char*)0 + SIZE_MAX - s - 1;
+ f.buf_size = n;
+ f.buf = f.wpos = (void*)s;
+ f.wbase = f.wend = (void*)(s + n);
+ r = vfprintf(&f, fmt, ap);
- /* Null-terminate, overwriting last char if dest buffer is full */
- if (n) f.wpos[-(f.wpos == f.wend)] = 0;
- return r;
+ /* Null-terminate, overwriting last char if dest buffer is full */
+ if (n)
+ f.wpos[-(f.wpos == f.wend)] = 0;
+ return r;
}

Powered by Google App Engine
This is Rietveld 408576698