> From: "Todd C. Miller" <todd.mil...@courtesan.com> > Date: Fri, 19 Jun 2015 09:11:21 -0600 > > There's no reason to cast delim to char * when we can just make > spanp const char * to match it.
Fewer casts is good. Not sure I agree with the s/0/'\0'/, but that's merely a matter of taste. ok kettenis@ > Index: lib/libc/string/strtok.c > =================================================================== > RCS file: /cvs/src/lib/libc/string/strtok.c,v > retrieving revision 1.6 > diff -u -p -u -r1.6 strtok.c > --- lib/libc/string/strtok.c 8 Aug 2005 08:05:37 -0000 1.6 > +++ lib/libc/string/strtok.c 19 Jun 2015 15:09:13 -0000 > @@ -40,11 +40,10 @@ strtok(char *s, const char *delim) > char * > strtok_r(char *s, const char *delim, char **last) > { > - char *spanp; > + const char *spanp; > int c, sc; > char *tok; > > - > if (s == NULL && (s = *last) == NULL) > return (NULL); > > @@ -53,7 +52,7 @@ strtok_r(char *s, const char *delim, cha > */ > cont: > c = *s++; > - for (spanp = (char *)delim; (sc = *spanp++) != 0;) { > + for (spanp = delim; (sc = *spanp++) != 0;) { > if (c == sc) > goto cont; > } > @@ -70,13 +69,13 @@ cont: > */ > for (;;) { > c = *s++; > - spanp = (char *)delim; > + spanp = delim; > do { > if ((sc = *spanp++) == c) { > if (c == 0) > s = NULL; > else > - s[-1] = 0; > + s[-1] = '\0'; > *last = s; > return (tok); > } > >