1 extern void abort (void);
2 extern int inside_main;
3 typedef __SIZE_TYPE__ size_t;
4
5 #define TEST_ABORT if (inside_main) abort()
6
7 /* LTO code is at the present to able to track that asm alias my_bcopy on builtin
8 actually refers to this function. See PR47181. */
9 __attribute__ ((used))
10 void *
my_memcpy(void * d,const void * s,size_t n)11 my_memcpy (void *d, const void *s, size_t n)
12 {
13 char *dst = (char *) d;
14 const char *src = (const char *) s;
15 while (n--)
16 *dst++ = *src++;
17 return (char *) d;
18 }
19
20 /* LTO code is at the present to able to track that asm alias my_bcopy on builtin
21 actually refers to this function. See PR47181. */
22 __attribute__ ((used))
23 void
my_bcopy(const void * s,void * d,size_t n)24 my_bcopy (const void *s, void *d, size_t n)
25 {
26 char *dst = (char *) d;
27 const char *src = (const char *) s;
28 if (src >= dst)
29 while (n--)
30 *dst++ = *src++;
31 else
32 {
33 dst += n;
34 src += n;
35 while (n--)
36 *--dst = *--src;
37 }
38 }
39
40 __attribute__ ((used))
41 void *
my_memmove(void * d,const void * s,size_t n)42 my_memmove (void *d, const void *s, size_t n)
43 {
44 char *dst = (char *) d;
45 const char *src = (const char *) s;
46 if (src >= dst)
47 while (n--)
48 *dst++ = *src++;
49 else
50 {
51 dst += n;
52 src += n;
53 while (n--)
54 *--dst = *--src;
55 }
56
57 return d;
58 }
59
60 /* LTO code is at the present to able to track that asm alias my_bcopy on builtin
61 actually refers to this function. See PR47181. */
62 __attribute__ ((used))
63 void *
my_memset(void * d,int c,size_t n)64 my_memset (void *d, int c, size_t n)
65 {
66 char *dst = (char *) d;
67 while (n--)
68 *dst++ = c;
69 return (char *) d;
70 }
71
72 /* LTO code is at the present to able to track that asm alias my_bcopy on builtin
73 actually refers to this function. See PR47181. */
74 __attribute__ ((used))
75 void
my_bzero(void * d,size_t n)76 my_bzero (void *d, size_t n)
77 {
78 char *dst = (char *) d;
79 while (n--)
80 *dst++ = '\0';
81 }
82
83 void *
memcpy(void * d,const void * s,size_t n)84 memcpy (void *d, const void *s, size_t n)
85 {
86 void *result = my_memcpy (d, s, n);
87 TEST_ABORT;
88 return result;
89 }
90
91 void
bcopy(const void * s,void * d,size_t n)92 bcopy (const void *s, void *d, size_t n)
93 {
94 my_bcopy (s, d, n);
95 TEST_ABORT;
96 }
97
98 void *
memset(void * d,int c,size_t n)99 memset (void *d, int c, size_t n)
100 {
101 void *result = my_memset (d, c, n);
102 TEST_ABORT;
103 return result;
104 }
105
106 void
bzero(void * d,size_t n)107 bzero (void *d, size_t n)
108 {
109 my_bzero (d, n);
110 TEST_ABORT;
111 }
112
113 #ifdef __vxworks
114 /* The RTP C library uses bfill, which is defined in the same file as
115 bzero and bcopy. */
116 #include "lib/bfill.c"
117 #endif
118