Browse Source

More reentrant code. The strtok() is replaced by strtok_r(). Fix issue #31.

git-svn-id: https://klish.googlecode.com/svn/trunk@253 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 14 years ago
parent
commit
b3360a7ca6
2 changed files with 6 additions and 4 deletions
  1. 3 2
      clish/shell/shell_spawn.c
  2. 3 2
      clish/variable/variable_expand.c

+ 3 - 2
clish/shell/shell_spawn.c

@@ -53,6 +53,7 @@ void clish_shell_load_files(clish_shell_t * this)
 	const char *path = getenv("CLISH_PATH");
 	char *buffer;
 	char *dirname;
+	char *saveptr;
 
 	if (NULL == path) {
 		/* use the default path */
@@ -62,8 +63,8 @@ void clish_shell_load_files(clish_shell_t * this)
 	buffer = clish_shell_tilde_expand(path);
 
 	/* now loop though each directory */
-	for (dirname = strtok(buffer, ";");
-	     dirname; dirname = strtok(NULL, ";")) {
+	for (dirname = strtok_r(buffer, ";", &saveptr);
+	     dirname; dirname = strtok_r(NULL, ";", &saveptr)) {
 		DIR *dir;
 		struct dirent *entry;
 

+ 3 - 2
clish/variable/variable_expand.c

@@ -170,6 +170,7 @@ static char *context_nextsegment(const context_t * this, const char **string)
 			if (p[-1] == '}') {
 				bool_t valid = BOOL_FALSE;
 				char *text, *q;
+				char *saveptr;
 
 				/* get the variable text */
 				text = lub_string_dupn(tmp, len);
@@ -179,8 +180,8 @@ static char *context_nextsegment(const context_t * this, const char **string)
 				 * Only return a result if at least 
 				 * of the words is an expandable variable
 				 */
-				for (q = strtok(text, ":");
-				     q; q = strtok(NULL, ":")) {
+				for (q = strtok_r(text, ":", &saveptr);
+				     q; q = strtok_r(NULL, ":", &saveptr)) {
 					char *var = context_retrieve(this, q);
 
 					/* copy the expansion or the raw word */