From 65aec024eabc20a1aaf019cd96bdec6818f0a9a6 Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Tue, 25 Sep 2001 23:31:27 +0000 Subject: [PATCH] uses strtok_r if avaliable. r=doug/cls, sr=rpotts, patch by drepper@cygnus.com. bug 99248 --- tools/trace-malloc/lib/nsTraceMalloc.c | 15 ++++++++++++++- xpcom/base/nsTraceMalloc.c | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/tools/trace-malloc/lib/nsTraceMalloc.c b/tools/trace-malloc/lib/nsTraceMalloc.c index 95af0f9bcbe6..6074838b5437 100644 --- a/tools/trace-malloc/lib/nsTraceMalloc.c +++ b/tools/trace-malloc/lib/nsTraceMalloc.c @@ -1507,6 +1507,9 @@ PR_IMPLEMENT(int) NS_TraceMallocStartupArgs(int argc, char* argv[]) /* In child: set up stdin, parse args, and exec. */ int maxargc, nargc; char **nargv, *token; +#if HAVE_STRTOK_R + char *newstr = nsnull; +#endif if (pipefds[0] != 0) { dup2(pipefds[0], 0); @@ -1514,13 +1517,23 @@ PR_IMPLEMENT(int) NS_TraceMallocStartupArgs(int argc, char* argv[]) } close(pipefds[1]); +#ifdef HAVE_STRTOK_R + tmlogname = strtok_r(tmlogname + 1, " \t", &newstr); +#else tmlogname = strtok(tmlogname + 1, " \t"); +#endif maxargc = 3; nargv = (char **) malloc((maxargc+1) * sizeof(char *)); if (!nargv) exit(1); nargc = 0; nargv[nargc++] = tmlogname; - while ((token = strtok(NULL, " \t")) != NULL) { + while ( +#ifdef HAVE_STRTOK_R + (token = strtok_r(newstr, " \t", &newstr)) +#else + (token = strtok(NULL, " \t")) +#endif + != NULL) { if (nargc == maxargc) { maxargc *= 2; nargv = (char**) diff --git a/xpcom/base/nsTraceMalloc.c b/xpcom/base/nsTraceMalloc.c index 95af0f9bcbe6..6074838b5437 100644 --- a/xpcom/base/nsTraceMalloc.c +++ b/xpcom/base/nsTraceMalloc.c @@ -1507,6 +1507,9 @@ PR_IMPLEMENT(int) NS_TraceMallocStartupArgs(int argc, char* argv[]) /* In child: set up stdin, parse args, and exec. */ int maxargc, nargc; char **nargv, *token; +#if HAVE_STRTOK_R + char *newstr = nsnull; +#endif if (pipefds[0] != 0) { dup2(pipefds[0], 0); @@ -1514,13 +1517,23 @@ PR_IMPLEMENT(int) NS_TraceMallocStartupArgs(int argc, char* argv[]) } close(pipefds[1]); +#ifdef HAVE_STRTOK_R + tmlogname = strtok_r(tmlogname + 1, " \t", &newstr); +#else tmlogname = strtok(tmlogname + 1, " \t"); +#endif maxargc = 3; nargv = (char **) malloc((maxargc+1) * sizeof(char *)); if (!nargv) exit(1); nargc = 0; nargv[nargc++] = tmlogname; - while ((token = strtok(NULL, " \t")) != NULL) { + while ( +#ifdef HAVE_STRTOK_R + (token = strtok_r(newstr, " \t", &newstr)) +#else + (token = strtok(NULL, " \t")) +#endif + != NULL) { if (nargc == maxargc) { maxargc *= 2; nargv = (char**)