* strsep final separator handling
@ 2020-09-08 15:51 Allen, Richard
0 siblings, 0 replies; only message in thread
From: Allen, Richard @ 2020-09-08 15:51 UTC (permalink / raw)
To: newlib
Hello,
I think I have identified a small difference between newlib strsep
and GNU/BSD strsep's handling of separators at the end of a string.
GNU and BSD strsep will return a pointer to the null terminating
character when asked to process a separator ending immediately before
a null-termination character. newlib strsep seems to return NULL instead.
Similarly, when presented with an empty string, GNU and BSD strsep will
return a pointer to the null terminating character, but newlib strsep
will return NULL.
I found this on _NEWLIB_VERSION "2.2.0" built for ARMv7-AR, but
I do not believe the implementation has changed since then when
comparing to the master branch in git.
Here is a short example program that prints Found: three times
when using GNU/BSD strsep, but only twice using newlib strsep:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TEST_STRING ",,"
#define DELIM ","
int main()
{
char * str = strdup(TEST_STRING);
char * found;
char * strwalker = str;
while( (found = strsep(&strwalker,DELIM)) != NULL )
{
printf("Found:%s\n",found);
}
free(str);
}
-Richard
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-09-08 15:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-08 15:51 strsep final separator handling Allen, Richard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).