forked from KolibriOS/kolibrios
libc.obj:
- Formatted by clang-format (WebKit-style). - Removed unnecessary errno linux. - Added KOS error codes. - String functions have been replaced with more optimal ones for x86. - Changed wrappers for 70 sysfunction. git-svn-id: svn://kolibrios.org@9765 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
@@ -1,24 +1,20 @@
|
||||
/* memchr( const void *, int, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void * memchr( const void * s, int c, size_t n )
|
||||
{
|
||||
const unsigned char * p = ( const unsigned char * ) s;
|
||||
|
||||
while ( n-- )
|
||||
{
|
||||
if ( *p == ( unsigned char ) c )
|
||||
{
|
||||
return ( void * ) p;
|
||||
}
|
||||
|
||||
++p;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
#include <assert.h>
|
||||
#include "unconst.h"
|
||||
#include <string.h>
|
||||
|
||||
void* memchr(const void* s, int c, size_t n)
|
||||
{
|
||||
int d0;
|
||||
register void* __res;
|
||||
if (!n)
|
||||
return NULL;
|
||||
__asm__ __volatile__(
|
||||
"repne\n\t"
|
||||
"scasb\n\t"
|
||||
"je 1f\n\t"
|
||||
"movl $1,%0\n"
|
||||
"1:\tdecl %0"
|
||||
: "=D"(__res), "=&c"(d0)
|
||||
: "a"(c), "0"(s), "1"(n));
|
||||
return __res;
|
||||
}
|
@@ -1,26 +1,15 @@
|
||||
/* memcmp( const void *, const void *, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int memcmp( const void * s1, const void * s2, size_t n )
|
||||
{
|
||||
const unsigned char * p1 = ( const unsigned char * ) s1;
|
||||
const unsigned char * p2 = ( const unsigned char * ) s2;
|
||||
|
||||
while ( n-- )
|
||||
{
|
||||
if ( *p1 != *p2 )
|
||||
{
|
||||
return *p1 - *p2;
|
||||
}
|
||||
|
||||
++p1;
|
||||
++p2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
int memcmp(const void* s1, const void* s2, size_t n)
|
||||
{
|
||||
if (n != 0) {
|
||||
const unsigned char *p1 = s1, *p2 = s2;
|
||||
do {
|
||||
if (*p1++ != *p2++)
|
||||
return (*--p1 - *--p2);
|
||||
} while (--n != 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
@@ -1,20 +1,19 @@
|
||||
/* memcpy( void *, const void *, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void * memcpy( void * s1, const void * s2, size_t n )
|
||||
{
|
||||
char * dest = ( char * ) s1;
|
||||
const char * src = ( const char * ) s2;
|
||||
|
||||
while ( n-- )
|
||||
{
|
||||
*dest++ = *src++;
|
||||
}
|
||||
|
||||
return s1;
|
||||
#include <string.h>
|
||||
|
||||
void* memcpy(void* _dest, const void* _src, size_t _n)
|
||||
{
|
||||
int d0, d1, d2;
|
||||
__asm__ __volatile__(
|
||||
"rep ; movsl\n\t"
|
||||
"testb $2,%b4\n\t"
|
||||
"je 1f\n\t"
|
||||
"movsw\n"
|
||||
"1:\ttestb $1,%b4\n\t"
|
||||
"je 2f\n\t"
|
||||
"movsb\n"
|
||||
"2:"
|
||||
: "=&c"(d0), "=&D"(d1), "=&S"(d2)
|
||||
: "0"(_n / 4), "q"(_n), "1"((long)_dest), "2"((long)_src)
|
||||
: "memory");
|
||||
return (_dest);
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
/* memmove( void *, const void *, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void * memmove( void * s1, const void * s2, size_t n )
|
||||
{
|
||||
char * dest = ( char * ) s1;
|
||||
const char * src = ( const char * ) s2;
|
||||
|
||||
if ( dest <= src )
|
||||
{
|
||||
while ( n-- )
|
||||
{
|
||||
*dest++ = *src++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
src += n;
|
||||
dest += n;
|
||||
|
||||
while ( n-- )
|
||||
{
|
||||
*--dest = *--src;
|
||||
}
|
||||
}
|
||||
|
||||
return s1;
|
||||
}
|
34
programs/develop/ktcc/trunk/libc.obj/source/string/memmove.s
Executable file
34
programs/develop/ktcc/trunk/libc.obj/source/string/memmove.s
Executable file
@@ -0,0 +1,34 @@
|
||||
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
|
||||
|
||||
.global memmove
|
||||
|
||||
memmove:
|
||||
pushl %ebp
|
||||
movl %esp,%ebp
|
||||
pushl %esi
|
||||
pushl %edi
|
||||
movl 8(%ebp),%edi
|
||||
movl 12(%ebp),%esi
|
||||
movl 16(%ebp),%ecx
|
||||
jecxz memmove.L2
|
||||
cld
|
||||
cmpl %esi,%edi
|
||||
jb memmove.L3
|
||||
|
||||
std
|
||||
addl %ecx,%esi
|
||||
addl %ecx,%edi
|
||||
decl %esi
|
||||
decl %edi
|
||||
memmove.L3:
|
||||
rep
|
||||
movsb
|
||||
|
||||
memmove.L2:
|
||||
cld
|
||||
popl %edi
|
||||
popl %esi
|
||||
movl 8(%ebp),%eax
|
||||
leave
|
||||
ret
|
||||
|
@@ -1,20 +0,0 @@
|
||||
/* memset( void *, int, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
void * memset( void * s, int c, size_t n )
|
||||
{
|
||||
unsigned char * p = ( unsigned char * ) s;
|
||||
|
||||
while ( n-- )
|
||||
{
|
||||
*p++ = ( unsigned char ) c;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
51
programs/develop/ktcc/trunk/libc.obj/source/string/memset.s
Executable file
51
programs/develop/ktcc/trunk/libc.obj/source/string/memset.s
Executable file
@@ -0,0 +1,51 @@
|
||||
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
|
||||
.text
|
||||
.align 4
|
||||
.global memset
|
||||
|
||||
memset:
|
||||
pushl %ebp
|
||||
movl %esp,%ebp
|
||||
pushl %edi
|
||||
movl 8(%ebp),%edi
|
||||
movl 12(%ebp),%eax
|
||||
movl 16(%ebp),%ecx
|
||||
cld
|
||||
|
||||
# We will handle memsets of <= 15 bytes one byte at a time.
|
||||
# This avoids some extra overhead for small memsets, and
|
||||
# knowing we are setting > 15 bytes eliminates some annoying
|
||||
# checks in the "long move" case.
|
||||
cmpl $15,%ecx
|
||||
jle memset.L3
|
||||
|
||||
# Otherwise, tile the byte value out into %eax.
|
||||
# 0x41 -> 0x41414141, etc.
|
||||
movb %al,%ah
|
||||
movl %eax,%edx
|
||||
sall $16,%eax
|
||||
movw %dx,%ax
|
||||
jmp memset.L2
|
||||
|
||||
# Handle any cruft necessary to get %edi long-aligned.
|
||||
memset.L1: stosb
|
||||
decl %ecx
|
||||
memset.L2: testl $3,%edi
|
||||
jnz memset.L1
|
||||
|
||||
# Now slam out all of the longs.
|
||||
movl %ecx,%edx
|
||||
shrl $2,%ecx
|
||||
rep
|
||||
stosl
|
||||
|
||||
# Finally, handle any trailing cruft. We know the high three bytes
|
||||
# of %ecx must be zero, so just put the "slop count" in the low byte.
|
||||
movb %dl,%cl
|
||||
andb $3,%cl
|
||||
memset.L3: rep
|
||||
stosb
|
||||
popl %edi
|
||||
movl 8(%ebp),%eax
|
||||
leave
|
||||
ret
|
@@ -1,27 +1,18 @@
|
||||
/* strcat( char *, const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char * strcat( char * s1, const char * s2 )
|
||||
{
|
||||
char * rc = s1;
|
||||
|
||||
if ( *s1 )
|
||||
{
|
||||
while ( *++s1 )
|
||||
{
|
||||
/* EMPTY */
|
||||
}
|
||||
}
|
||||
|
||||
while ( ( *s1++ = *s2++ ) )
|
||||
{
|
||||
/* EMPTY */
|
||||
}
|
||||
|
||||
return rc;
|
||||
#include <string.h>
|
||||
|
||||
char* strcat(char* s, const char* append)
|
||||
{
|
||||
int d0, d1, d2, d3;
|
||||
__asm__ __volatile__(
|
||||
"repne\n\t"
|
||||
"scasb\n\t"
|
||||
"decl %1\n"
|
||||
"1:\tlodsb\n\t"
|
||||
"stosb\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"jne 1b"
|
||||
: "=&S"(d0), "=&D"(d1), "=&a"(d2), "=&c"(d3)
|
||||
: "0"(append), "1"(s), "2"(0), "3"(0xffffffff)
|
||||
: "memory");
|
||||
return s;
|
||||
}
|
@@ -1,20 +1,21 @@
|
||||
/* strchr( const char *, int )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char * strchr( const char * s, int c )
|
||||
{
|
||||
do
|
||||
{
|
||||
if ( *s == ( char ) c )
|
||||
{
|
||||
return ( char * ) s;
|
||||
}
|
||||
} while ( *s++ );
|
||||
|
||||
return NULL;
|
||||
#include "unconst.h"
|
||||
#include <string.h>
|
||||
|
||||
char* strchr(const char* s, int c)
|
||||
{
|
||||
int d0;
|
||||
register char* __res;
|
||||
__asm__ __volatile__(
|
||||
"movb %%al,%%ah\n"
|
||||
"1:\tlodsb\n\t"
|
||||
"cmpb %%ah,%%al\n\t"
|
||||
"je 2f\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"jne 1b\n\t"
|
||||
"movl $1,%1\n"
|
||||
"2:\tmovl %1,%0\n\t"
|
||||
"decl %0"
|
||||
: "=a"(__res), "=&S"(d0)
|
||||
: "1"((unsigned)s), "0"(c));
|
||||
return __res;
|
||||
}
|
@@ -1,14 +1,21 @@
|
||||
/* strcmp( const char *, const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/ksys.h>
|
||||
|
||||
int strcmp(const char * s1, const char * s2)
|
||||
{
|
||||
return __strcmp(s1, s2);
|
||||
}
|
||||
#include <string.h>
|
||||
|
||||
int strcmp(const char* s1, const char* s2)
|
||||
{
|
||||
int d0, d1;
|
||||
register int __res;
|
||||
__asm__ __volatile__(
|
||||
"1:\tlodsb\n\t"
|
||||
"scasb\n\t"
|
||||
"jne 2f\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"jne 1b\n\t"
|
||||
"xorl %%eax,%%eax\n\t"
|
||||
"jmp 3f\n"
|
||||
"2:\tsbbl %%eax,%%eax\n\t"
|
||||
"orb $1,%%al\n"
|
||||
"3:"
|
||||
: "=a"(__res), "=&S"(d0), "=&D"(d1)
|
||||
: "1"(s1), "2"(s2));
|
||||
return __res;
|
||||
}
|
||||
|
@@ -1,13 +1,7 @@
|
||||
/* strcoll( const char *, const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int strcoll( const char * s1, const char * s2 )
|
||||
{
|
||||
/* FIXME: This should access _PDCLIB_lc_collate. */
|
||||
return strcmp( s1, s2 );
|
||||
}
|
||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <string.h>
|
||||
|
||||
int strcoll(const char* s1, const char* s2)
|
||||
{
|
||||
return strcmp(s1, s2);
|
||||
}
|
||||
|
@@ -1,19 +1,16 @@
|
||||
/* strcpy( char *, const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char * strcpy( char * s1, const char * s2 )
|
||||
{
|
||||
char * rc = s1;
|
||||
|
||||
while ( ( *s1++ = *s2++ ) )
|
||||
{
|
||||
/* EMPTY */
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <string.h>
|
||||
|
||||
char* strcpy(char* to, const char* from)
|
||||
{
|
||||
int d0, d1, d2;
|
||||
__asm__ __volatile__(
|
||||
"1:\tlodsb\n\t"
|
||||
"stosb\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"jne 1b"
|
||||
: "=&S"(d0), "=&D"(d1), "=&a"(d2)
|
||||
: "0"(from), "1"(to)
|
||||
: "memory");
|
||||
return to;
|
||||
}
|
||||
|
@@ -1,30 +1,17 @@
|
||||
/* strcspn( const char *, const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t strcspn( const char * s1, const char * s2 )
|
||||
{
|
||||
size_t len = 0;
|
||||
const char * p;
|
||||
|
||||
while ( s1[len] )
|
||||
{
|
||||
p = s2;
|
||||
|
||||
while ( *p )
|
||||
{
|
||||
if ( s1[len] == *p++ )
|
||||
{
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
++len;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <string.h>
|
||||
|
||||
size_t strcspn(const char* s1, const char* s2)
|
||||
{
|
||||
const char *p, *spanp;
|
||||
char c, sc;
|
||||
|
||||
for (p = s1;;) {
|
||||
c = *p++;
|
||||
spanp = s2;
|
||||
do {
|
||||
if ((sc = *spanp++) == c)
|
||||
return p - 1 - s1;
|
||||
} while (sc != 0);
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char* strdup(const char *str)
|
||||
char* strdup(const char* str)
|
||||
{
|
||||
char *buf = malloc(strlen(str) + 1);
|
||||
char* buf = malloc(strlen(str) + 1);
|
||||
buf[strlen(str)] = '\0';
|
||||
strcpy(buf, str);
|
||||
return buf;
|
||||
|
@@ -3,66 +3,34 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
int _errno;
|
||||
int __errno;
|
||||
|
||||
char* strerror(int err)
|
||||
{
|
||||
char *msg;
|
||||
switch(err){
|
||||
case 0: msg = "No errors"; break;
|
||||
case EPERM: msg = "Operation not permitted"; break;
|
||||
case ENOENT: msg = "No such file or directory"; break;
|
||||
case ESRCH: msg = "No such process"; break;
|
||||
case EINTR: msg = "Interrupted system call"; break;
|
||||
case EIO: msg = "Input/output error"; break;
|
||||
case ENXIO: msg = "Device not configured"; break;
|
||||
case E2BIG: msg = "Argument list too long"; break;
|
||||
case ENOEXEC: msg = "Exec format error"; break;
|
||||
case EBADF: msg = "Bad file descriptor"; break;
|
||||
case ECHILD: msg = "No child processes"; break;
|
||||
case EDEADLK: msg = "Resource deadlock avoided"; break;
|
||||
case ENOMEM: msg = "Cannot allocate memory"; break;
|
||||
case EACCES: msg = "Permission denied"; break;
|
||||
case EFAULT: msg = "Bad address"; break;
|
||||
case ENOTBLK: msg = "Block device required"; break;
|
||||
case EBUSY: msg = "Device / Resource busy"; break;
|
||||
case EEXIST: msg = "File exists"; break;
|
||||
case EXDEV: msg = "Cross-device link"; break;
|
||||
case ENODEV: msg = "Operation not supported by device"; break;
|
||||
case ENOTDIR: msg = "Not a directory"; break;
|
||||
case EISDIR: msg = "Is a directory"; break;
|
||||
case EINVAL: msg = "Invalid argument"; break;
|
||||
case ENFILE: msg = "Too many open files in system"; break;
|
||||
case EMFILE: msg = "Too many open files"; break;
|
||||
case ENOTTY: msg = "Inappropriate ioctl for device"; break;
|
||||
case ETXTBSY: msg = "Text file busy"; break;
|
||||
case EFBIG: msg = "File too large"; break;
|
||||
case ENOSPC: msg = "No space left on device"; break;
|
||||
case ESPIPE: msg = "Illegal seek"; break;
|
||||
case EROFS: msg = "Read-only file system"; break;
|
||||
case EMLINK: msg = "Too many links"; break;
|
||||
case EPIPE: msg = "Broken pipe"; break;
|
||||
|
||||
// math software
|
||||
case ENOTSUP: msg = "Function is not supported"; break;
|
||||
case EUNKNFS: msg = "Unknown file system"; break;
|
||||
case ENOTFOUND: msg = "File not found"; break;
|
||||
case EEOF: msg = "End of file"; break;
|
||||
case EFAULT: msg = "Bad address"; break;
|
||||
case EDQUOT: msg = "Disc quota exceeded"; break;
|
||||
case EFS: msg = "File system error"; break;
|
||||
case EACCES: msg = "Permission denied"; break;
|
||||
case EDEV: msg = "Device error"; break;
|
||||
case ENOMEMFS: msg = "File system requires more memory"; break;
|
||||
|
||||
case ENOMEM: msg = "Not enough memory"; break;
|
||||
case ENOEXEC: msg = "Exec format error"; break;
|
||||
case EPROCLIM: msg = "Too many processes"; break;
|
||||
case EINVAL: msg = "Invalid argument"; break;
|
||||
|
||||
case EDOM: msg = "Numerical argument out of domain"; break;
|
||||
case ERANGE: msg = "Result too large"; break;
|
||||
|
||||
// should be rearranged
|
||||
case EHOSTDOWN: msg = "Host is down"; break;
|
||||
case EHOSTUNREACH: msg = "No route to host"; break;
|
||||
case ENOTEMPTY: msg = "Directory not empty"; break;
|
||||
|
||||
// quotas & mush
|
||||
case EPROCLIM: msg = "Too many processes"; break;
|
||||
case EUSERS: msg = "Too many users"; break;
|
||||
case EDQUOT: msg = "Disc quota exceeded"; break;
|
||||
|
||||
// Intelligent device errors
|
||||
case EPWROFF: msg = "Device power is off"; break;
|
||||
case EDEVERR: msg = "Device error, e.g. paper out"; break;
|
||||
case EOVERFLOW: msg = "Value too large to be stored in data type"; break;
|
||||
|
||||
// Socket errors
|
||||
case EILSEQ: msg = "Illegal byte sequence"; break;
|
||||
|
||||
case ENOBUFS: msg = "Broken buffer"; break;
|
||||
case EINPROGRESS: msg = "Operation now in progress"; break;
|
||||
case EOPNOTSUPP: msg = "Operation not supported on transport endpoint"; break;
|
||||
|
@@ -1,19 +1,16 @@
|
||||
/* strlen( const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t strlen( const char * s )
|
||||
{
|
||||
size_t rc = 0;
|
||||
|
||||
while ( s[rc] )
|
||||
{
|
||||
++rc;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <string.h>
|
||||
|
||||
size_t strlen(const char* str)
|
||||
{
|
||||
int d0;
|
||||
register int __res;
|
||||
__asm__ __volatile__(
|
||||
"repne\n\t"
|
||||
"scasb\n\t"
|
||||
"notl %0\n\t"
|
||||
"decl %0"
|
||||
: "=c"(__res), "=&D"(d0)
|
||||
: "1"(str), "a"(0), "0"(0xffffffff));
|
||||
return __res;
|
||||
}
|
||||
|
@@ -1,29 +1,23 @@
|
||||
/* strncat( char *, const char *, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char * strncat( char * s1, const char * s2, size_t n )
|
||||
{
|
||||
char * rc = s1;
|
||||
|
||||
while ( *s1 )
|
||||
{
|
||||
++s1;
|
||||
}
|
||||
|
||||
while ( n && ( *s1++ = *s2++ ) )
|
||||
{
|
||||
--n;
|
||||
}
|
||||
|
||||
if ( n == 0 )
|
||||
{
|
||||
*s1 = '\0';
|
||||
}
|
||||
|
||||
return rc;
|
||||
#include <string.h>
|
||||
|
||||
char* strncat(char* dst, const char* src, size_t n)
|
||||
{
|
||||
int d0, d1, d2, d3;
|
||||
__asm__ __volatile__(
|
||||
"repne\n\t"
|
||||
"scasb\n\t"
|
||||
"decl %1\n\t"
|
||||
"movl %8,%3\n"
|
||||
"1:\tdecl %3\n\t"
|
||||
"js 2f\n\t"
|
||||
"lodsb\n\t"
|
||||
"stosb\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"jne 1b\n"
|
||||
"2:\txorl %2,%2\n\t"
|
||||
"stosb"
|
||||
: "=&S"(d0), "=&D"(d1), "=&a"(d2), "=&c"(d3)
|
||||
: "0"(src), "1"(dst), "2"(0), "3"(0xffffffff), "g"(n)
|
||||
: "memory");
|
||||
return dst;
|
||||
}
|
@@ -1,26 +1,24 @@
|
||||
/* strncmp( const char *, const char *, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int strncmp( const char * s1, const char * s2, size_t n )
|
||||
{
|
||||
while ( n && *s1 && ( *s1 == *s2 ) )
|
||||
{
|
||||
++s1;
|
||||
++s2;
|
||||
--n;
|
||||
}
|
||||
|
||||
if ( n == 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ( *( unsigned char * )s1 - * ( unsigned char * )s2 );
|
||||
}
|
||||
}
|
||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <string.h>
|
||||
|
||||
int strncmp(const char* s1, const char* s2, size_t n)
|
||||
{
|
||||
register int __res;
|
||||
int d0, d1, d2;
|
||||
__asm__ __volatile__(
|
||||
"1:\tdecl %3\n\t"
|
||||
"js 2f\n\t"
|
||||
"lodsb\n\t"
|
||||
"scasb\n\t"
|
||||
"jne 3f\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"jne 1b\n"
|
||||
"2:\txorl %%eax,%%eax\n\t"
|
||||
"jmp 4f\n"
|
||||
"3:\tsbbl %%eax,%%eax\n\t"
|
||||
"orb $1,%%al\n"
|
||||
"4:"
|
||||
: "=a"(__res), "=&S"(d0), "=&D"(d1), "=&c"(d2)
|
||||
: "1"(s1), "2"(s2), "3"(n));
|
||||
return __res;
|
||||
}
|
||||
|
@@ -1,29 +1,21 @@
|
||||
/* strncpy( char *, const char *, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char * strncpy( char * s1, const char * s2, size_t n )
|
||||
{
|
||||
char * rc = s1;
|
||||
|
||||
while ( n && ( *s1++ = *s2++ ) )
|
||||
{
|
||||
/* Cannot do "n--" in the conditional as size_t is unsigned and we have
|
||||
to check it again for >0 in the next loop below, so we must not risk
|
||||
underflow.
|
||||
*/
|
||||
--n;
|
||||
}
|
||||
|
||||
/* Checking against 1 as we missed the last --n in the loop above. */
|
||||
while ( n-- > 1 )
|
||||
{
|
||||
*s1++ = '\0';
|
||||
}
|
||||
|
||||
return rc;
|
||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <string.h>
|
||||
|
||||
char* strncpy(char* dst, const char* src, size_t n)
|
||||
{
|
||||
int d0, d1, d2, d3;
|
||||
__asm__ __volatile__(
|
||||
"1:\tdecl %2\n\t"
|
||||
"js 2f\n\t"
|
||||
"lodsb\n\t"
|
||||
"stosb\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"jne 1b\n\t"
|
||||
"rep\n\t"
|
||||
"stosb\n"
|
||||
"2:"
|
||||
: "=&S"(d0), "=&D"(d1), "=&c"(d2), "=&a"(d3)
|
||||
: "0"(src), "1"(dst), "2"(n)
|
||||
: "memory");
|
||||
return dst;
|
||||
}
|
@@ -1,30 +1,16 @@
|
||||
/* strpbrk( const char *, const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char * strpbrk( const char * s1, const char * s2 )
|
||||
{
|
||||
const char * p1 = s1;
|
||||
const char * p2;
|
||||
|
||||
while ( *p1 )
|
||||
{
|
||||
p2 = s2;
|
||||
|
||||
while ( *p2 )
|
||||
{
|
||||
if ( *p1 == *p2++ )
|
||||
{
|
||||
return ( char * ) p1;
|
||||
}
|
||||
}
|
||||
|
||||
++p1;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include "unconst.h"
|
||||
#include <string.h>
|
||||
|
||||
char* strpbrk(const char* s1, const char* s2)
|
||||
{
|
||||
const char* scanp;
|
||||
int c, sc;
|
||||
|
||||
while ((c = *s1++) != 0) {
|
||||
for (scanp = s2; (sc = *scanp++) != 0;)
|
||||
if (sc == c)
|
||||
return unconst(s1 - 1, char*);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,27 +1,18 @@
|
||||
/* strrchr( const char *, int )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char * strrchr( const char * s, int c )
|
||||
{
|
||||
size_t i = 0;
|
||||
|
||||
while ( s[i++] )
|
||||
{
|
||||
/* EMPTY */
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if ( s[--i] == ( char ) c )
|
||||
{
|
||||
return ( char * ) s + i;
|
||||
}
|
||||
} while ( i );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
|
||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include "unconst.h"
|
||||
#include <string.h>
|
||||
|
||||
char* strrchr(const char* s, int c)
|
||||
{
|
||||
char cc = c;
|
||||
const char* sp = (char*)0;
|
||||
while (*s) {
|
||||
if (*s == cc)
|
||||
sp = s;
|
||||
s++;
|
||||
}
|
||||
if (cc == 0)
|
||||
sp = s;
|
||||
return unconst(sp, char*);
|
||||
}
|
||||
|
@@ -1,37 +1,15 @@
|
||||
/* strspn( const char *, const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t strspn( const char * s1, const char * s2 )
|
||||
{
|
||||
size_t len = 0;
|
||||
const char * p;
|
||||
|
||||
while ( s1[ len ] )
|
||||
{
|
||||
p = s2;
|
||||
|
||||
while ( *p )
|
||||
{
|
||||
if ( s1[len] == *p )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
++p;
|
||||
}
|
||||
|
||||
if ( ! *p )
|
||||
{
|
||||
return len;
|
||||
}
|
||||
|
||||
++len;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <string.h>
|
||||
|
||||
size_t strspn(const char* s1, const char* s2)
|
||||
{
|
||||
const char *p = s1, *spanp;
|
||||
char c, sc;
|
||||
|
||||
cont:
|
||||
c = *p++;
|
||||
for (spanp = s2; (sc = *spanp++) != 0;)
|
||||
if (sc == c)
|
||||
goto cont;
|
||||
return (p - 1 - s1);
|
||||
}
|
||||
|
@@ -1,34 +1,21 @@
|
||||
/* strstr( const char *, const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char * strstr( const char * s1, const char * s2 )
|
||||
{
|
||||
const char * p1 = s1;
|
||||
const char * p2;
|
||||
|
||||
while ( *s1 )
|
||||
{
|
||||
p2 = s2;
|
||||
|
||||
while ( *p2 && ( *p1 == *p2 ) )
|
||||
{
|
||||
++p1;
|
||||
++p2;
|
||||
}
|
||||
|
||||
if ( ! *p2 )
|
||||
{
|
||||
return ( char * ) s1;
|
||||
}
|
||||
|
||||
++s1;
|
||||
p1 = s1;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include "unconst.h"
|
||||
#include <string.h>
|
||||
|
||||
char* strstr(const char* s, const char* find)
|
||||
{
|
||||
char c, sc;
|
||||
size_t len;
|
||||
|
||||
if ((c = *find++) != 0) {
|
||||
len = strlen(find);
|
||||
do {
|
||||
do {
|
||||
if ((sc = *s++) == 0)
|
||||
return 0;
|
||||
} while (sc != c);
|
||||
} while (strncmp(s, find, len) != 0);
|
||||
s--;
|
||||
}
|
||||
return unconst(s, char*);
|
||||
}
|
||||
|
@@ -1,30 +1,49 @@
|
||||
/* strtok( char *, const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char* strtok(char* s, const char* delim)
|
||||
{
|
||||
static char* savep;
|
||||
char* res;
|
||||
|
||||
if(s)
|
||||
savep = NULL;
|
||||
else
|
||||
s = savep;
|
||||
|
||||
if (*s == '\0')
|
||||
return NULL;
|
||||
s += strspn(s, delim);
|
||||
if (*s == '\0')
|
||||
return NULL;
|
||||
res = s;
|
||||
s += strcspn(s, delim);
|
||||
savep = s + 1;
|
||||
*s = '\0';
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <string.h>
|
||||
|
||||
char* strtok(char* s, const char* delim)
|
||||
{
|
||||
const char* spanp;
|
||||
int c, sc;
|
||||
char* tok;
|
||||
static char* last;
|
||||
|
||||
if (s == NULL && (s = last) == NULL)
|
||||
return (NULL);
|
||||
|
||||
/*
|
||||
* Skip (span) leading delimiters (s += strspn(s, delim), sort of).
|
||||
*/
|
||||
cont:
|
||||
c = *s++;
|
||||
for (spanp = delim; (sc = *spanp++) != 0;) {
|
||||
if (c == sc)
|
||||
goto cont;
|
||||
}
|
||||
|
||||
if (c == 0) { /* no non-delimiter characters */
|
||||
last = NULL;
|
||||
return (NULL);
|
||||
}
|
||||
tok = s - 1;
|
||||
|
||||
/*
|
||||
* Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
|
||||
* Note that delim must have one NUL; we stop if we see that, too.
|
||||
*/
|
||||
for (;;) {
|
||||
c = *s++;
|
||||
spanp = delim;
|
||||
do {
|
||||
if ((sc = *spanp++) == c) {
|
||||
if (c == 0)
|
||||
s = NULL;
|
||||
else
|
||||
s[-1] = 0;
|
||||
last = s;
|
||||
return (tok);
|
||||
}
|
||||
} while (sc != 0);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
@@ -1,26 +1,22 @@
|
||||
/* strxfrm( char *, const char *, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t strxfrm( char * s1, const char * s2, size_t n )
|
||||
{
|
||||
size_t len = strlen( s2 );
|
||||
|
||||
if ( len < n )
|
||||
{
|
||||
/* Cannot use strncpy() here as the filling of s1 with '\0' is not part
|
||||
of the spec.
|
||||
*/
|
||||
/* FIXME: This should access _PDCLIB_lc_collate. */
|
||||
while ( n-- && ( *s1++ = ( unsigned char )*s2++ ) )
|
||||
{
|
||||
/* EMPTY */
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <string.h>
|
||||
|
||||
size_t strxfrm(char* dst, const char* src, size_t n)
|
||||
{
|
||||
size_t r = 0;
|
||||
int c;
|
||||
|
||||
if (n != 0) {
|
||||
while ((c = *src++) != 0) {
|
||||
r++;
|
||||
if (--n == 0) {
|
||||
while (*src++ != 0)
|
||||
r++;
|
||||
break;
|
||||
}
|
||||
*dst++ = c;
|
||||
}
|
||||
*dst = 0;
|
||||
}
|
||||
return r;
|
||||
}
|
8
programs/develop/ktcc/trunk/libc.obj/source/string/unconst.h
Executable file
8
programs/develop/ktcc/trunk/libc.obj/source/string/unconst.h
Executable file
@@ -0,0 +1,8 @@
|
||||
#ifndef _UNCONST_H_
|
||||
#define _UNCONST_H_
|
||||
|
||||
#ifndef unconst
|
||||
#define unconst(__v, __t) __extension__ ({union { const __t __cp; __t __p; } __q; __q.__cp = __v; __q.__p;})
|
||||
#endif
|
||||
|
||||
#endif // _UNCONST_H_
|
Reference in New Issue
Block a user