Espresso 0.0.1a
This commit is contained in:
80
lib/string.c
80
lib/string.c
@ -1,6 +1,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <vector_extentions/sse.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <vector_extentions/sse.h>
|
||||
|
||||
extern int16_t sse_initialized;
|
||||
|
||||
@ -77,6 +79,82 @@ void strcat(char *dest, const char *src)
|
||||
*end = '\0';
|
||||
}
|
||||
|
||||
char* strdup(const char* s)
|
||||
{
|
||||
if (!s)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t len = strlen(s);
|
||||
char* copy = (char*)malloc(len + 1);
|
||||
|
||||
if (!copy)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(copy, s, len);
|
||||
copy[len] = '\0';
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
char* strtok(char* str, const char* delim)
|
||||
{
|
||||
static char* next_token = NULL;
|
||||
|
||||
if (str != NULL)
|
||||
{
|
||||
next_token = str;
|
||||
}
|
||||
else if (next_token == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (*next_token && strchr(delim, *next_token))
|
||||
{
|
||||
next_token++;
|
||||
}
|
||||
|
||||
if (*next_token == '\0')
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* token_start = next_token;
|
||||
|
||||
while (*next_token && !strchr(delim, *next_token))
|
||||
{
|
||||
next_token++;
|
||||
}
|
||||
|
||||
if (*next_token)
|
||||
{
|
||||
*next_token = '\0';
|
||||
next_token++;
|
||||
}
|
||||
|
||||
return token_start;
|
||||
}
|
||||
|
||||
char* strchr(const char* s, int c)
|
||||
{
|
||||
while (*s)
|
||||
{
|
||||
if (*s == (char)c)
|
||||
{
|
||||
return (char*)s;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void *memset(void *dst, char c, uint32_t n)
|
||||
{
|
||||
char *temp = dst;
|
||||
|
Reference in New Issue
Block a user