[LEDE-DEV] [PATCH] ubox: Replace strtok with strsep

Rosen Penev rosenp at gmail.com
Sat Dec 17 17:18:32 PST 2016


Thread safe replacement.

Signed-off by: Rosen Penev <rosenp at gmail.com>
---
 kmodloader.c        | 8 ++++----
 lsbloader.c         | 6 +++---
 validate/validate.c | 2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/kmodloader.c b/kmodloader.c
index f80835a..65e7001 100644
--- a/kmodloader.c
+++ b/kmodloader.c
@@ -255,10 +255,10 @@ static int scan_loaded_modules(void)
 		struct module m;
 		struct module *n;
 
-		m.name = strtok(buf, " ");
-		m.size = atoi(strtok(NULL, " "));
-		m.usage = atoi(strtok(NULL, " "));
-		m.depends = strtok(NULL, " ");
+		m.name = strsep(&buf, " ");
+		m.size = atoi(strsep(&buf " "));
+		m.usage = atoi(strsep(&buf, " "));
+		m.depends = strsep(&buf, " ");
 
 		if (!m.name || !m.depends)
 			continue;
diff --git a/lsbloader.c b/lsbloader.c
index b40a505..af9af3a 100644
--- a/lsbloader.c
+++ b/lsbloader.c
@@ -12,7 +12,7 @@
  *   along with this program; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  *
- *   Copyright (C) 2012 John Crispin <blogic at openwrt.org> 
+ *   Copyright (C) 2012 John Crispin <blogic at openwrt.org>
  */
 
 #include <stdio.h>
@@ -148,10 +148,10 @@ static int init_services(void)
 		instances = blobmsg_open_table(&b, "instances");
 		instance = blobmsg_open_table(&b, "instance");
 		command = blobmsg_open_array(&b, "command");
-		t = strtok(i->exec, " ");
+		t = strsep(&i->exec, " ");
 		while (t) {
 			blobmsg_add_string(&b, NULL, t);
-			t = strtok(NULL, " ");
+			t = strsep(&i->exec, " ");
 		}
 		blobmsg_close_array(&b, command);
 		blobmsg_close_table(&b, instance);
diff --git a/validate/validate.c b/validate/validate.c
index e72b811..e15b886 100644
--- a/validate/validate.c
+++ b/validate/validate.c
@@ -178,7 +178,7 @@ dt_type_list(struct dt_state *s, int nargs)
 		return false;
 	}
 
-	for (p = strtok(str, " \t"); p; p = strtok(NULL, " \t"))
+	for (p = strsep(&str, " \t"); p; p = strsep(&strx, " \t"))
 	{
 		s->value = p;
 
-- 
2.9.3




More information about the Lede-dev mailing list