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

Unified Diff: fusl/src/string/stpncpy.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/string/stpncpy.c
diff --git a/fusl/src/string/stpncpy.c b/fusl/src/string/stpncpy.c
index 1f57a4ddbd0a818168e56c0b15178e93304c42cf..1860fb9ca4941ed390ca93b8d0d10f77c73848ec 100644
--- a/fusl/src/string/stpncpy.c
+++ b/fusl/src/string/stpncpy.c
@@ -3,29 +3,33 @@
#include <limits.h>
#include "libc.h"
-#define ALIGN (sizeof(size_t)-1)
-#define ONES ((size_t)-1/UCHAR_MAX)
-#define HIGHS (ONES * (UCHAR_MAX/2+1))
-#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)
+#define ALIGN (sizeof(size_t) - 1)
+#define ONES ((size_t)-1 / UCHAR_MAX)
+#define HIGHS (ONES * (UCHAR_MAX / 2 + 1))
+#define HASZERO(x) ((x)-ONES & ~(x)&HIGHS)
-char *__stpncpy(char *restrict d, const char *restrict s, size_t n)
-{
- size_t *wd;
- const size_t *ws;
+char* __stpncpy(char* restrict d, const char* restrict s, size_t n) {
+ size_t* wd;
+ const size_t* ws;
- if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) {
- for (; ((uintptr_t)s & ALIGN) && n && (*d=*s); n--, s++, d++);
- if (!n || !*s) goto tail;
- wd=(void *)d; ws=(const void *)s;
- for (; n>=sizeof(size_t) && !HASZERO(*ws);
- n-=sizeof(size_t), ws++, wd++) *wd = *ws;
- d=(void *)wd; s=(const void *)ws;
- }
- for (; n && (*d=*s); n--, s++, d++);
+ if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) {
+ for (; ((uintptr_t)s & ALIGN) && n && (*d = *s); n--, s++, d++)
+ ;
+ if (!n || !*s)
+ goto tail;
+ wd = (void*)d;
+ ws = (const void*)s;
+ for (; n >= sizeof(size_t) && !HASZERO(*ws);
+ n -= sizeof(size_t), ws++, wd++)
+ *wd = *ws;
+ d = (void*)wd;
+ s = (const void*)ws;
+ }
+ for (; n && (*d = *s); n--, s++, d++)
+ ;
tail:
- memset(d, 0, n);
- return d;
+ memset(d, 0, n);
+ return d;
}
weak_alias(__stpncpy, stpncpy);
-

Powered by Google App Engine
This is Rietveld 408576698