lkml.org 
[lkml]   [1999]   [Jun]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subjectstrsep() instead of strtok()
Hi there,

I've implemented strsep() for use in kernel.

Reasons:
- strsep() is reentrant instead of strtok() which need an
global variable (___strtok)

- strsep() is a bit faster, because you need not copy the
variable "send" -> "___strtok" every time you use it, and
you need no global protection for the "___strtok" variable

If this patch is accepted (within two weeks) I'm going to change
every occourance of "strtok()" to "strsep()" with every needed
implication.

There seem to be no point for using strtok() any longer for me.

Regards

Ingo Oeser
--
Feel the power of the penguin - run linux@your.pc
<esc>:x
--- /usr/src/linux-2.2.9/lib/string.c Sun Sep 6 20:19:15 1998
+++ /usr/src/linux/lib/string.c Fri Jun 25 15:01:43 1999
@@ -9,6 +9,10 @@
* as inline code in <asm-xx/string.h>
*
* These are buggy as well..
+ *
+ * * Fri Jun 25 1999, Ingo Oeser <ioe@informatik.tu-chemnitz.de>
+ * - Added strsep() which will replace strtok() soon (because strsep() is
+ * reentrant and should be faster). Use only strsep() in new code, please.
*/

#include <linux/types.h>
@@ -228,6 +232,25 @@
if (send && *send != '\0')
*send++ = '\0';
___strtok = send;
+ return (sbegin);
+}
+#endif
+
+#ifndef __HAVE_ARCH_STRSEP
+
+char * strsep(char **s, const char * ct)
+{
+ char *sbegin=*s;
+ if (!sbegin)
+ return NULL;
+
+ sbegin += strspn(sbegin,ct);
+ if (*sbegin == '\0')
+ return NULL;
+
+ *s = strpbrk( sbegin, ct);
+ if (*s && **s != '\0')
+ **s++ = '\0';
return (sbegin);
}
#endif
--- /usr/src/linux-2.2.9/include/linux/string.h Fri Apr 23 18:36:09 1999
+++ /usr/src/linux/include/linux/string.h Fri Jun 25 20:51:36 1999
@@ -20,6 +20,7 @@
extern char * strrchr(const char *,int);
extern char * strpbrk(const char *,const char *);
extern char * strtok(char *,const char *);
+extern char * strsep(char **,const char *);
extern char * strstr(const char *,const char *);
extern __kernel_size_t strlen(const char *);
extern __kernel_size_t strnlen(const char *,__kernel_size_t);
\
 
 \ /
  Last update: 2005-03-22 13:52    [W:2.455 / U:0.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site