libroot/posix: Replace strtok_r with musl's.
And rewrite/cleanup strtok.c also.
This commit is contained in:
@@ -27,6 +27,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
strpbrk.c
|
||||
strspn.c
|
||||
strstr.c
|
||||
strtok_r.c
|
||||
swab.c
|
||||
;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#include <string.h>
|
||||
|
||||
char *strtok_r(char *restrict s, const char *restrict sep, char **restrict p)
|
||||
{
|
||||
if (!s && !(s = *p)) return NULL;
|
||||
s += strspn(s, sep);
|
||||
if (!*s) return *p = 0;
|
||||
*p = s + strcspn(s, sep);
|
||||
if (**p) *(*p)++ = 0;
|
||||
else *p = 0;
|
||||
return s;
|
||||
}
|
||||
@@ -1,48 +1,14 @@
|
||||
/*
|
||||
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
|
||||
** Distributed under the terms of the NewOS License.
|
||||
*/
|
||||
* Copyright 2026, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
static char *___strtok = NULL;
|
||||
|
||||
|
||||
char *
|
||||
strtok_r(char *s, char const *ct, char **save_ptr)
|
||||
char*
|
||||
strtok(char* str, char const* sep)
|
||||
{
|
||||
char *sbegin, *send;
|
||||
|
||||
if (!s && !save_ptr)
|
||||
return NULL;
|
||||
|
||||
sbegin = s ? s : *save_ptr;
|
||||
if (!sbegin)
|
||||
return NULL;
|
||||
|
||||
sbegin += strspn(sbegin, ct);
|
||||
if (*sbegin == '\0') {
|
||||
if (save_ptr)
|
||||
*save_ptr = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
send = strpbrk(sbegin, ct);
|
||||
if (send && *send != '\0')
|
||||
*send++ = '\0';
|
||||
if (save_ptr)
|
||||
*save_ptr = send;
|
||||
|
||||
return sbegin;
|
||||
static char *p = NULL;
|
||||
return strtok_r(str, sep, &p);
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
strtok(char *s, char const *ct)
|
||||
{
|
||||
return strtok_r(s, ct, &___strtok);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user