]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Use reentrant strtok_r() instead of strtok()
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 14 Aug 2010 19:19:32 +0000 (21:19 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 14 Aug 2010 19:19:32 +0000 (21:19 +0200)
args.c
ccache.c
execute.c
hashutil.c

diff --git a/args.c b/args.c
index 23819046af630f847dc0caaeab44a6e642425611..ae5ec96941c998d99c1d1a182d496d7245981fed 100644 (file)
--- a/args.c
+++ b/args.c
@@ -43,10 +43,10 @@ args_init_from_string(const char *command)
        struct args *args;
        char *p = x_strdup(command);
        char *q = p;
-       char *word;
+       char *word, *saveptr = NULL;
 
        args = args_init(0, NULL);
-       while ((word = strtok(q, " \t\r\n"))) {
+       while ((word = strtok_r(q, " \t\r\n", &saveptr))) {
                args_add(args, word);
                q = NULL;
        }
index b27127fa7afaf8c5a1de93f2ac22b83b42c3cae3..2242fa3f36009440be3da83c687cbd930605b521 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -944,10 +944,10 @@ calculate_common_hash(struct args *args, struct mdfour *hash)
 
        p = getenv("CCACHE_EXTRAFILES");
        if (p) {
-               char *path, *q;
+               char *path, *q, *saveptr = NULL;
                p = x_strdup(p);
                q = p;
-               while ((path = strtok(q, PATH_DELIM))) {
+               while ((path = strtok_r(q, PATH_DELIM, &saveptr))) {
                        cc_log("Hashing extra file %s", path);
                        hash_delimiter(hash, "extrafile");
                        if (!hash_file(hash, path)) {
@@ -1847,14 +1847,14 @@ static unsigned
 parse_sloppiness(char *p)
 {
        unsigned result = 0;
-       char *word, *q;
+       char *word, *q, *saveptr = NULL;
 
        if (!p) {
                return result;
        }
        p = x_strdup(p);
        q = p;
-       while ((word = strtok(q, ", "))) {
+       while ((word = strtok_r(q, ", ", &saveptr))) {
                if (str_eq(word, "file_macro")) {
                        cc_log("Being sloppy about __FILE__");
                        result |= SLOPPY_FILE_MACRO;
index a3a0894e9e93d9ae0a07a09b42902323f5eb55c7..45b1469c246c6ecfcdb1270e3d717005992be4f3 100644 (file)
--- a/execute.c
+++ b/execute.c
@@ -247,13 +247,15 @@ find_executable(const char *name, const char *exclude_name)
 static char *
 find_executable_in_path(const char *name, const char *exclude_name, char *path)
 {
-       char *tok;
+       char *tok, *saveptr = NULL;
 
        path = x_strdup(path);
 
        /* search the path looking for the first compiler of the right name
           that isn't us */
-       for (tok = strtok(path, PATH_DELIM); tok; tok = strtok(NULL, PATH_DELIM)) {
+       for (tok = strtok_r(path, PATH_DELIM, &saveptr);
+            tok;
+            tok = strtok_r(NULL, PATH_DELIM, &saveptr)) {
 #ifdef _WIN32
                char namebuf[MAX_PATH];
                int ret = SearchPath(tok, name, ".exe",
index 11c6cddadb6c8405817bbc47447666b811835167..1674c3a83280193667eefb1a6b59c770ba80222c 100644 (file)
@@ -287,12 +287,12 @@ int
 hash_multicommand_output(struct mdfour *hash, const char *commands,
                          const char *compiler)
 {
-       char *command_string, *command, *p;
+       char *command_string, *command, *p, *saveptr = NULL;
        int ok = 1;
 
        command_string = x_strdup(commands);
        p = command_string;
-       while ((command = strtok(p, ";"))) {
+       while ((command = strtok_r(p, ";", &saveptr))) {
                if (!hash_command_output(hash, command, compiler)) {
                        ok = 0;
                }