1extern void abort (void); 2extern int inside_main; 3typedef __SIZE_TYPE__ size_t; 4 5#define TEST_ABORT if (inside_main) abort() 6 7void * 8my_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 17void 18my_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 34void * 35my_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 43void 44my_bzero (void *d, size_t n) 45{ 46 char *dst = (char *) d; 47 while (n--) 48 *dst++ = '\0'; 49} 50 51void * 52memcpy (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 59void 60bcopy (const void *s, void *d, size_t n) 61{ 62 my_bcopy (s, d, n); 63 TEST_ABORT; 64} 65 66void * 67memset (void *d, int c, size_t n) 68{ 69 void *result = my_memset (d, c, n); 70 TEST_ABORT; 71 return result; 72} 73 74void 75bzero (void *d, size_t n) 76{ 77 my_bzero (d, n); 78 TEST_ABORT; 79} 80