char *strchr (const char * string, int ch)
{
while (*string && *string != (char)ch)
string++;
if (*string == (char)ch)
return((char *)string);
return(NULL);
}
char * strcpy(char * dst, const char * src)
{
char * cp = dst;
while( *cp++ = *src++ )
; /* Copy src over dst */
return( dst );
}
char *strcat (char * dst,const char * src)
{
char * cp = dst;
while( *cp )
cp++; /* find end of dst */
while( *cp++ = *src++ ) ; /* Copy src to end of dst */
return( dst ); /* return dst */
}
int strcmp (const char * src,const char * dst)
{
int ret = 0 ;
while( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst)
++src, ++dst;
if ( ret < 0 )
ret = -1 ;
else if ( ret > 0 )
ret = 1 ;
return( ret );
}
char * strdup (const char * string)
{
char *memory;
size_t size = 0;
if (!string)
return(NULL);
size = strlen(string) + 1;
if (memory = malloc(size))
{
strcpy(memory, size, string));
return memory;
}
return(NULL);
}
int stricmp (const char * dst,const char * src)
{
int f, l;
do
{
if ( ((f = (unsigned char)(*(dst++))) >= 'A') && (f <= 'Z') )
f -= 'A' - 'a';
if ( ((l = (unsigned char)(*(src++))) >= 'A') && (l <= 'Z') )
l -= 'A' - 'a';
}
while ( f && (f == l) );
return(f - l);
}
size_t strlen (const char * str)
{
const char *eos = str;
while( *eos++ ) ;
return( eos - str - 1 );
}
size_t strnlen(const char *str, size_t maxsize)
{
size_t n;
/* Note that we do not check if s == NULL, because we do not
* return errno_t...
*/
for (n = 0; n < maxsize && *str; n++, str++)
;
return n;
}
char * strlwr (char * string)
{
char * cp;
/* validation section */
for (cp=string; *cp; ++cp)
{
if ('A' <= *cp && *cp <= 'Z')
*cp += 'a' - 'A';
}
return(string);
}
char * strnset (char * string,int val,size_t count)
{
char *start = string;
while (count-- && *string)
*string++ = (char)val;
return(start);
}
int strnicmp (const char * first,const char * last,size_t count)
{
if(count)
{
int f=0;
int l=0;
do
{
if ( ((f = (unsigned char)(*(first++))) >= 'A') &&
(f <= 'Z') )
f -= 'A' - 'a';
if ( ((l = (unsigned char)(*(last++))) >= 'A') &&
(l <= 'Z') )
l -= 'A' - 'a';
}
while ( --count && f && (f == l) );
return ( f - l );
}
else
{
return 0;
}
}
size_t strncnt (const char *string, size_t cnt)
{
size_t n = cnt;
char *cp = (char *)string;
while (n-- && *cp)
cp++;
return cnt - n - 1;
}