Add: argument handling & PoC: echo command

This commit is contained in:
xamidev
2024-08-09 11:49:47 +02:00
parent 3524fdc760
commit f3b30bbb9a
7 changed files with 97 additions and 8 deletions

View File

@@ -17,4 +17,6 @@ typedef uint8_t bool;
#define true 1
#define false 0
#define NULL ((void*)0)
#endif

View File

@@ -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;
}

View File

@@ -3,5 +3,6 @@
int strlen(const char* str);
int strcmp(const char* str1, const char* str2);
char* strtok(char* str, const char* delimiter);
#endif