blob: aed8b929b6eb8fcf4c866fdbb1518298e3e15cb2 [file] [log] [blame]
/*
* linux/lib/string.c
*
* Copyright (C) 1991, 1992 Linus Torvalds
*/
/*
* stupid library routines.. The optimized versions should generally be found
* as inline code in <asm-xx/string.h>
*
* These are buggy as well..
*
* * Fri Jun 25 1999, Ingo Oeser <ioe@informatik.tu-chemnitz.de>
* - Added strsep() which will replace strtok() soon (because strsep() is
* reentrant and should be faster). Use only strsep() in new code, please.
*/
#include <linux/types.h>
#include <asm/string.h>
//#include <malloc.h>
/*
******************************************************************************
* Function:
* Description:
* Parameters:
* Input:
* Output:
* Returns:
* Others:
*******************************************************************************
*/
uint32_t strlen( uint8_t* s )
{
uint8_t *sc;
for (sc = s; *sc != '\0'; ++sc)
/* nothing */;
return sc - s;
}
/*
******************************************************************************
* Function:
* Description:
* Parameters:
* Input:
* Output:
* Returns:
* Others:
*******************************************************************************
*/
void * memset(void * s,int c,size_t count)
{
unsigned long *sl = (unsigned long *) s;
unsigned long cl = 0;
char *s8;
int i;
/* do it one word at a time (32 bits or 64 bits) while possible */
if ( ((ulong)s & (sizeof(*sl) - 1)) == 0) {
for (i = 0; i < sizeof(*sl); i++) {
cl <<= 8;
cl |= c & 0xff;
}
while (count >= sizeof(*sl)) {
*sl++ = cl;
count -= sizeof(*sl);
}
}
/* fill 8 bits at a time */
s8 = (char *)sl;
while (count--)
*s8++ = c;
return s;
}
/*
******************************************************************************
* Function:
* Description:
* Parameters:
* Input:
* Output:
* Returns:
* Others:
*******************************************************************************
*/
int memcmp(void *a, void *c, int n)
{
int i;
for (i = 0; i < n; i++) {
if (((unsigned char *)c)[i] != ((unsigned char *)a)[i])
return 1;
}
return 0;
}
/*
******************************************************************************
* Function:
* Description:
* Parameters:
* Input:
* Output:
* Returns:
* Others:
*******************************************************************************
*/
void memcpy( uint32_t dest, uint32_t src, uint32_t count )
{
char *tmp = (char *) dest, *s = (char *) src;
while (count--)
*tmp++ = *s++;
}