summaryrefslogtreecommitdiff
path: root/native
diff options
context:
space:
mode:
authorMario Torre <neugens@limasoftware.net>2008-04-09 20:23:10 +0000
committerMario Torre <neugens@limasoftware.net>2008-04-09 20:23:10 +0000
commit26c7eeb38377d6ddbf58a8360e52d29179ee0c97 (patch)
tree6ede434d301dd9d2459545f9974012beb174e9f4 /native
parent859285709b02bf70062853865fb322cfe932e25b (diff)
downloadclasspath-26c7eeb38377d6ddbf58a8360e52d29179ee0c97.tar.gz
2008-04-09 Mario Torre <neugens@aicas.com>
* java/io/File.java (canWrite): use canWriteDirectory(String). * vm/reference/java/io/VMFile.java (canWriteDirectory): new native method. * native/jni/java-io/java_io_VMFile.c: correct indentation, sync function names with header file definition. (Java_java_io_VMFile_canRead): use cpio_checkAccess to get access permission. Removed unused variable. (Java_java_io_VMFile_canWrite): likewise. (Java_java_io_VMFile_canWriteDirectory): new function.
Diffstat (limited to 'native')
-rw-r--r--native/jni/java-io/java_io_VMFile.c106
1 files changed, 55 insertions, 51 deletions
diff --git a/native/jni/java-io/java_io_VMFile.c b/native/jni/java-io/java_io_VMFile.c
index e79704fa6..a15cec769 100644
--- a/native/jni/java-io/java_io_VMFile.c
+++ b/native/jni/java-io/java_io_VMFile.c
@@ -97,7 +97,7 @@ Java_java_io_VMFile_create (JNIEnv * env,
if (result != CPNATIVE_OK)
{
if (result != EEXIST)
- JCL_ThrowException (env,
+ JCL_ThrowException (env,
"java/io/IOException",
cpnative_getErrorString (result));
JCL_free_cstring (env, name, filename);
@@ -124,12 +124,11 @@ Java_java_io_VMFile_create (JNIEnv * env,
JNIEXPORT jboolean JNICALL
Java_java_io_VMFile_canRead (JNIEnv * env,
- jobject obj __attribute__ ((__unused__)),
- jstring name)
+ jclass clazz __attribute__ ((__unused__)),
+ jstring name)
{
#ifndef WITHOUT_FILESYSTEM
const char *filename;
- int fd;
int result;
/* Don't use the JCL convert function because it throws an exception
@@ -137,20 +136,18 @@ Java_java_io_VMFile_canRead (JNIEnv * env,
filename = (*env)->GetStringUTFChars (env, name, 0);
if (filename == NULL)
{
- return 0;
+ return JNI_FALSE;
}
- /* The lazy man's way out. We actually do open the file for reading
- briefly to verify it can be done */
- result = cpio_openFile (filename, &fd, CPFILE_FLAG_READ, 0);
+ result = cpio_checkAccess (filename, CPFILE_FLAG_READ);
+
(*env)->ReleaseStringUTFChars (env, name, filename);
if (result != CPNATIVE_OK)
- return 0;
- cpio_closeFile (fd);
+ return JNI_FALSE;
- return 1;
+ return JNI_TRUE;
#else /* not WITHOUT_FILESYSTEM */
- return 0;
+ return JNI_FALSE;
#endif /* not WITHOUT_FILESYSTEM */
}
@@ -166,12 +163,11 @@ Java_java_io_VMFile_canRead (JNIEnv * env,
JNIEXPORT jboolean JNICALL
Java_java_io_VMFile_canWrite (JNIEnv * env,
- jobject obj __attribute__ ((__unused__)),
- jstring name)
+ jclass clazz __attribute__ ((__unused__)),
+ jstring name)
{
#ifndef WITHOUT_FILESYSTEM
const char *filename;
- int fd;
int result;
/* Don't use the JCL convert function because it throws an exception
@@ -179,27 +175,34 @@ Java_java_io_VMFile_canWrite (JNIEnv * env,
filename = (*env)->GetStringUTFChars (env, name, 0);
if (filename == NULL)
{
- return 0;
+ return JNI_FALSE;
}
- /* The lazy man's way out. We actually do open the file for writing
- briefly to verify it can be done */
- result = cpio_openFile (filename, &fd, CPFILE_FLAG_READWRITE, 0);
+ result = cpio_checkAccess (filename, CPFILE_FLAG_WRITE);
+
(*env)->ReleaseStringUTFChars (env, name, filename);
if (result != CPNATIVE_OK)
{
- return 0;
+ return JNI_FALSE;
}
- cpio_closeFile (fd);
- return 1;
+ return JNI_TRUE;
#else /* not WITHOUT_FILESYSTEM */
- return 0;
+ return JNI_FALSE;
#endif /* not WITHOUT_FILESYSTEM */
}
/*************************************************************************/
+JNIEXPORT jboolean JNICALL
+Java_java_io_VMFile_canWriteDirectory (JNIEnv *env, jclass clazz, jstring path)
+{
+ /* this is only valid on *nix systems */
+ return Java_java_io_VMFile_canWrite(env, clazz, path);
+}
+
+/*************************************************************************/
+
/*
* This method checks to see if we have execute permission on a file.
*
@@ -250,8 +253,8 @@ Java_java_io_VMFile_canExecute (JNIEnv * env,
JNIEXPORT jboolean JNICALL
Java_java_io_VMFile_setReadOnly (JNIEnv * env,
- jobject obj __attribute__ ((__unused__)),
- jstring name)
+ jclass clazz __attribute__ ((__unused__)),
+ jstring name)
{
#ifndef WITHOUT_FILESYSTEM
const char *filename;
@@ -326,10 +329,10 @@ Java_java_io_VMFile_setWritable (JNIEnv *env,
*/
JNIEXPORT jboolean JNICALL
Java_java_io_VMFile_setExecutable (JNIEnv *env,
- jclass clazz __attribute__ ((__unused__)),
- jstring name,
- jboolean executable,
- jboolean ownerOnly)
+ jclass clazz __attribute__ ((__unused__)),
+ jstring name,
+ jboolean executable,
+ jboolean ownerOnly)
{
return set_file_permissions (env, name, executable, ownerOnly,
CPFILE_FLAG_EXEC);
@@ -434,8 +437,8 @@ Java_java_io_VMFile_getUsableSpace (JNIEnv *env,
JNIEXPORT jboolean JNICALL
Java_java_io_VMFile_exists (JNIEnv * env,
- jobject obj __attribute__ ((__unused__)),
- jstring name)
+ jclass clazz __attribute__ ((__unused__)),
+ jstring name)
{
#ifndef WITHOUT_FILESYSTEM
const char *filename;
@@ -471,8 +474,8 @@ Java_java_io_VMFile_exists (JNIEnv * env,
JNIEXPORT jboolean JNICALL
Java_java_io_VMFile_isFile (JNIEnv * env,
- jobject obj __attribute__ ((__unused__)),
- jstring name)
+ jclass clazz __attribute__ ((__unused__)),
+ jstring name)
{
#ifndef WITHOUT_FILESYSTEM
const char *filename;
@@ -508,8 +511,8 @@ Java_java_io_VMFile_isFile (JNIEnv * env,
JNIEXPORT jboolean JNICALL
Java_java_io_VMFile_isDirectory (JNIEnv * env,
- jobject obj __attribute__ ((__unused__)),
- jstring name)
+ jclass clazz __attribute__ ((__unused__)),
+ jstring name)
{
#ifndef WITHOUT_FILESYSTEM
const char *filename;
@@ -545,8 +548,8 @@ Java_java_io_VMFile_isDirectory (JNIEnv * env,
JNIEXPORT jlong JNICALL
Java_java_io_VMFile_length (JNIEnv * env,
- jobject obj __attribute__ ((__unused__)),
- jstring name)
+ jclass clazz __attribute__ ((__unused__)),
+ jstring name)
{
#ifndef WITHOUT_FILESYSTEM
const char *filename;
@@ -593,8 +596,8 @@ Java_java_io_VMFile_length (JNIEnv * env,
JNIEXPORT jlong JNICALL
Java_java_io_VMFile_lastModified (JNIEnv * env,
- jobject obj __attribute__ ((__unused__)),
- jstring name)
+ jclass clazz __attribute__ ((__unused__)),
+ jstring name)
{
#ifndef WITHOUT_FILESYSTEM
const char *filename;
@@ -630,8 +633,8 @@ Java_java_io_VMFile_lastModified (JNIEnv * env,
JNIEXPORT jboolean JNICALL
Java_java_io_VMFile_setLastModified (JNIEnv * env,
- jobject obj __attribute__ ((__unused__)),
- jstring name, jlong newtime)
+ jclass clazz __attribute__ ((__unused__)),
+ jstring name, jlong newtime)
{
#ifndef WITHOUT_FILESYSTEM
const char *filename;
@@ -667,8 +670,8 @@ Java_java_io_VMFile_setLastModified (JNIEnv * env,
JNIEXPORT jboolean JNICALL
Java_java_io_VMFile_delete (JNIEnv * env,
- jobject obj __attribute__ ((__unused__)),
- jstring name)
+ jclass clazz __attribute__ ((__unused__)),
+ jstring name)
{
#ifndef WITHOUT_FILESYSTEM
const char *filename;
@@ -703,8 +706,8 @@ Java_java_io_VMFile_delete (JNIEnv * env,
JNIEXPORT jboolean JNICALL
Java_java_io_VMFile_mkdir (JNIEnv * env,
- jobject obj __attribute__ ((__unused__)),
- jstring name)
+ jclass clazz __attribute__ ((__unused__)),
+ jstring name)
{
#ifndef WITHOUT_FILESYSTEM
const char *pathname;
@@ -739,8 +742,8 @@ Java_java_io_VMFile_mkdir (JNIEnv * env,
JNIEXPORT jboolean JNICALL
Java_java_io_VMFile_renameTo (JNIEnv * env,
- jobject obj __attribute__ ((__unused__)),
- jstring t, jstring d)
+ jclass clazz __attribute__ ((__unused__)),
+ jstring t, jstring d)
{
#ifndef WITHOUT_FILESYSTEM
const char *old_filename, *new_filename;
@@ -783,8 +786,9 @@ Java_java_io_VMFile_renameTo (JNIEnv * env,
*/
JNIEXPORT jobjectArray JNICALL
-Java_java_io_VMFile_list (JNIEnv * env, jobject obj
- __attribute__ ((__unused__)), jstring name)
+Java_java_io_VMFile_list (JNIEnv * env,
+ jclass clazz __attribute__ ((__unused__)),
+ jstring name)
{
#ifndef WITHOUT_FILESYSTEM
const int REALLOC_SIZE = 10;
@@ -991,8 +995,8 @@ maybeGrowBuf (JNIEnv *env, char *buf, int *size, int required)
JNIEXPORT jstring JNICALL
Java_java_io_VMFile_toCanonicalForm (JNIEnv *env,
- jclass class __attribute__ ((__unused__)),
- jstring jpath)
+ jclass class __attribute__ ((__unused__)),
+ jstring jpath)
{
#ifndef WITHOUT_FILESYSTEM
const char *path;