]>
Commit | Line | Data |
---|---|---|
1 | #include "console.h" | |
2 | #include <minilib.h> | |
3 | ||
4 | void memcpy(void *dest, const void *src, int bytes) | |
5 | { | |
6 | char *cdest = dest; | |
7 | const char *csrc = src; | |
8 | while (bytes--) | |
9 | *(cdest++) = *(csrc++); | |
10 | } | |
11 | ||
12 | void memset(void *dest, int data, int bytes) | |
13 | { | |
14 | unsigned char *cdest = dest; | |
15 | while (bytes--) | |
16 | *(cdest++) = (unsigned char)data; | |
17 | } | |
18 | ||
19 | void memmove(void *dest, void *src, int bytes) | |
20 | { | |
21 | char * cdest = dest; | |
22 | char * csrc = src; | |
23 | if ((cdest > csrc) && (cdest <= (csrc + bytes))) | |
24 | { | |
25 | /* do it backwards! */ | |
26 | cdest += bytes; | |
27 | csrc += bytes; | |
28 | while (bytes--) | |
29 | *(--cdest) = *(--csrc); | |
30 | } else | |
31 | while (bytes--) | |
32 | *(cdest++) = *(csrc++); | |
33 | } | |
34 | ||
35 | int memcmp (const char *a2, const char *a1, int bytes) { | |
36 | while (bytes--) | |
37 | { | |
38 | if (*(a2++) != *(a1++)) | |
39 | return 1; | |
40 | } | |
41 | return 0; | |
42 | } | |
43 | ||
44 | int strcmp (const char *a2, const char *a1) { | |
45 | while (1) { | |
46 | if (*a2 != *a1) return 1; | |
47 | if (*a2 == 0) return 0; | |
48 | a1++; | |
49 | a2++; | |
50 | } | |
51 | } | |
52 | ||
53 | int strlen(const char *c) | |
54 | { | |
55 | int l = 0; | |
56 | while (*(c++)) | |
57 | l++; | |
58 | return l; | |
59 | } | |
60 | ||
61 | void strcpy(char *a2, const char *a1) | |
62 | { | |
63 | do { | |
64 | *(a2++) = *a1; | |
65 | } while (*(a1++)); | |
66 | } | |
67 | ||
68 | void puts(const char *c) | |
69 | { | |
70 | putbytes(c, strlen(c)); | |
71 | } | |
72 | ||
73 | static char hexarr[] = "0123456789ABCDEF"; | |
74 | void tohex(char *s, unsigned long l) | |
75 | { | |
76 | int i; | |
77 | for (i = 0; i < 8; i++) | |
78 | { | |
79 | s[i] = hexarr[l >> 28]; | |
80 | l <<= 4; | |
81 | } | |
82 | } | |
83 | ||
84 | void puthex(unsigned long l) | |
85 | { | |
86 | char d[9]; | |
87 | d[8] = 0; | |
88 | tohex(d, l); | |
89 | puts(d); | |
90 | } | |
91 | ||
92 | unsigned short htons(unsigned short in) | |
93 | { | |
94 | return (in >> 8) | (in << 8); | |
95 | } | |
96 | ||
97 | unsigned int htonl(unsigned int in) | |
98 | { | |
99 | return ((in & 0xff) << 24) | | |
100 | ((in & 0xff00) << 8) | | |
101 | ((in & 0xff0000UL) >> 8) | | |
102 | ((in & 0xff000000UL) >> 24); | |
103 | } |