void memcpy(void * dest, const void * src, int n)
{
__asm__("cld\n\t"。
"rep\n\t"
"movsb"
::"c" (n),"S" (src),"D" (dest)
);
}
void memset(char *src, unsigned char ch, int len)
{
char *p;
int i;
p = src;
for (i = 0; i < len; i++)
p[i] = ch;
}
int strlen(const char * s)
{
int i=0;
while(*(str++))
i++;
return i;
}
int strcmp(const char * s1, const char * s2)
{
int i, ret;
ret = 0;
for (i = 0; s1[i] != '\0' || s2[i] != '\0'; i++) {
if(s1[i] != s2[i]){
ret = s1[i] > s2[i] ? 1 : -1;
break;
}
}
return ret;
}
int strncmp(const char * cs, const char * ct, int count)
{
int i, ret;
for (i = 0; i < count; i++) {
if (cs[i] != ct[i]) {
ret = cs[i] > ct[i] ? 1 : -1;
return ret;
}
}
return 0;
}
char * strcpy(char *dest, const char *src)
{
int j;
for (j = 0; src[j] != '\0'; j++)
dest[j] = src[j];
dest[j] = '\0';
return dest;
}
char * strcpy(char *dest, const char *src)
{
while (*dest++ = *src++)
return dest;
}
char *strcat(char *dest, const char *src)
{
int i, j;
for (i = 0; dest[i] != '\0'; i++)
;
for (j = 0; src[j] != '\0'; i++, j++)
dest[i] = src[j];
dest[i] = '\0';
return dest;
}
char *strncat(char *dest, const char *src, int maxlen)
{
int i, j;
for (i = 0; dest[i] != '\0'; i++)
;
for (j = 0; j < maxlen; j++) {
dest[i] = src[j];
i++;
}
dest[i] = '\0';
return dest;
}
char *strchr(const char *s, int c)
{
int i;
for (i = 0; s[i] != '\0'; i++) {
if (s[i] == c)
return &s[i];
}
return '\0';
}
char *strrchr(const char *s, int c)
{
int i, len;
len = strlen(s);
for (i = len; s[i] != '\0'; i--) {
if (s[i] == c)
return &s[i];
}
return '\0';
}
char *strstr(const char *s1, const char *s2)
{
int i, j;
i = 0;
for (j = 0; s1[j] != '\0'; j++) {
if (s1[j] == s2[i]) {
if (strcmp(&s1[j], s2) == 0)
return &s1[j];
}
}
return '\0';
}
阅读(1005) | 评论(3) | 转发(0) |