5 /* We have both _memcpy and memcpy, because gcc might be able to do better in lwip.
6 * For small things, gcc inlines its memcpy, but for large things, we call out
9 void _memcpy(void *dest, const void *src, int bytes)
12 /* Since we otherwise compile with -O0, we might as well manually speed this up a bit. */
15 const char *csrc = src;
20 /* Align to src (picked arbitrarily; might as well align to something) */
21 while (bytes && ((unsigned int)csrc & 3))
23 *(cdest++) = *(csrc++);
28 isrc = (const int *)csrc;
33 switch(nwords % 8) /* They see me Duff'sin'. They hatin'. */
35 case 0: nwords--; *(idest++) = *(isrc++);
36 case 7: nwords--; *(idest++) = *(isrc++);
37 case 6: nwords--; *(idest++) = *(isrc++);
38 case 5: nwords--; *(idest++) = *(isrc++);
39 case 4: nwords--; *(idest++) = *(isrc++);
40 case 3: nwords--; *(idest++) = *(isrc++);
41 case 2: nwords--; *(idest++) = *(isrc++);
42 case 1: nwords--; *(idest++) = *(isrc++);
45 cdest = (char *)idest;
46 csrc = (const char *)isrc;
47 while (bytes) /* Clean up the remainder */
49 *(cdest++) = *(csrc++);
54 void memcpy(void *dest, const void *src, int bytes)
56 _memcpy(dest, src, bytes);
59 void memset(void *dest, int data, int bytes)
61 unsigned char *cdest = dest;
63 *(cdest++) = (unsigned char)data;
66 void memmove(void *dest, void *src, int bytes)
70 if ((cdest > csrc) && (cdest <= (csrc + bytes)))
72 /* do it backwards! */
76 *(--cdest) = *(--csrc);
78 memcpy(dest, src, bytes);
81 int memcmp (const char *a2, const char *a1, int bytes) {
84 if (*(a2++) != *(a1++))
90 int strcmp (const char *a2, const char *a1) {
92 if (*a2 != *a1) return 1;
93 if (*a2 == 0) return 0;
99 int strncmp (const char *a2, const char *a1, int n) {
101 if (*a2 != *a1) return 1;
102 if (*a2 == 0) return 0;
109 int strlen(const char *c)
117 void strcpy(char *a2, const char *a1)
124 void strcat(char *dest, char *src)
129 *(dest++) = *(src++);
130 *(dest++) = *(src++);
133 void puts(const char *c)
135 putbytes(c, strlen(c));
138 static char hexarr[] = "0123456789ABCDEF";
139 void tohex(char *s, unsigned long l)
142 for (i = 0; i < 8; i++)
144 s[i] = hexarr[l >> 28];
149 void puthex(unsigned long l)
157 unsigned short htons(unsigned short in)
159 return (in >> 8) | (in << 8);
162 unsigned int htonl(unsigned int in)
164 return ((in & 0xff) << 24) |
165 ((in & 0xff00) << 8) |
166 ((in & 0xff0000UL) >> 8) |
167 ((in & 0xff000000UL) >> 24);