meta: move photon/libc to root

This commit is contained in:
2026-02-08 20:45:25 +00:00
parent f00e74260d
commit 345a37962e
140 changed files with 0 additions and 0 deletions

62
libc/string/strtok.c Normal file
View File

@@ -0,0 +1,62 @@
#include <string.h>
static char *global_sp = NULL;
char *strtok(char *str, const char *delim)
{
return strtok_r(str, delim, &global_sp);
}
char *strtok_r(char *str, const char *delim, char **sp)
{
int i = 0;
int len = strlen(delim);
if (len == 0) {
return NULL;
}
if (!str && !sp) {
return NULL;
}
if (str) {
*sp = str;
}
char *p_start = *sp;
while (1) {
for (i = 0; i < len; i++) {
if (*p_start == delim[i]) {
p_start++;
break;
}
}
if (i == len) {
*sp = p_start;
break;
}
}
if (**sp == '\0') {
*sp = NULL;
return *sp;
}
while (**sp != '\0') {
for (i = 0; i < len; i++) {
if (**sp == delim[i]) {
**sp = '\0';
break;
}
}
(*sp)++;
if (i < len) {
break;
}
}
return p_start;
}