This commit is contained in:
elvis
2022-04-17 23:50:38 +02:00
parent 5642ad4906
commit 3bf2a13e89
3 changed files with 41 additions and 26 deletions

View File

@ -17,20 +17,26 @@
char *
strsep_gnu (char **stringp, const char *delim)
{
char *begin, *end;
begin = *stringp;
if (begin == NULL)
return NULL;
/* Find the end of the token. */
end = begin + strcspn (begin, delim);
if (*end)
#if defined(__APPLE__) || defined(__FreeBSD__)
return strsep(stringp, delim);
#endif /* __APPLE__ or __FreeBSD__ */
#if defined(__linux__)
char *begin, *end;
begin = *stringp;
if (begin == NULL)
return NULL;
/* Find the end of the token. */
end = begin + strcspn (begin, delim);
if (*end)
{
/* Terminate the token and set *STRINGP past NUL character. */
*end++ = '\0';
*stringp = end;
/* Terminate the token and set *STRINGP past NUL character. */
*end++ = '\0';
*stringp = end;
}
else
/* No more delimiters; this is the last token. */
*stringp = NULL;
return begin;
else
/* No more delimiters; this is the last token. */
*stringp = NULL;
return begin;
#endif /* __linux__ */
}