Mail Archives: djgpp-workers/2005/01/20/07:13:36
On Mon, 03 Jan 2005 17:42:20 +0100 (CET), ams AT ludd DOT ltu DOT se wrote:
>Hello.
>
>Here's my patch that adds strtok_r(). There will be some fuzz if somebody
>tries to apply it as I've had to remove some lines containing other changes.
It looks like your first patch to strtok.c was applied/committed,
looking as I have edited it below, but the second was not, when I did
an update and make.
As a result, go32-v2 failed to link (calls strtok which now calls
strtok_r).
These two might be better as one atomic patch.
>Index: djgpp/src/libc/ansi/string/strtok.c
>===================================================================
>RCS file: /cvs/djgpp/djgpp/src/libc/ansi/string/strtok.c,v
>retrieving revision 1.1
>diff -p -u -r1.1 strtok.c
>--- djgpp/src/libc/ansi/string/strtok.c 29 Nov 1994 09:40:46 -0000 1.1
>+++ djgpp/src/libc/ansi/string/strtok.c 3 Jan 2005 16:28:47 -0000
>@@ -1,51 +1,12 @@
>+/* Copyright (C) 2005 DJ Delorie, see COPYING.DJ for details */
> /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
>+#include <libc/stubs.h>
> #include <string.h>
>
> char *
> strtok(char *s, const char *delim)
> {
...
>+ return strtok_r(s, delim, &last);
> }
>Index: djgpp/src/libc/posix/string/strtok_r.c
>===================================================================
>RCS file: djgpp/src/libc/posix/string/strtok_r.c
>diff -N djgpp/src/libc/posix/string/strtok_r.c
>--- /dev/null 1 Jan 1970 00:00:00 -0000
>+++ djgpp/src/libc/posix/string/strtok_r.c 3 Jan 2005 16:28:59 -0000
>@@ -0,0 +1,51 @@
>+/* Copyright (C) 2005 DJ Delorie, see COPYING.DJ for details */
>+/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
>+#include <libc/stubs.h>
>+#include <string.h>
>+
>+char *
>+strtok_r(char *s, const char *delim, char **last)
>+{
>+ const char *spanp;
>+ int c, sc;
>+ char *tok;
>+
>+ if (s == NULL && (s = *last) == NULL)
>+ return (NULL);
>+
>+ /*
>+ * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
>+ */
>+ cont:
>+ c = *s++;
>+ for (spanp = delim; (sc = *spanp++) != 0;) {
>+ if (c == sc)
>+ goto cont;
>+ }
>+
>+ if (c == 0) { /* no non-delimiter characters */
>+ *last = NULL;
>+ return (NULL);
>+ }
>+ tok = s - 1;
>+
>+ /*
>+ * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
>+ * Note that delim must have one NUL; we stop if we see that, too.
>+ */
>+ for (;;) {
>+ c = *s++;
>+ spanp = delim;
>+ do {
>+ if ((sc = *spanp++) == c) {
>+ if (c == 0)
>+ s = NULL;
>+ else
>+ s[-1] = 0;
>+ *last = s;
>+ return (tok);
>+ }
>+ } while (sc != 0);
>+ }
>+ /* NOTREACHED */
>+}
--
Thanks. Take care, Brian Inglis
- Raw text -