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 void *
my_memcpy(void * d,const void * s,size_t n)8 my_memcpy (void *d, const void *s, size_t n)
9 {
10 char *dst = (char *) d;
11 const char *src = (const char *) s;
12 while (n--)
13 *dst++ = *src++;
14 return (char *) d;
15 }
16
17 void
my_bcopy(const void * s,void * d,size_t n)18 my_bcopy (const void *s, void *d, size_t n)
19 {
20 char *dst = (char *) d;
21 const char *src = (const char *) s;
22 if (src >= dst)
23 while (n--)
24 *dst++ = *src++;
25 else
26 {
27 dst += n;
28 src += n;
29 while (n--)
30 *--dst = *--src;
31 }
32 }
33
34 void *
my_memset(void * d,int c,size_t n)35 my_memset (void *d, int c, size_t n)
36 {
37 char *dst = (char *) d;
38 while (n--)
39 *dst++ = c;
40 return (char *) d;
41 }
42
43 void
my_bzero(void * d,size_t n)44 my_bzero (void *d, size_t n)
45 {
46 char *dst = (char *) d;
47 while (n--)
48 *dst++ = '\0';
49 }
50
51 void *
memcpy(void * d,const void * s,size_t n)52 memcpy (void *d, const void *s, size_t n)
53 {
54 void *result = my_memcpy (d, s, n);
55 TEST_ABORT;
56 return result;
57 }
58
59 void
bcopy(const void * s,void * d,size_t n)60 bcopy (const void *s, void *d, size_t n)
61 {
62 my_bcopy (s, d, n);
63 TEST_ABORT;
64 }
65
66 void *
memset(void * d,int c,size_t n)67 memset (void *d, int c, size_t n)
68 {
69 void *result = my_memset (d, c, n);
70 TEST_ABORT;
71 return result;
72 }
73
74 void
bzero(void * d,size_t n)75 bzero (void *d, size_t n)
76 {
77 my_bzero (d, n);
78 TEST_ABORT;
79 }
80