strsep final separator handling
Allen, Richard
Richard.Allen@garmin.com
Tue Sep 8 15:51:27 GMT 2020
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
More information about the Newlib
mailing list