strsep final separator handling

"Allen, Richard via Newlib" <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.