size_t strlen( const char *string )
{
const char *s;
s = string;
while ( *s ) {
s++;
}
return s - string;
}
char *strcat( char *strDestination, const char *strSource )
{
char *s;
s = strDestination;
while ( *s ) {
s++;
}
while ( *strSource ) {
*s++ = *strSource++;
}
*s = 0;
return strDestination;
}
char *strcpy( char *strDestination, const char *strSource )
{
char *s;
s = strDestination;
while ( *strSource ) {
*s++ = *strSource++;
}
*s = 0;
return strDestination;
}
int strcmp( const char *string1, const char *string2 )
{
while ( *string1 == *string2 && *string1 && *string2 ) {
string1++;
string2++;
}
return *string1 - *string2;
}
char *strchr( const char *string, int c ) {
while ( *string ) {
if ( *string == c ) {
return ( char * )string;
}
string++;
}
return (char *)0;
}
char *strstr( const char *string, const char *strCharSet )
{
while ( *string ) {
int i;
for ( i = 0 ; strCharSet[i] ; i++ ) {
if ( string[i] != strCharSet[i] ) {
break;
}
}
if ( !strCharSet[i] ) {
return (char *)string;
}
string++;
}
return (char *)0;
}
#if !defined ( _MSC_VER ) && ! defined ( __linux__ ) && ! defined ( MAC_WOLF2_MP )
int tolower( int c )
{
if ( c >= 'A' && c <= 'Z' ) {
c += 'a' - 'A';
}
return c;
}
int toupper( int c )
{
if ( c >= 'a' && c <= 'z' ) {
c += 'A' - 'a';
}
return c;
}
#endif
//#ifndef _MSC_VER
void *memmove( void *dest, const void *src, size_t count )
{
int i;
if ( dest > src ) {
for ( i = count-1 ; i >= 0 ; i-- ) {
((char *)dest)[i] = ((char *)src)[i];
}
} else {
for ( i = 0 ; i < count ; i++ ) {
((char *)dest)[i] = ((char *)src)[i];
}
}
return dest;
}
#if 0
double floor( double x )
{
return (int)(x + 0x40000000) - 0x40000000;
}
void *memset( void *dest, int c, size_t count )
{
while ( count-- ) {
((char *)dest)[count] = c;
}
return dest;
}
void *memcpy( void *dest, const void *src, size_t count )
{
while ( count-- ) {
((char *)dest)[count] = ((char *)src)[count];
}
return dest;
}
char *strncpy( char *strDest, const char *strSource, size_t count )
{
char *s;
s = strDest;
while ( *strSource && count ) {
*s++ = *strSource++;
count--;
}
while ( count-- ) {
*s++ = 0;
}
return strDest;
}
double sqrt( double x )
{
float y;
float delta;
float maxError;
if ( x <= 0 ) {
return 0;
}
// initial guess
y = x / 2;
// refine
maxError = x * 0.001;
do {
delta = ( y * y ) - x;
y -= delta / ( 2 * y );
} while ( delta > maxError || delta < -maxError );
return y;
}
一些库函数的实现
最新推荐文章于 2024-01-18 18:40:57 发布