Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/macosx/native_NOTIOS/com/apple/laf/AquaFileView.m
38902 views
/*1* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/242526#include <jni_util.h>2728#import "com_apple_laf_AquaFileView.h"2930#import <sys/param.h> // for MAXPATHLEN31#import <CoreFoundation/CoreFoundation.h>32#import <JavaNativeFoundation/JavaNativeFoundation.h>3334/*35* Class: com_apple_laf_AquaFileView36* Method: getNativePathToRunningJDKBundle37* Signature: ()Ljava/lang/String;38*/39// TODO: Un-comment this out40/*JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativePathToRunningJDKBundle41(JNIEnv *env, jclass clazz)42{43jstring returnValue = NULL;44JNF_COCOA_ENTER(env);4546returnValue = JNFNSToJavaString(env, getRunningJavaBundle());4748JNF_COCOA_EXIT(env);49return returnValue;50}*/5152/*53* Class: com_apple_laf_AquaFileView54* Method: getNativePathToSharedJDKBundle55* Signature: ()Ljava/lang/String;56*/57JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativePathToSharedJDKBundle58(JNIEnv *env, jclass clazz)59{60jstring returnValue = NULL;61JNF_COCOA_ENTER(env);6263returnValue = JNFNSToJavaString(env, [[NSBundle bundleWithIdentifier:@"com.apple.JavaVM"] bundlePath]);6465JNF_COCOA_EXIT(env);66return returnValue;67}6869/*70* Class: com_apple_laf_AquaFileView71* Method: getNativeMachineName72* Signature: ()Ljava/lang/String;73*/74JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativeMachineName75(JNIEnv *env, jclass clazz)76{77jstring returnValue = NULL;78JNF_COCOA_ENTER(env);7980CFStringRef machineName = CSCopyMachineName();81returnValue = JNFNSToJavaString(env, (NSString*)machineName);8283if (machineName != NULL) {84CFRelease(machineName);85}8687JNF_COCOA_EXIT(env);88return returnValue;89}9091/*92* Class: com_apple_laf_AquaFileView93* Method: getNativeLSInfo94* Signature: ([BZ)I95*/96JNIEXPORT jint JNICALL Java_com_apple_laf_AquaFileView_getNativeLSInfo97(JNIEnv *env, jclass clazz, jbyteArray absolutePath, jboolean isDir)98{99jint returnValue = com_apple_laf_AquaFileView_UNINITALIZED_LS_INFO;100JNF_COCOA_ENTER(env);101102jbyte *byteArray = (*env)->GetByteArrayElements(env, absolutePath, NULL);103CHECK_NULL_RETURN(byteArray, returnValue);104jsize length = (*env)->GetArrayLength(env, absolutePath);105106// Can't assume that byteArray is NULL terminated and FSPathMakeRef doesn't107// let us specify a length.108UInt8 arrayCopy[length + 1];109jsize i;110for (i = 0; i < length; i++) {111arrayCopy[i] = (UInt8)byteArray[i];112}113arrayCopy[length] = '\0';114(*env)->ReleaseByteArrayElements(env, absolutePath, byteArray, JNI_ABORT);115116Boolean isDirectory = (isDir == JNI_TRUE ? true : false);117FSRef ref;118OSErr err = FSPathMakeRef((const UInt8 *)&arrayCopy, &ref, &isDirectory);119if (err == noErr) {120LSItemInfoRecord itemInfo;121err = LSCopyItemInfoForRef(&ref, kLSRequestBasicFlagsOnly, &itemInfo);122123if (err == noErr) {124returnValue = itemInfo.flags;125}126}127128JNF_COCOA_EXIT(env);129return returnValue;130}131132/*133* Class: com_apple_laf_AquaFileView134* Method: getNativeDisplayName135* Signature: ([BZ)Ljava/lang/String;136*/137JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativeDisplayName138(JNIEnv *env, jclass clazz, jbyteArray absolutePath, jboolean isDir)139{140jstring returnValue = NULL;141JNF_COCOA_ENTER(env);142143jbyte *byteArray = (*env)->GetByteArrayElements(env, absolutePath, NULL);144CHECK_NULL_RETURN(byteArray, returnValue);145jsize length = (*env)->GetArrayLength(env, absolutePath);146147// Can't assume that byteArray is NULL terminated and FSPathMakeRef doesn't148// let us specify a length.149UInt8 arrayCopy[length + 1];150jsize i;151for (i = 0; i < length; i++) {152arrayCopy[i] = (UInt8)byteArray[i];153}154arrayCopy[length] = '\0';155(*env)->ReleaseByteArrayElements(env, absolutePath, byteArray, JNI_ABORT);156157Boolean isDirectory = (isDir == JNI_TRUE ? true : false);158FSRef ref;159160OSErr theErr = FSPathMakeRefWithOptions((const UInt8 *)&arrayCopy,161kFSPathMakeRefDoNotFollowLeafSymlink,162&ref, &isDirectory);163if (theErr == noErr) {164CFStringRef displayName = NULL;165166theErr = LSCopyDisplayNameForRef(&ref, &displayName);167168if (theErr == noErr) {169CFMutableStringRef mutableDisplayName = CFStringCreateMutableCopy(NULL, 0, displayName);170CFStringNormalize(mutableDisplayName, kCFStringNormalizationFormC);171returnValue = JNFNSToJavaString(env, (NSString *)mutableDisplayName);172CFRelease(mutableDisplayName);173}174175if (displayName != NULL) {176CFRelease(displayName);177}178}179180JNF_COCOA_EXIT(env);181return returnValue;182}183184/*185* Class: com_apple_laf_AquaFileView186* Method: getNativePathForResolvedAlias187* Signature: ([BZ)Ljava/lang/String;188*/189JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativePathForResolvedAlias190(JNIEnv *env, jclass clazz, jbyteArray pathToAlias, jboolean isDir)191{192jstring returnValue = NULL;193JNF_COCOA_ENTER(env);194195UInt8 pathCString[MAXPATHLEN + 1];196size_t maxPathLen = sizeof(pathCString) - 1;197198jbyte *byteArray = (*env)->GetByteArrayElements(env, pathToAlias, NULL);199CHECK_NULL_RETURN(byteArray, returnValue);200jsize length = (*env)->GetArrayLength(env, pathToAlias);201202if (length > maxPathLen) {203length = maxPathLen;204}205strncpy((char *)pathCString, (char *)byteArray, length);206// make sure it's null terminated207pathCString[length] = '\0';208(*env)->ReleaseByteArrayElements(env, pathToAlias, byteArray, JNI_ABORT);209210Boolean isDirectory = (isDir == JNI_TRUE ? true : false);211FSRef fileRef;212OSErr theErr = FSPathMakeRef(pathCString, &fileRef, &isDirectory);213214Boolean ignored;215theErr = FSResolveAliasFileWithMountFlags(&fileRef, false, &ignored,216&ignored, kResolveAliasFileNoUI);217if (theErr == noErr) {218UInt8 resolvedPath[MAXPATHLEN];219theErr = FSRefMakePath(&fileRef, resolvedPath, MAXPATHLEN);220221if (theErr == noErr) {222returnValue = (*env)->NewStringUTF(env, (char *)resolvedPath);223}224}225226JNF_COCOA_EXIT(env);227return returnValue;228}229230231