github.com/256dpi/max-go@v0.7.0/lib/max/common/basic_c_strings.c (about) 1 #include "ext.h" 2 3 #ifdef WIN_VERSION 4 5 #ifndef _CRT_SECURE_NO_WARNINGS 6 #define _CRT_SECURE_NO_WARNINGS 7 #endif 8 9 #include <string.h> 10 11 #endif // #ifdef WIN_VERSION 12 13 #ifndef WIN_VERSION 14 #ifndef NDEBUG 15 16 char *strcpy(char *s1, const char *s2) 17 { 18 char *ret = s1; 19 20 while ((*s1++ = *s2++) != 0) 21 ; 22 23 return ret; 24 } 25 26 char *strcat(char *s1, const char *s2) 27 { 28 char *ret = s1; 29 30 while (*s1++) 31 ; 32 --s1; 33 while ((*s1++ = *s2++) != 0) 34 ; 35 return ret; 36 } 37 38 int strcmp(const char *s1, const char *s2) 39 { 40 char c1, c2, dif; 41 42 for (;;) { 43 if (!(c1 = *s1++)) 44 return *s2 ? -1 : 0; 45 if (!(c2 = *s2++)) 46 return 1; 47 if (!(dif = (c1 - c2))) 48 continue; 49 if (dif < 0) 50 return -1; 51 else 52 return 1; 53 } 54 55 return 0; 56 } 57 58 unsigned long strlen(const char *s) 59 { 60 long len = 0; 61 62 while (*s++) 63 ++len; 64 65 return len; 66 } 67 68 char *strncpy(char *s1, const char *s2, unsigned long n) 69 { 70 char *res = s1; 71 72 while (n--) { 73 if ((*s1++ = *s2)!=0) 74 ++s2; 75 } 76 return res; 77 } 78 79 char *strncat(char *s1, const char *s2, unsigned long n) 80 { 81 char *res = s1; 82 83 if (n) { 84 while (*s1++) 85 ; 86 --s1; 87 while (n--) 88 if (!(*s1++ = *s2++)) 89 return res; 90 *s1 = '\0'; 91 } 92 return res; 93 } 94 95 int strncmp(const char *s1, const char *s2, unsigned long n) 96 { 97 char c1, c2, dif; 98 99 while (n--) { 100 if (!(c1 = *s1++)) 101 return *s2 ? -1 : 0; 102 if (!(c2 = *s2++)) 103 return 1; 104 if (!(dif = (c1 - c2))) 105 continue; 106 if (dif < 0) 107 return -1; 108 else 109 return 1; 110 } 111 return 0; 112 } 113 114 #endif // NDEBUG 115 #endif // #ifndef WIN_VERSION 116 117 void ctopcpy(unsigned char *p1, char *p2) 118 { 119 long len= (long) strlen(p2); 120 //changed this to not rely on CtoPstr 121 strcpy((char *)p1+1, p2); 122 p1[0]=(len>255)?255:(unsigned char)len; 123 } 124 125 void ptoccpy(char *p1, unsigned char *p2) 126 { 127 register int len = (*p2++) & 0xff; 128 while (len--) *p1++ = *p2++; 129 *p1 = '\0'; 130 } 131 132 void setmem(void *ss, long n, short b) 133 { 134 register int i; 135 unsigned char *s = (unsigned char *)ss; 136 137 for (i=0; i < n; i++,s++) 138 *s = (unsigned char)b; 139 } 140 141 void pstrcpy(unsigned char *p2, unsigned char *p1) 142 { 143 register int len; 144 145 len = *p2++ = *p1++; 146 while (--len>=0) *p2++=*p1++; 147 }