Add: argument handling & PoC: echo command
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#include "stdint.h"
|
||||
|
||||
int strlen(const char* str)
|
||||
{
|
||||
int len = 0;
|
||||
@@ -17,3 +19,52 @@ int strcmp(const char* str1, const char* str2)
|
||||
}
|
||||
return *(const unsigned char*)str1 - *(const unsigned char*)str2;
|
||||
}
|
||||
|
||||
char* strchr(const char* str, int c)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
if (*str == (char)c)
|
||||
{
|
||||
return (char*)str;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
if (c == '\0')
|
||||
{
|
||||
return (char*)str;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* strtok(char* str, const char* delimiter)
|
||||
{
|
||||
static char* last;
|
||||
if (str)
|
||||
{
|
||||
last = str;
|
||||
} else {
|
||||
str = last;
|
||||
}
|
||||
|
||||
if (!str || *str == '\0')
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* token_start = str;
|
||||
while (*str && !strchr(delimiter, *str))
|
||||
{
|
||||
str++;
|
||||
}
|
||||
|
||||
if (*str)
|
||||
{
|
||||
*str = '\0';
|
||||
last = str + 1;
|
||||
} else {
|
||||
last = NULL;
|
||||
}
|
||||
|
||||
return token_start;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user