X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f Date: Thu, 20 Jan 2005 05:13:28 -0700 From: Brian Inglis Subject: Re: strtok_r() patch In-reply-to: <200501031642.j03GgKJ9026830@speedy.ludd.ltu.se> To: djgpp-workers AT delorie DOT com Message-id: Organization: Systematic Software MIME-version: 1.0 X-Mailer: Forte Agent 1.93/32.576 English (American) Content-type: text/plain; charset=us-ascii References: <200501031642 DOT j03GgKJ9026830 AT speedy DOT ludd DOT ltu DOT se> Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id j0KCDUvx032497 Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk 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 > #include > > 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 >+#include >+ >+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