diff --git a/jdk/src/share/back/export/sys.h b/jdk/src/share/back/export/sys.h index 4c42ec23d64..bd4bb9dd1d0 100644 --- a/jdk/src/share/back/export/sys.h +++ b/jdk/src/share/back/export/sys.h @@ -37,7 +37,7 @@ /* Implemented in linker_md.c */ -void dbgsysBuildLibName(char *, int, char *, char *); +void dbgsysBuildLibName(char *, int, const char *, const char *); void * dbgsysLoadLibrary(const char *, char *err_buf, int err_buflen); void dbgsysUnloadLibrary(void *); void * dbgsysFindLibraryEntry(void *, const char *); diff --git a/jdk/src/share/back/transport.c b/jdk/src/share/back/transport.c index 1d7335d660b..20892e3d998 100644 --- a/jdk/src/share/back/transport.c +++ b/jdk/src/share/back/transport.c @@ -97,12 +97,12 @@ findTransportOnLoad(void *handle) /* Load transport library (directory=="" means do system search) */ static void * -loadTransportLibrary(char *libdir, char *name) +loadTransportLibrary(const char *libdir, const char *name) { void *handle; char libname[MAXPATHLEN+2]; char buf[MAXPATHLEN*2+100]; - char *plibdir; + const char *plibdir; /* Convert libdir from UTF-8 to platform encoding */ plibdir = NULL; @@ -131,12 +131,12 @@ loadTransportLibrary(char *libdir, char *name) * JDK 1.2 javai.c v1.61 */ static jdwpError -loadTransport(char *name, jdwpTransportEnv **transportPtr) +loadTransport(const char *name, jdwpTransportEnv **transportPtr) { JNIEnv *env; jdwpTransport_OnLoad_t onLoad; void *handle; - char *libdir; + const char *libdir; /* Make sure library name is not empty */ if (name == NULL) { diff --git a/jdk/src/share/demo/jvmti/hprof/hprof_md.h b/jdk/src/share/demo/jvmti/hprof/hprof_md.h index b3e66fe36a6..b65cba0ed9b 100644 --- a/jdk/src/share/demo/jvmti/hprof/hprof_md.h +++ b/jdk/src/share/demo/jvmti/hprof/hprof_md.h @@ -69,7 +69,7 @@ unsigned md_htonl(unsigned l); unsigned md_ntohs(unsigned short s); unsigned md_ntohl(unsigned l); -void md_build_library_name(char *holder, int holderlen, char *pname, char *fname); +void md_build_library_name(char *holder, int holderlen, const char *pname, const char *fname); void * md_load_library(const char *name, char *err_buf, int err_buflen); void md_unload_library(void *handle); void * md_find_library_entry(void *handle, const char *name); diff --git a/jdk/src/solaris/back/linker_md.c b/jdk/src/solaris/back/linker_md.c index dbcfc04a40a..07be055a5ff 100644 --- a/jdk/src/solaris/back/linker_md.c +++ b/jdk/src/solaris/back/linker_md.c @@ -55,34 +55,27 @@ #endif static void dll_build_name(char* buffer, size_t buflen, - const char* pname, const char* fname) { - // Based on os_solaris.cpp + const char* paths, const char* fname) { + char *path, *paths_copy, *next_token; - char *path_sep = PATH_SEPARATOR; - char *pathname = (char *)pname; - *buffer = '\0'; - while (strlen(pathname) > 0) { - char *p = strchr(pathname, *path_sep); - if (p == NULL) { - p = pathname + strlen(pathname); - } - /* check for NULL path */ - if (p == pathname) { - continue; - } - (void)snprintf(buffer, buflen, "%.*s/lib%s." LIB_SUFFIX, (int)(p - pathname), - pathname, fname); + paths_copy = strdup(paths); + if (paths_copy == NULL) { + return; + } + next_token = NULL; + path = strtok_r(paths_copy, PATH_SEPARATOR, &next_token); + + while (path != NULL) { + snprintf(buffer, buflen, "%s/lib%s." LIB_SUFFIX, path, fname); if (access(buffer, F_OK) == 0) { break; } - if (*p == '\0') { - pathname = p; - } else { - pathname = p + 1; - } *buffer = '\0'; + path = strtok_r(NULL, PATH_SEPARATOR, &next_token); } + + free(paths_copy); } /* @@ -103,7 +96,7 @@ dbgsysBuildFunName(char *name, int nameLen, int args_size, int encodingIndex) * appropriate pre and extensions to a filename and the path */ void -dbgsysBuildLibName(char *holder, int holderlen, char *pname, char *fname) +dbgsysBuildLibName(char *holder, int holderlen, const char *pname, const char *fname) { const int pnamelen = pname ? strlen(pname) : 0; diff --git a/jdk/src/solaris/demo/jvmti/hprof/hprof_md.c b/jdk/src/solaris/demo/jvmti/hprof/hprof_md.c index 204636328f9..9cfcc592c3a 100644 --- a/jdk/src/solaris/demo/jvmti/hprof/hprof_md.c +++ b/jdk/src/solaris/demo/jvmti/hprof/hprof_md.c @@ -381,38 +381,32 @@ md_ntohl(unsigned l) } static void dll_build_name(char* buffer, size_t buflen, - const char* pname, const char* fname) { - // Loosely based on os_solaris.cpp + const char* paths, const char* fname) { + char *path, *paths_copy, *next_token; - char *pathname = (char *)pname; - *buffer = '\0'; - while (strlen(pathname) > 0) { - char *p = strchr(pathname, ':'); - if (p == NULL) { - p = pathname + strlen(pathname); - } - /* check for NULL path */ - if (p == pathname) { - continue; - } - (void)snprintf(buffer, buflen, "%.*s/lib%s" JNI_LIB_SUFFIX, - (int)(p - pathname), pathname, fname); + paths_copy = strdup(paths); + if (paths_copy == NULL) { + return; + } - if (access(buffer, F_OK) == 0) { - break; - } - if (*p == '\0') { - pathname = p; - } else { - pathname = p + 1; - } - *buffer = '\0'; - } + next_token = NULL; + path = strtok_r(paths_copy, ":", &next_token); + + while (path != NULL) { + snprintf(buffer, buflen, "%s/lib%s" JNI_LIB_SUFFIX, path, fname); + if (access(buffer, F_OK) == 0) { + break; + } + *buffer = '\0'; + path = strtok_r(NULL, ":", &next_token); + } + + free(paths_copy); } /* Create the actual fill filename for a dynamic library. */ void -md_build_library_name(char *holder, int holderlen, char *pname, char *fname) +md_build_library_name(char *holder, int holderlen, const char *pname, const char *fname) { int pnamelen; diff --git a/jdk/src/windows/back/linker_md.c b/jdk/src/windows/back/linker_md.c index ad48d3d57c2..52bf494186d 100644 --- a/jdk/src/windows/back/linker_md.c +++ b/jdk/src/windows/back/linker_md.c @@ -39,38 +39,27 @@ #include "path_md.h" static void dll_build_name(char* buffer, size_t buflen, - const char* pname, const char* fname) { - // Based on os_windows.cpp + const char* paths, const char* fname) { + char *path, *paths_copy, *next_token; - char *path_sep = PATH_SEPARATOR; - char *pathname = (char *)pname; - *buffer = '\0'; - while (strlen(pathname) > 0) { - char *p = strchr(pathname, *path_sep); - if (p == NULL) { - p = pathname + strlen(pathname); - } - /* check for NULL path */ - if (p == pathname) { - continue; - } - if (*(p-1) == ':' || *(p-1) == '\\') { - (void)_snprintf(buffer, buflen, "%.*s%s.dll", (int)(p - pathname), - pathname, fname); - } else { - (void)_snprintf(buffer, buflen, "%.*s\\%s.dll", (int)(p - pathname), - pathname, fname); - } + paths_copy = strdup(paths); + if (paths_copy == NULL) { + return; + } + + next_token = NULL; + path = strtok_s(paths_copy, PATH_SEPARATOR, &next_token); + + while (path != NULL) { + _snprintf(buffer, buflen, "%s\\%s.dll", path, fname); if (_access(buffer, 0) == 0) { break; } - if (*p == '\0') { - pathname = p; - } else { - pathname = p + 1; - } *buffer = '\0'; + path = strtok_s(NULL, PATH_SEPARATOR, &next_token); } + + free(paths_copy); } /* @@ -113,7 +102,7 @@ dbgsysGetLastErrorString(char *buf, int len) * Build a machine dependent library name out of a path and file name. */ void -dbgsysBuildLibName(char *holder, int holderlen, char *pname, char *fname) +dbgsysBuildLibName(char *holder, int holderlen, const char *pname, const char *fname) { const int pnamelen = pname ? (int)strlen(pname) : 0; diff --git a/jdk/src/windows/demo/jvmti/hprof/hprof_md.c b/jdk/src/windows/demo/jvmti/hprof/hprof_md.c index 4bd4a40f049..90e15ed5b84 100644 --- a/jdk/src/windows/demo/jvmti/hprof/hprof_md.c +++ b/jdk/src/windows/demo/jvmti/hprof/hprof_md.c @@ -368,42 +368,32 @@ get_last_error_string(char *buf, int len) } static void dll_build_name(char* buffer, size_t buflen, - const char* pname, const char* fname) { - // Loosley based on os_windows.cpp + const char* paths, const char* fname) { + char *path, *paths_copy, *next_token; - char *pathname = (char *)pname; - *buffer = '\0'; - while (strlen(pathname) > 0) { - char *p = strchr(pathname, ';'); - if (p == NULL) { - p = pathname + strlen(pathname); - } - /* check for NULL path */ - if (p == pathname) { - continue; - } - if (*(p-1) == ':' || *(p-1) == '\\') { - (void)_snprintf(buffer, buflen, "%.*s%s.dll", (int)(p - pathname), - pathname, fname); - } else { - (void)_snprintf(buffer, buflen, "%.*s\\%s.dll", (int)(p - pathname), - pathname, fname); - } + paths_copy = strdup(paths); + if (paths_copy == NULL) { + return; + } + + next_token = NULL; + path = strtok_s(paths_copy, ";", &next_token); + + while (path != NULL) { + _snprintf(buffer, buflen, "%s\\%s.dll", path, fname); if (_access(buffer, 0) == 0) { break; } - if (*p == '\0') { - pathname = p; - } else { - pathname = p + 1; - } *buffer = '\0'; + path = strtok_s(NULL, ";", &next_token); } + + free(paths_copy); } /* Build a machine dependent library name out of a path and file name. */ void -md_build_library_name(char *holder, int holderlen, char *pname, char *fname) +md_build_library_name(char *holder, int holderlen, const char *pname, const char *fname) { int pnamelen;