Subversion Repositories Kolibri OS

Rev

Rev 8793 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8793 Rev 9765
Line 1... Line -...
1
/* strncmp( const char *, const char *, size_t )
-
 
2
 
-
 
3
   This file is part of the Public Domain C Library (PDCLib).
-
 
4
   Permission is granted to use, modify, and / or redistribute at will.
1
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
5
*/
-
 
6
 
-
 
7
#include 
2
#include 
Line 8... Line 3...
8
 
3
 
9
int strncmp( const char * s1, const char * s2, size_t n )
4
int strncmp(const char* s1, const char* s2, size_t n)
10
{
5
{
11
    while ( n && *s1 && ( *s1 == *s2 ) )
6
    register int __res;
-
 
7
    int d0, d1, d2;
12
    {
8
    __asm__ __volatile__(
13
        ++s1;
9
        "1:\tdecl %3\n\t"
14
        ++s2;
10
        "js 2f\n\t"
15
        --n;
11
        "lodsb\n\t"
16
    }
-
 
17
 
12
        "scasb\n\t"
18
    if ( n == 0 )
13
        "jne 3f\n\t"
19
    {
14
        "testb %%al,%%al\n\t"
-
 
15
        "jne 1b\n"
20
        return 0;
16
        "2:\txorl %%eax,%%eax\n\t"
-
 
17
        "jmp 4f\n"
21
    }
18
        "3:\tsbbl %%eax,%%eax\n\t"
22
    else
19
        "orb $1,%%al\n"
23
    {
20
        "4:"
-
 
21
        : "=a"(__res), "=&S"(d0), "=&D"(d1), "=&c"(d2)
24
        return ( *( unsigned char * )s1 - * ( unsigned char * )s2 );
22
        : "1"(s1), "2"(s2), "3"(n));
25
    }
23
    return __res;
26
}
24
}