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

Side by Side 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 unified diff | Download patch
OLDNEW
1 #include <string.h> 1 #include <string.h>
2 #include <stdint.h> 2 #include <stdint.h>
3 #include <limits.h> 3 #include <limits.h>
4 #include "libc.h" 4 #include "libc.h"
5 5
6 #define ALIGN (sizeof(size_t)-1) 6 #define ALIGN (sizeof(size_t) - 1)
7 #define ONES ((size_t)-1/UCHAR_MAX) 7 #define ONES ((size_t)-1 / UCHAR_MAX)
8 #define HIGHS (ONES * (UCHAR_MAX/2+1)) 8 #define HIGHS (ONES * (UCHAR_MAX / 2 + 1))
9 #define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) 9 #define HASZERO(x) ((x)-ONES & ~(x)&HIGHS)
10 10
11 char *__stpncpy(char *restrict d, const char *restrict s, size_t n) 11 char* __stpncpy(char* restrict d, const char* restrict s, size_t n) {
12 { 12 size_t* wd;
13 » size_t *wd; 13 const size_t* ws;
14 » const size_t *ws;
15 14
16 » if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) { 15 if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) {
17 » » for (; ((uintptr_t)s & ALIGN) && n && (*d=*s); n--, s++, d++); 16 for (; ((uintptr_t)s & ALIGN) && n && (*d = *s); n--, s++, d++)
18 » » if (!n || !*s) goto tail; 17 ;
19 » » wd=(void *)d; ws=(const void *)s; 18 if (!n || !*s)
20 » » for (; n>=sizeof(size_t) && !HASZERO(*ws); 19 goto tail;
21 » » n-=sizeof(size_t), ws++, wd++) *wd = *ws; 20 wd = (void*)d;
22 » » d=(void *)wd; s=(const void *)ws; 21 ws = (const void*)s;
23 » } 22 for (; n >= sizeof(size_t) && !HASZERO(*ws);
24 » for (; n && (*d=*s); n--, s++, d++); 23 n -= sizeof(size_t), ws++, wd++)
24 *wd = *ws;
25 d = (void*)wd;
26 s = (const void*)ws;
27 }
28 for (; n && (*d = *s); n--, s++, d++)
29 ;
25 tail: 30 tail:
26 » memset(d, 0, n); 31 memset(d, 0, n);
27 » return d; 32 return d;
28 } 33 }
29 34
30 weak_alias(__stpncpy, stpncpy); 35 weak_alias(__stpncpy, stpncpy);
31
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698