Skip to contentSkip to conversation

strtok --> strsep in filesystem drivers (part 1)

PATCH New René Scharfe 1 participant 1 message Nov 16, 2001

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 strtok --> strsep in filesystem drivers (part 1)

Hello again,

patch below is for making most of the filesystem drivers strtok()-free. Part 2 will consist of some not so boring chunks.

As usual, the patch is untested. It survived a heavy staring-at-it, though. ;) Please, apply.

René

fs/adfs/super.c +3 -1
diff -Nur linux-2.4.15-pre5/fs/adfs/super.c linux-2.4.15-pre5-rs/fs/adfs/super.c
@@ -171,7 +171,9 @@
 	if (!options)
 		return 0;
 
-	for (opt = strtok(options, ","); opt != NULL; opt = strtok(NULL, ",")) {
+	while ((opt = strsep(&options, ",")) != NULL) {
+		if (!*opt)
+			continue;
 		value = strchr(opt, '=');
 		if (value)
 			*value++ = '\0';
fs/affs/super.c +3 -1
diff -Nur linux-2.4.15-pre5/fs/affs/super.c linux-2.4.15-pre5-rs/fs/affs/super.c
@@ -109,7 +109,9 @@
 	*mount_opts = 0;
 	if (!options)
 		return 1;
-	for (this_char = strtok(options,","); this_char; this_char = strtok(NULL,",")) {
+	while ((this_char = strsep(&options, ",")) != NULL) {
+		if (!*this_char)
+			continue;
 		f = 0;
 		if ((value = strchr(this_char,'=')) != NULL)
 			*value++ = 0;
fs/autofs/inode.c +3 -1
diff -Nur linux-2.4.15-pre5/fs/autofs/inode.c linux-2.4.15-pre5-rs/fs/autofs/inode.c
@@ -60,7 +60,9 @@
 	*pipefd = -1;
 
 	if ( !options ) return 1;
-	for (this_char = strtok(options,","); this_char; this_char = strtok(NULL,",")) {
+	while ((this_char = strsep(&options,",")) != NULL) {
+		if (!*this_char)
+			continue;
 		if ((value = strchr(this_char,'=')) != NULL)
 			*value++ = 0;
 		if (!strcmp(this_char,"fd")) {
fs/autofs4/inode.c +3 -1
diff -Nur linux-2.4.15-pre5/fs/autofs4/inode.c linux-2.4.15-pre5-rs/fs/autofs4/inode.c
@@ -112,7 +112,9 @@
 	*pipefd = -1;
 
 	if ( !options ) return 1;
-	for (this_char = strtok(options,","); this_char; this_char = strtok(NULL,",")) {
+	while ((this_char = strsep(&options,",")) != NULL) {
+		if (!*this_char)
+			continue;
 		if ((value = strchr(this_char,'=')) != NULL)
 			*value++ = 0;
 		if (!strcmp(this_char,"fd")) {
fs/devpts/inode.c +3 -4
diff -Nur linux-2.4.15-pre5/fs/devpts/inode.c linux-2.4.15-pre5-rs/fs/devpts/inode.c
@@ -66,10 +66,9 @@
 	umode_t mode = 0600;
 	char *this_char, *value;
 
-	this_char = NULL;
-	if ( options )
-		this_char = strtok(options,",");
-	for ( ; this_char; this_char = strtok(NULL,",")) {
+	while ((this_char = strsep(&options,",")) != NULL) {
+		if (!*this_char)
+			continue;
 		if ((value = strchr(this_char,'=')) != NULL)
 			*value++ = 0;
 		if (!strcmp(this_char,"uid")) {
fs/ext2/super.c +3 -3
diff -Nur linux-2.4.15-pre5/fs/ext2/super.c linux-2.4.15-pre5-rs/fs/ext2/super.c
@@ -166,9 +166,9 @@
 
 	if (!options)
 		return 1;
-	for (this_char = strtok (options, ",");
-	     this_char != NULL;
-	     this_char = strtok (NULL, ",")) {
+	while ((this_char = strsep (&options, ",")) != NULL) {
+		if (!*this_char)
+			continue;
 		if ((value = strchr (this_char, '=')) != NULL)
 			*value++ = 0;
 		if (!strcmp (this_char, "bsddf"))
fs/ext3/super.c +3 -3
diff -Nur linux-2.4.15-pre5/fs/ext3/super.c linux-2.4.15-pre5-rs/fs/ext3/super.c
@@ -505,9 +505,9 @@
 
 	if (!options)
 		return 1;
-	for (this_char = strtok (options, ",");
-	     this_char != NULL;
-	     this_char = strtok (NULL, ",")) {
+	while ((this_char = strsep (&options, ",")) != NULL) {
+		if (!*this_char)
+			continue;
 		if ((value = strchr (this_char, '=')) != NULL)
 			*value++ = 0;
 		if (!strcmp (this_char, "bsddf"))
fs/hfs/super.c +3 -2
diff -Nur linux-2.4.15-pre5/fs/hfs/super.c linux-2.4.15-pre5-rs/fs/hfs/super.c
@@ -181,8 +181,9 @@
 	if (!options) {
 		goto done;
 	}
-	for (this_char = strtok(options,","); this_char;
-	     this_char = strtok(NULL,",")) {
+	while ((this_char = strsep(&options, ",")) != NULL) {
+		if (!*this_char)
+			continue;
 		if ((value = strchr(this_char,'=')) != NULL) {
 			*value++ = 0;
 		}
fs/hpfs/super.c +3 -1
diff -Nur linux-2.4.15-pre5/fs/hpfs/super.c linux-2.4.15-pre5-rs/fs/hpfs/super.c
@@ -176,7 +176,9 @@
 
 	/*printk("Parsing opts: '%s'\n",opts);*/
 
-	for (p = strtok(opts, ","); p != 0; p = strtok(0, ",")) {
+	while ((p = strsep(&opts, ",")) != NULL) {
+		if (!*p)
+			continue;
 		if ((rhs = strchr(p, '=')) != 0)
 			*rhs++ = '\0';
 		if (!strcmp(p, "help")) return 2;
fs/intermezzo/super.c +3 -3
diff -Nur linux-2.4.15-pre5/fs/intermezzo/super.c linux-2.4.15-pre5-rs/fs/intermezzo/super.c
@@ -120,10 +120,10 @@
         store_opt(prestodev, NULL, PRESTO_PSDEV_NAME "0"); 
 
         CDEBUG(D_SUPER, "parsing options\n");
-        for (this_char = strtok (options, ",");
-             this_char != NULL;
-             this_char = strtok (NULL, ",")) {
+        while ((this_char = strsep (&options, ",")) != NULL) {
                 char *opt;
+                if (!*this_char)
+                        continue;
                 CDEBUG(D_SUPER, "this_char %s\n", this_char);
 
                 if ( (opt = read_opt("fileset", this_char)) ) {
fs/isofs/inode.c +3 -1
diff -Nur linux-2.4.15-pre5/fs/isofs/inode.c linux-2.4.15-pre5-rs/fs/isofs/inode.c
@@ -294,7 +294,9 @@
 	popt->session=-1;
 	popt->sbsector=-1;
 	if (!options) return 1;
-	for (this_char = strtok(options,","); this_char; this_char = strtok(NULL,",")) {
+	while ((this_char = strsep(&options,",")) != NULL) {
+		if (!*this_char)
+			continue;
 	        if (strncmp(this_char,"norock",6) == 0) {
 		  popt->rock = 'n';
 		  continue;
fs/proc/inode.c +3 -1
diff -Nur linux-2.4.15-pre5/fs/proc/inode.c linux-2.4.15-pre5-rs/fs/proc/inode.c
@@ -106,7 +106,9 @@
 	*uid = current->uid;
 	*gid = current->gid;
 	if (!options) return 1;
-	for (this_char = strtok(options,","); this_char; this_char = strtok(NULL,",")) {
+	while ((this_char = strsep(&options,",")) != NULL) {
+		if (!*this_char)
+			continue;
 		if ((value = strchr(this_char,'=')) != NULL)
 			*value++ = 0;
 		if (!strcmp(this_char,"uid")) {
fs/reiserfs/super.c +3 -1
diff -Nur linux-2.4.15-pre5/fs/reiserfs/super.c linux-2.4.15-pre5-rs/fs/reiserfs/super.c
@@ -153,7 +153,9 @@
 	/* use default configuration: create tails, journaling on, no
            conversion to newest format */
 	return 1;
-    for (this_char = strtok (options, ","); this_char != NULL; this_char = strtok (NULL, ",")) {
+    while ((this_char = strsep (&options, ",")) != NULL) {
+	if (!*this_char)
+	    continue;
 	if ((value = strchr (this_char, '=')) != NULL)
 	    *value++ = 0;
 	if (!strcmp (this_char, "notail")) {
fs/udf/super.c +3 -1
diff -Nur linux-2.4.15-pre5/fs/udf/super.c linux-2.4.15-pre5-rs/fs/udf/super.c
@@ -218,8 +218,10 @@
 	if (!options)
 		return 1;
 
-	for (opt = strtok(options, ","); opt; opt = strtok(NULL, ","))
+	while ((opt = strsep(&options, ",")) != NULL)
 	{
+		if (!*opt)
+			continue;
 		/* Make "opt=val" into two strings */
 		val = strchr(opt, '=');
 		if (val)
fs/ufs/super.c +3 -4
diff -Nur linux-2.4.15-pre5/fs/ufs/super.c linux-2.4.15-pre5-rs/fs/ufs/super.c
@@ -257,10 +257,9 @@
 	if (!options)
 		return 1;
 		
-	for (this_char = strtok (options, ",");
-	     this_char != NULL;
-	     this_char = strtok (NULL, ",")) {
-	     
+	while ((this_char = strsep (&options, ",")) != NULL) {
+		if (!*this_char)
+			continue;
 		if ((value = strchr (this_char, '=')) != NULL)
 			*value++ = 0;
 		if (!strcmp (this_char, "ufstype")) {