| 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 | |
|---|
| 22 | int strncpy(char* dest,char* src,int len) |
|---|
| 23 | { |
|---|
| 24 | while (*src != '\0' && len--) |
|---|
| 25 | *dest++=*src++; |
|---|
| 26 | |
|---|
| 27 | while (len--) |
|---|
| 28 | *dest++='\0'; |
|---|
| 29 | |
|---|
| 30 | return 0; |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | SYMBOL_EXPORT(strncpy); |
|---|
| 34 | |
|---|
| 35 | int strcpy(char* dest,char* src) |
|---|
| 36 | { |
|---|
| 37 | while ((*dest++=*src++)); |
|---|
| 38 | return 0; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | SYMBOL_EXPORT(strcpy); |
|---|
| 42 | |
|---|
| 43 | int strncmp(const char* s1,const char* s2,int num) |
|---|
| 44 | { |
|---|
| 45 | unsigned char res=0; |
|---|
| 46 | |
|---|
| 47 | while (num) |
|---|
| 48 | { |
|---|
| 49 | if ((res=*s1-*s2++) || !*s1++) |
|---|
| 50 | break; |
|---|
| 51 | |
|---|
| 52 | --num; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | return res; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | SYMBOL_EXPORT(strncmp); |
|---|
| 59 | |
|---|
| 60 | int strnicmp(const char* s1,const char* s2,int num) |
|---|
| 61 | { |
|---|
| 62 | unsigned char res=0; |
|---|
| 63 | |
|---|
| 64 | while (num) |
|---|
| 65 | { |
|---|
| 66 | char a=toupper(*s1),b=toupper(*s2); |
|---|
| 67 | if ((res=a-b)) |
|---|
| 68 | break; |
|---|
| 69 | |
|---|
| 70 | s1++; s2++; |
|---|
| 71 | --num; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | return res; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | SYMBOL_EXPORT(strnicmp); |
|---|
| 78 | |
|---|
| 79 | int strlen(char* str) |
|---|
| 80 | { |
|---|
| 81 | int ret=0; |
|---|
| 82 | |
|---|
| 83 | while (*str++) |
|---|
| 84 | ++ret; |
|---|
| 85 | |
|---|
| 86 | return ret; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | SYMBOL_EXPORT(strlen); |
|---|
| 90 | |
|---|
| 91 | char* strcat(char *str1,const char *str2) |
|---|
| 92 | { |
|---|
| 93 | char* target=str1; |
|---|
| 94 | while (*target) |
|---|
| 95 | target++; |
|---|
| 96 | |
|---|
| 97 | const char* src=str2; |
|---|
| 98 | while((*target++=*src++) != '\0'); |
|---|
| 99 | |
|---|
| 100 | return str1; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | SYMBOL_EXPORT(strcat); |
|---|
| 104 | |
|---|
| 105 | char* strchr(char* string,int c) |
|---|
| 106 | { |
|---|
| 107 | for (; *string; string++) |
|---|
| 108 | if (*string == (char)c) |
|---|
| 109 | return (char*)string; |
|---|
| 110 | |
|---|
| 111 | return 0; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | SYMBOL_EXPORT(strchr); |
|---|
| 115 | |
|---|
| 116 | char* strrchr(char* string,int c) |
|---|
| 117 | { |
|---|
| 118 | for (string+=strlen(string); *string; string--) |
|---|
| 119 | if (*string == (char)c) |
|---|
| 120 | return (char*)string; |
|---|
| 121 | |
|---|
| 122 | return 0; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | SYMBOL_EXPORT(strrchr); |
|---|
| 126 | |
|---|
| 127 | void* memset(void* pointer,int size,char value) |
|---|
| 128 | { |
|---|
| 129 | char* iterate=(char*)pointer; |
|---|
| 130 | |
|---|
| 131 | while (size--) |
|---|
| 132 | *iterate++=value; |
|---|
| 133 | |
|---|
| 134 | return pointer; |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | SYMBOL_EXPORT(memset); |
|---|
| 138 | |
|---|
| 139 | void* memsetw(void* pointer,int size,WORD value) |
|---|
| 140 | { |
|---|
| 141 | WORD* iterate=(WORD*)pointer; |
|---|
| 142 | |
|---|
| 143 | while (size--) |
|---|
| 144 | *iterate++=value; |
|---|
| 145 | |
|---|
| 146 | return pointer; |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | SYMBOL_EXPORT(memsetw); |
|---|
| 150 | |
|---|
| 151 | int memcmp(const void *s1, const void *s2, int n) |
|---|
| 152 | { |
|---|
| 153 | unsigned char* c1, *c2; |
|---|
| 154 | int res=0; |
|---|
| 155 | |
|---|
| 156 | for (c1=(unsigned char*)s1, c2=(unsigned char*)s2; n; ++c1, ++c2, n--) |
|---|
| 157 | { |
|---|
| 158 | if ((res=*c1-*c2)) |
|---|
| 159 | break; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | return res; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | SYMBOL_EXPORT(memcmp); |
|---|
| 166 | |
|---|
| 167 | int toupper(char ch) |
|---|
| 168 | { |
|---|
| 169 | if (ch>=97 && ch<=122) |
|---|
| 170 | ch-=0x20; |
|---|
| 171 | |
|---|
| 172 | return ch; |
|---|
| 173 | } |
|---|