Esempio n. 1
0
File: zip.c Progetto: freeVM/freeVM
JNIEXPORT jint JNICALL
Java_java_util_zip_ZipFile_openZipImpl (JNIEnv * env, jobject recv,
                                        jbyteArray zipName)
{
  VMI_ACCESS_FROM_ENV (env);
  PORT_ACCESS_FROM_ENV (env);

  I_32 retval;
  JCLZipFile *jclZipFile;
  JCLZipFileLink *zipfileHandles;
  jsize length;
  char pathCopy[HyMaxPath];
  HyZipCachePool *zipCachePool;

  jclZipFile = jclmem_allocate_memory (env, sizeof (*jclZipFile));
  if (!jclZipFile)
    return 3;

  length = (*env)->GetArrayLength (env, zipName);
  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
  ((*env)->GetByteArrayRegion (env, zipName, 0, length, pathCopy));
  pathCopy[length++] = '\0';
  ioh_convertToPlatform (pathCopy);

  /* Open the zip file (caching will be managed automatically by zipsup) */
  zipCachePool = (*VMI)->GetZipCachePool (VMI);
  retval =
    zip_openZipFile (privatePortLibrary, pathCopy, &(jclZipFile->hyZipFile),
                     zipCachePool);

  if (retval)
    {
      jclmem_free_memory (env, jclZipFile);     /* free on fail */

      if (retval == ZIP_ERR_FILE_OPEN_ERROR)
        return 1;
      else
        return 2;
    }

  /* Add the zipFile we just allocated to the list of zip files -- we will
   * free this on UnLoad if its not already free'd.
   */
  zipfileHandles = JCL_CACHE_GET (env, zipfile_handles);
  jclZipFile->last = (JCLZipFile *) zipfileHandles;
  jclZipFile->next = zipfileHandles->next;
  if (zipfileHandles->next != NULL)
    zipfileHandles->next->last = jclZipFile;
  zipfileHandles->next = jclZipFile;

  (*env)->SetLongField (env, recv,
                        JCL_CACHE_GET (env,
                                       FID_java_util_zip_ZipFile_descriptor),
			            ((IDATA) jclZipFile));
  return 0;
}
Esempio n. 2
0
/*
 * Class:     org_apache_harmony_luni_platform_OSFileSystem
 * Method:    openImpl
 * Signature: ([BI)J
 */
JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSFileSystem_openImpl
  (JNIEnv * env, jobject obj, jbyteArray path, jint jflags){
      PORT_ACCESS_FROM_ENV (env);
      I_32 flags = 0;
      I_32 mode = 0; 
      IDATA portFD;
      jsize length;
      char pathCopy[HyMaxPath];

      switch(jflags){
        case org_apache_harmony_luni_platform_IFileSystem_O_RDONLY:
                flags = HyOpenRead;
                mode = 0;
                break;
        case org_apache_harmony_luni_platform_IFileSystem_O_WRONLY:
                flags = HyOpenCreate | HyOpenWrite | HyOpenTruncate;
                mode = 0666;
                break;
        case org_apache_harmony_luni_platform_IFileSystem_O_RDWR:
                flags = HyOpenRead | HyOpenWrite | HyOpenCreate;
                mode = 0666;
                break;
        case org_apache_harmony_luni_platform_IFileSystem_O_APPEND:
                flags = HyOpenWrite | HyOpenCreate | HyOpenAppend; 
                mode = 0666;
                break;
        case org_apache_harmony_luni_platform_IFileSystem_O_RDWRSYNC:
        		flags = HyOpenRead | HyOpenWrite | HyOpenCreate | HyOpenSync;
        		mode = 0666;
        		break;
      }

      length = (*env)->GetArrayLength (env, path);
      length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
      ((*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy));
      pathCopy[length] = '\0';
      ioh_convertToPlatform (pathCopy);

      portFD = hyfile_open (pathCopy, flags, mode);
      return (jlong)portFD;
  }