blob: 6d802fa8e0e96540c802e511eeaad69ad2a56b51 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
/* Copyright (c) 2017 SiFive Inc. All rights reserved.
This copyrighted material is made available to anyone wishing to use,
modify, copy, or redistribute it subject to the terms and conditions
of the FreeBSD License. This program is distributed in the hope that
it will be useful, but WITHOUT ANY WARRANTY expressed or implied,
including the implied warranties of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. A copy of this license is available at
http://www.opensource.org/licenses.
*/
#include <string.h>
#include <stdint.h>
char *strcpy(char *dst, const char *src)
{
char *dst0 = dst;
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
int misaligned = ((uintptr_t)dst | (uintptr_t)src) & (sizeof (long) - 1);
if (__builtin_expect(!misaligned, 1))
{
long *ldst = (long *)dst;
const long *lsrc = (const long *)src;
while (!__libc_detect_null(*lsrc))
*ldst++ = *lsrc++;
dst = (char *)ldst;
src = (const char *)lsrc;
char c0 = src[0];
char c1 = src[1];
char c2 = src[2];
if (!(*dst++ = c0)) return dst0;
if (!(*dst++ = c1)) return dst0;
char c3 = src[3];
if (!(*dst++ = c2)) return dst0;
if (sizeof (long) == 4) goto out;
char c4 = src[4];
if (!(*dst++ = c3)) return dst0;
char c5 = src[5];
if (!(*dst++ = c4)) return dst0;
char c6 = src[6];
if (!(*dst++ = c5)) return dst0;
if (!(*dst++ = c6)) return dst0;
out:
*dst++ = 0;
return dst0;
}
#endif /* not PREFER_SIZE_OVER_SPEED */
char ch;
do
{
ch = *src;
src++;
dst++;
*(dst - 1) = ch;
} while (ch);
return dst0;
}
|