Path: blob/master/runtime/jcl/filesys/vmfilesys.c
6000 views
/*******************************************************************************1* Copyright (c) 1998, 2016 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 "jcl.h"23#include <ctype.h>24#include <string.h>25#include "jclglob.h"26#include "iohelp.h"27#include "util_api.h"282930jbyteArray JNICALL Java_com_ibm_oti_vm_VM_getPathFromClassPath(JNIEnv * env, jclass clazz, jint cpIndex)31{32#if defined(J9VM_OPT_DYNAMIC_LOAD_SUPPORT)33J9JavaVM *javaVM;34J9ClassPathEntry cpEntry;35J9ClassLoader *classLoader;36jbyteArray jbytes;37jsize length;3839/* Check the parameters */40javaVM = ((J9VMThread *) env)->javaVM;41classLoader = (J9ClassLoader*)javaVM->systemClassLoader;4243/* Sniff the cpEntry */44if (getClassPathEntry((J9VMThread *)env, classLoader, cpIndex, &cpEntry)) {45return NULL;46}47if(cpEntry.type == CPE_TYPE_DIRECTORY || cpEntry.type == CPE_TYPE_JAR)48{49length = (jsize)cpEntry.pathLength;50if (cpEntry.type == CPE_TYPE_DIRECTORY &&51cpEntry.path[length-1] != '/' && cpEntry.path[length-1] != '\\')52length++;53jbytes = (*env)->NewByteArray(env, length);54if (jbytes != NULL) {55(*env)->SetByteArrayRegion(env, jbytes, 0, (jint)cpEntry.pathLength, (jbyte *) cpEntry.path);56if (length != (jsize)cpEntry.pathLength)57(*env)->SetByteArrayRegion(env, jbytes, length-1, 1, (jbyte *) DIR_SEPARATOR_STR);58}59return jbytes;60}6162/* Not a directory. Return NULL; */63return NULL;6465#else66/* No dynamic loader. */67return NULL;68#endif69}707172