J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | #include <sys/types.h> |
| 27 | #include <sys/stat.h> |
| 28 | |
| 29 | #include "jni.h" |
| 30 | #include "jni_util.h" |
| 31 | #include "sun_management_FileSystemImpl.h" |
| 32 | |
| 33 | /* |
| 34 | * Class: sun_management_FileSystemImpl |
| 35 | * Method: isAccessUserOnly0 |
| 36 | * Signature: (Ljava/lang/String;)Z |
| 37 | */ |
| 38 | JNIEXPORT jboolean JNICALL Java_sun_management_FileSystemImpl_isAccessUserOnly0 |
| 39 | (JNIEnv *env, jclass ignored, jstring str) |
| 40 | { |
| 41 | jboolean res = JNI_FALSE; |
| 42 | jboolean isCopy; |
| 43 | const char *path = JNU_GetStringPlatformChars(env, str, &isCopy); |
| 44 | if (path != NULL) { |
| 45 | struct stat64 sb; |
| 46 | if (stat64(path, &sb) == 0) { |
| 47 | res = ((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) == 0) ? JNI_TRUE : JNI_FALSE; |
| 48 | } else { |
| 49 | JNU_ThrowIOExceptionWithLastError(env, "stat64 failed"); |
| 50 | } |
| 51 | if (isCopy) { |
| 52 | JNU_ReleaseStringPlatformChars(env, str, path); |
| 53 | } |
| 54 | } |
| 55 | return res; |
| 56 | } |