/*******************************************************************************1* Copyright (c) 1998, 2017 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/2122#include <string.h>2324#include "j9.h"25#include "j9consts.h"26#include "jni.h"27#include "j9protos.h"2829#define JIMAGE_EXTENSION "jimage"3031/* this file is owned by the VM-team. Please do not modify it without consulting the VM team */3233#if (defined(J9VM_OPT_DYNAMIC_LOAD_SUPPORT))343536char* getDefaultBootstrapClassPath(J9JavaVM * vm, char* javaHome)37{38PORT_ACCESS_FROM_JAVAVM(vm);39char separator = (char) j9sysinfo_get_classpathSeparator();40extern const char* const jclBootstrapClassPath[];41extern char* jclBootstrapClassPathAllocated[];42char **entry = NULL;43char *path = NULL;44char *lastEntry = NULL;45UDATA pathLength = 0;46UDATA javaHomeLength = strlen(javaHome);4748for (entry = GLOBAL_TABLE(jclBootstrapClassPath); NULL != *entry; ++entry) {49lastEntry = *entry;5051pathLength += strlen(lastEntry);5253/*54* Entries that start with ! don't need our attention:55* The space for the exclamation mark will be consumed56* by a path separator.57*/58if ('!' != lastEntry[0]) {59pathLength += javaHomeLength;60pathLength += 1; /* for separator or NUL-terminator */61pathLength += sizeof("/lib/") - 1;62}63}6465/* Always create space enough for the NUL-terminator. */66if (0 == pathLength) {67pathLength = 1;68}6970path = j9mem_allocate_memory(pathLength, J9MEM_CATEGORY_VM_JCL);71if (NULL != path) {72UDATA i = 0;73char* subPath = path;7475/* Always NUL-terminate the path. */76path[0] = '\0';7778for (entry = GLOBAL_TABLE(jclBootstrapClassPath), i = 0; NULL != *entry; ++entry, ++i) {79UDATA subLength = 0;8081/* add a separator before the second and subsequent entries */82if (0 != i) {83*subPath = separator;84subPath += 1;85pathLength -= 1;86}8788lastEntry = *entry;8990if ('!' == lastEntry[0]) {91j9str_printf(PORTLIB, subPath, (U_32)pathLength, "%s", lastEntry + 1);92j9mem_free_memory(*entry);93} else {94j9str_printf(PORTLIB, subPath, (U_32)pathLength,95"%s" DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR "%s",96/* classes.zip */ javaHome, *entry);97/* if this entry was allocated then free it as we will not use it98* after this point */99if (NULL != jclBootstrapClassPathAllocated[i]) {100j9mem_free_memory(jclBootstrapClassPathAllocated[i]);101}102}103*entry = NULL;104jclBootstrapClassPathAllocated[i] = NULL;105106subLength = strlen(subPath);107subPath += subLength;108pathLength -= subLength;109}110}111112return path;113}114115#endif /* J9VM_OPT_DYNAMIC_LOAD_SUPPORT */116117118