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
/* strncat( 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.
-
 
5
*/
-
 
6
 
-
 
7
#include 
1
#include 
Line 8... Line 2...
8
 
2
 
9
char * strncat( char * s1, const char * s2, size_t n )
-
 
10
{
-
 
11
    char * rc = s1;
-
 
12
 
-
 
13
    while ( *s1 )
-
 
14
    {
-
 
15
        ++s1;
-
 
16
    }
-
 
17
 
-
 
18
    while ( n && ( *s1++ = *s2++ ) )
-
 
19
    {
-
 
20
        --n;
-
 
21
    }
-
 
22
 
-
 
23
    if ( n == 0 )
3
char* strncat(char* dst, const char* src, size_t n)
-
 
4
{
-
 
5
    int d0, d1, d2, d3;
-
 
6
    __asm__ __volatile__(
24
    {
7
        "repne\n\t"
-
 
8
        "scasb\n\t"
-
 
9
        "decl %1\n\t"
-
 
10
        "movl %8,%3\n"
-
 
11
        "1:\tdecl %3\n\t"
-
 
12
        "js 2f\n\t"
-
 
13
        "lodsb\n\t"
-
 
14
        "stosb\n\t"
-
 
15
        "testb %%al,%%al\n\t"
-
 
16
        "jne 1b\n"
25
        *s1 = '\0';
17
        "2:\txorl %2,%2\n\t"
26
    }
-
 
-
 
18
        "stosb"
-
 
19
        : "=&S"(d0), "=&D"(d1), "=&a"(d2), "=&c"(d3)
-
 
20
        : "0"(src), "1"(dst), "2"(0), "3"(0xffffffff), "g"(n)
27
 
21
        : "memory");
28
    return rc;
22
    return dst;
29
}
23
}