Last change
on this file since 367 was 337, checked in by coas-nagasima, 6 years ago |
ASP3版ECNLを追加
|
-
Property svn:eol-style
set to
native
-
Property svn:mime-type
set to
text/x-csrc;charset=UTF-8
|
File size:
766 bytes
|
Line | |
---|
1 | #include <string.h>
|
---|
2 | #include <stdint.h>
|
---|
3 | #include <limits.h>
|
---|
4 | #include "libc.h"
|
---|
5 |
|
---|
6 | #define ALIGN (sizeof(size_t)-1)
|
---|
7 | #define ONES ((size_t)-1/UCHAR_MAX)
|
---|
8 | #define HIGHS (ONES * (UCHAR_MAX/2+1))
|
---|
9 | #define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)
|
---|
10 |
|
---|
11 | char *__stpncpy(char *restrict d, const char *restrict s, size_t n)
|
---|
12 | {
|
---|
13 | size_t *wd;
|
---|
14 | const size_t *ws;
|
---|
15 |
|
---|
16 | if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) {
|
---|
17 | for (; ((uintptr_t)s & ALIGN) && n && (*d=*s); n--, s++, d++);
|
---|
18 | if (!n || !*s) goto tail;
|
---|
19 | wd=(void *)d; ws=(const void *)s;
|
---|
20 | for (; n>=sizeof(size_t) && !HASZERO(*ws);
|
---|
21 | n-=sizeof(size_t), ws++, wd++) *wd = *ws;
|
---|
22 | d=(void *)wd; s=(const void *)ws;
|
---|
23 | }
|
---|
24 | for (; n && (*d=*s); n--, s++, d++);
|
---|
25 | tail:
|
---|
26 | memset(d, 0, n);
|
---|
27 | return d;
|
---|
28 | }
|
---|
29 |
|
---|
30 | weak_alias(__stpncpy, stpncpy);
|
---|
31 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.