| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | #include <module.h> |
|---|
| 20 | #include <string.h> |
|---|
| 21 | #include <malloc.h> |
|---|
| 22 | |
|---|
| 23 | int strncpy(char* dest,char* src, int len) |
|---|
| 24 | { |
|---|
| 25 | while (*src != '\0' && len--) |
|---|
| 26 | *dest++=*src++; |
|---|
| 27 | |
|---|
| 28 | while (len--) |
|---|
| 29 | *dest++='\0'; |
|---|
| 30 | |
|---|
| 31 | return 0; |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | SYMBOL_EXPORT(strncpy); |
|---|
| 35 | |
|---|
| 36 | char* stpcpy(char* dest, char* src) |
|---|
| 37 | { |
|---|
| 38 | while (*src != '\0') |
|---|
| 39 | *dest++=*src++; |
|---|
| 40 | |
|---|
| 41 | return dest; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | SYMBOL_EXPORT(stpcpy); |
|---|
| 45 | |
|---|
| 46 | int strncmp(const char* s1,const char* s2,int num) |
|---|
| 47 | { |
|---|
| 48 | unsigned char res=0; |
|---|
| 49 | |
|---|
| 50 | while (num) |
|---|
| 51 | { |
|---|
| 52 | if ((res=*s1-*s2++) || !*s1++) |
|---|
| 53 | break; |
|---|
| 54 | |
|---|
| 55 | --num; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | return res; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | SYMBOL_EXPORT(strncmp); |
|---|
| 62 | |
|---|
| 63 | int strnicmp(const char* s1,const char* s2,int num) |
|---|
| 64 | { |
|---|
| 65 | unsigned char res=0; |
|---|
| 66 | |
|---|
| 67 | while (num) |
|---|
| 68 | { |
|---|
| 69 | char a=toupper(*s1),b=toupper(*s2); |
|---|
| 70 | if ((res=a-b)) |
|---|
| 71 | break; |
|---|
| 72 | |
|---|
| 73 | s1++; s2++; |
|---|
| 74 | --num; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | return res; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | SYMBOL_EXPORT(strnicmp); |
|---|
| 81 | |
|---|
| 82 | int stricmp(const char* s1, const char* s2) |
|---|
| 83 | { |
|---|
| 84 | unsigned char res=0; |
|---|
| 85 | |
|---|
| 86 | while (1) |
|---|
| 87 | { |
|---|
| 88 | char a = toupper(*s1), b = toupper(*s2); |
|---|
| 89 | if (( res = a - b )) |
|---|
| 90 | break; |
|---|
| 91 | |
|---|
| 92 | s1++; s2++; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | return res; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | SYMBOL_EXPORT(stricmp); |
|---|
| 99 | |
|---|
| 100 | int strlen(char* str) |
|---|
| 101 | { |
|---|
| 102 | int ret=0; |
|---|
| 103 | |
|---|
| 104 | while (*str++) |
|---|
| 105 | ++ret; |
|---|
| 106 | |
|---|
| 107 | return ret; |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | SYMBOL_EXPORT(strlen); |
|---|
| 111 | |
|---|
| 112 | char* strcat(char *str1,const char *str2) |
|---|
| 113 | { |
|---|
| 114 | char* target=str1; |
|---|
| 115 | while (*target) |
|---|
| 116 | target++; |
|---|
| 117 | |
|---|
| 118 | const char* src=str2; |
|---|
| 119 | while((*target++=*src++) != '\0'); |
|---|
| 120 | |
|---|
| 121 | return str1; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | SYMBOL_EXPORT(strcat); |
|---|
| 125 | |
|---|
| 126 | char* strncat(char* dest, const char* src, size_t count) |
|---|
| 127 | { |
|---|
| 128 | char* tmp = dest; |
|---|
| 129 | |
|---|
| 130 | if (count) |
|---|
| 131 | { |
|---|
| 132 | while (*dest) |
|---|
| 133 | dest++; |
|---|
| 134 | |
|---|
| 135 | while ((*dest++ = *src++)) |
|---|
| 136 | { |
|---|
| 137 | if (!--count) |
|---|
| 138 | { |
|---|
| 139 | *dest = '\0'; |
|---|
| 140 | break; |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | return tmp; |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | SYMBOL_EXPORT(strncat); |
|---|
| 149 | |
|---|
| 150 | char* strchr(char* string,int c) |
|---|
| 151 | { |
|---|
| 152 | for (; *string; string++) |
|---|
| 153 | if (*string == (char)c) |
|---|
| 154 | return (char*)string; |
|---|
| 155 | |
|---|
| 156 | return 0; |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | SYMBOL_EXPORT(strchr); |
|---|
| 160 | |
|---|
| 161 | char* strrchr(char* string,int c) |
|---|
| 162 | { |
|---|
| 163 | for (string+=strlen(string); *string; string--) |
|---|
| 164 | if (*string == (char)c) |
|---|
| 165 | return (char*)string; |
|---|
| 166 | |
|---|
| 167 | return 0; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | SYMBOL_EXPORT(strrchr); |
|---|
| 171 | |
|---|
| 172 | void* memset(void* pointer, unsigned int size,char value) |
|---|
| 173 | { |
|---|
| 174 | char* iterate=(char*)pointer; |
|---|
| 175 | |
|---|
| 176 | while (size--) |
|---|
| 177 | *iterate++=value; |
|---|
| 178 | |
|---|
| 179 | return pointer; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | SYMBOL_EXPORT(memset); |
|---|
| 183 | |
|---|
| 184 | void* memsetw(void* pointer,int size,WORD value) |
|---|
| 185 | { |
|---|
| 186 | WORD* iterate=(WORD*)pointer; |
|---|
| 187 | |
|---|
| 188 | while (size--) |
|---|
| 189 | *iterate++=value; |
|---|
| 190 | |
|---|
| 191 | return pointer; |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | SYMBOL_EXPORT(memsetw); |
|---|
| 195 | |
|---|
| 196 | int memcmp(const void *s1, const void *s2, int n) |
|---|
| 197 | { |
|---|
| 198 | unsigned char* c1, *c2; |
|---|
| 199 | int res=0; |
|---|
| 200 | |
|---|
| 201 | for (c1=(unsigned char*)s1, c2=(unsigned char*)s2; n; ++c1, ++c2, n--) |
|---|
| 202 | { |
|---|
| 203 | if ((res=*c1-*c2)) |
|---|
| 204 | break; |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | return res; |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | SYMBOL_EXPORT(memcmp); |
|---|
| 211 | |
|---|
| 212 | int toupper(char ch) |
|---|
| 213 | { |
|---|
| 214 | if (ch>=97 && ch<=122) |
|---|
| 215 | ch-=0x20; |
|---|
| 216 | |
|---|
| 217 | return ch; |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | SYMBOL_EXPORT(toupper); |
|---|
| 221 | |
|---|
| 222 | char* strdup(char* name) |
|---|
| 223 | { |
|---|
| 224 | char* ret; |
|---|
| 225 | |
|---|
| 226 | ret = MemAlloc(strlen(name) + 1); |
|---|
| 227 | strncpy(ret, name, strlen(name)); |
|---|
| 228 | |
|---|
| 229 | return ret; |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | SYMBOL_EXPORT(strdup); |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | char* strcpy(char* dest, const char* src) |
|---|
| 237 | { |
|---|
| 238 | char* save = dest; |
|---|
| 239 | |
|---|
| 240 | while (*src != '\0') |
|---|
| 241 | *dest++ = *src++; |
|---|
| 242 | |
|---|
| 243 | *dest='\0'; |
|---|
| 244 | |
|---|
| 245 | return save; |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | SYMBOL_EXPORT(strcpy); |
|---|