char* strcpy_s(char* dest, unsigned int size, char* src) { if (NULL == dest || NULL == src || 0 == size) { return NULL; } char* p = dest; char* q = src; int srcSize = 0; while (*(q++)) { ++srcSize; } if (size - 1 < srcSize)//源比目标长 { return NULL; } q = src; while (*q) { *(p++) = *(q++); } *p = '\0'; return dest; }
int strcmp_s(char* str1, char* str2) { if (NULL == str1 && NULL == str2)return 0; if (NULL == str1)return -1; if (NULL == str2)return 1; while(1) { if (*str1 == *str2) { if(0 == *str1) { return 0; } str1++; str2++; } else { return *str1 - *str2; } } }