Exemplo n.º 1
0
/**
 * Gets a resource length for pointed reource identifier and locale.
 *
 * @param resource_id   resource identifier
 * @param locale_index  index of the locale
 * @return resource length in case successful operation and -1 if something is wrong
 */
JSR238_STATUSCODE jsr238_get_resource_length(jsize* length /* OUT */, jint resource_id, jint locale_index) {
    ResourceTableEntryType entry;
    unsigned char buf[4];
    void * handle;
    JSR238_STATUSCODE res = JSR238_STATUSCODE_FAIL;

    REPORT_CALL_TRACE(LC_LOWUI, "LF:STUB:jsr238_get_resource_length()\n");
    if (jsr238_devresource_file_open(locale_index, &handle) >= 0)
    {
        pcsl_file_read(handle, (char*)&ResourceFileHeader, 4);
        pcsl_file_read(handle, buf, 4);
        jsr238_fillInt(&ResourceFileHeader.headerLength, buf);
        if (jsr238_seekEntry(handle, resource_id, ResourceFileHeader.headerLength / 8, &entry)){
            *length = entry.resourceOffset;
            pcsl_file_read(handle, buf, 4);
            pcsl_file_read(handle, buf, 4);
            buf[0] = 0;
            jsr238_fillInt(&entry.resourceOffset, buf);
            *length = entry.resourceOffset - *length;
            res = JSR238_STATUSCODE_OK;
        }
        pcsl_file_close(handle);
    }
    return res;
}
Exemplo n.º 2
0
/**
 * Tests for pcsl_file_get_time().
 */
void testTimes() {
    int res;
    long time1, time2;
    int fileID;
    int i, j;

    res = pcsl_file_get_time(&dummy1, PCSL_FILE_TIME_LAST_MODIFIED, &time1);
    assertTrue("Time query succeeded for non-existent file", res == -1);

    res = pcsl_file_open(&file1, PCSL_FILE_O_RDWR | PCSL_FILE_O_TRUNC | PCSL_FILE_O_CREAT, (void **)&fileID);
    pcsl_file_close((void *)fileID);
    assertTrue("File creation failed", res == 0);

    res = pcsl_file_get_time(&file1, PCSL_FILE_TIME_LAST_MODIFIED, &time1);
    assertTrue("Time query failed", res == 0);
    res = pcsl_file_open(&file1, PCSL_FILE_O_RDWR | PCSL_FILE_O_APPEND, (void **)&fileID);
    assertTrue("File opening failed", res == 0);
    for (i = 0; i < 1000000; i++) {
        res = pcsl_file_write((void *)fileID, (unsigned char *)&time1, 4);
        assertTrue("Write failed", res == 4);
    }
    pcsl_file_close((void *)fileID);

    /* Writing 4 MB to a file should take several seconds */
    res = pcsl_file_get_time(&file1, PCSL_FILE_TIME_LAST_MODIFIED, &time2);
    assertTrue("Time query failed", res == 0);
    assertTrue("Modification time should be greater", time2 > time1);

    for (j = 0; j < 10; j++) {
        res = pcsl_file_open(&file1, PCSL_FILE_O_RDWR | PCSL_FILE_O_APPEND, (void **)&fileID);
        assertTrue("File opening failed", res == 0);
        for (i = 0; i < 1000000; i++) {
            res = pcsl_file_read((void *)fileID, (unsigned char *)&time1, 4);
            assertTrue("Read failed", res == 4);
        }
        pcsl_file_close((void *)fileID);
    }

    /* Reading anything from a file shouldn't lead to modification time change */
    res = pcsl_file_get_time(&file1, PCSL_FILE_TIME_LAST_MODIFIED, &time1);
    assertTrue("Time query failed", res == 0);
    assertTrue("Modification time shouldn't change", time1 == time2);

    pcsl_file_unlink(&file1);
}
Exemplo n.º 3
0
/**
 * FS only need to support MIDLets to quiry the size of the file. 
 * Check the File size by file name
 */
long pcsl_file_sizeof(const pcsl_string * fileName)
{
     void *fd;
     long size;
     
     pcsl_file_open(fileName, PCSL_FILE_O_RDONLY, &fd);
     size = pcsl_file_sizeofopenfile(fd);
     pcsl_file_close(fd);
     return size;
}
Exemplo n.º 4
0
/**
 * Gets the number of supported locales for device resources.
 *
 * @return the number of supported locales or 0 if something is wrong
 */
jint jsr238_get_resource_locales_count() {
    int res = 0;
    void *handle;

    REPORT_CALL_TRACE(LC_LOWUI, "LF:STUB:jsr238_get_resource_locales_count()\n");
    jsr238_file_open(JSR238_METAFILENAME, 0, &handle);
    if (handle != NULL) {
        while (jsr238_read_word(handle, NULL) >= 0) {
            res++;
        }
        pcsl_file_close(handle);
    }
    return res;
}
Exemplo n.º 5
0
/**
 * Checks if resource with given identifier exists.
 *
 * @param resource_id   resource identifier
 * @param locale_index  index of the locale
 * @return 1 if resource ID is valid and 0 if something is wrong
 */
jboolean jsr238_is_valid_resource_id(jint resource_id, jint locale_index) {
    ResourceTableEntryType entry;
    unsigned char buf[4];
    void * handle;
    jboolean res = PCSL_FALSE;

    REPORT_CALL_TRACE(LC_LOWUI, "LF:STUB:jsr238_is_valid_resource_id()\n");
    if (jsr238_devresource_file_open(locale_index, &handle) >= 0) {
        pcsl_file_read(handle, (char*)&ResourceFileHeader, 4);
        pcsl_file_read(handle, buf, 4);
        jsr238_fillInt(&ResourceFileHeader.headerLength, buf);
        res = jsr238_seekEntry(handle, resource_id, ResourceFileHeader.headerLength / 8, &entry);
        pcsl_file_close(handle);
    }

    return res;
}
Exemplo n.º 6
0
OsFile_Handle OsFile_open(const JvmPathChar *filename, const char *mode) {
  int name_len = fn_strlen(filename);
  pcsl_string pcsl_filename = PCSL_STRING_NULL;

  GUARANTEE(sizeof(jchar) == sizeof(JvmPathChar), "Types must match");

  if (pcsl_string_convert_from_utf16(filename, 
                                     name_len, 
                                     &pcsl_filename) != PCSL_STRING_OK) {
    return NULL;
  }

/*
  int pcsl_flags = (*mode == 'w') ? (PCSL_FILE_O_CREAT|PCSL_FILE_O_WRONLY|
                                     PCSL_FILE_O_TRUNC) :
                                    (PCSL_FILE_O_RDONLY);
*/

  int pcsl_flags;
  if(*mode == 'w') { 
    pcsl_flags = (PCSL_FILE_O_CREAT | PCSL_FILE_O_WRONLY | PCSL_FILE_O_TRUNC);
  } else if(*mode == 'a') {
    pcsl_flags = (PCSL_FILE_O_WRONLY | PCSL_FILE_O_APPEND);
  } else {
    pcsl_flags = PCSL_FILE_O_RDONLY;
  }

  void *pcsl_handle;
  if (pcsl_file_open(&pcsl_filename, pcsl_flags, &pcsl_handle) == 0) {
    pcsl_string_free(&pcsl_filename);
    OsFile_Handle handle =
      (OsFile_Handle)pcsl_mem_malloc(sizeof(struct _OsFile_Handle));
    if (handle) {
      handle->pcsl_handle = pcsl_handle;
    } else {
      pcsl_file_close(pcsl_handle);
    }
    return handle;
  } else {
    pcsl_string_free(&pcsl_filename);
    return NULL;
  }
}
Exemplo n.º 7
0
/*
 * Close a opened by storage_open. Does no block.
 *
 * If not successful *ppszError will set to point to an error string,
 * on success it will be set to NULL.
 */
void
storageClose(char** ppszError, int handle) {
    int status;

    *ppszError = NULL;
    status = pcsl_file_close((void *)handle);

    REPORT_INFO2(LC_CORE, "storageClose on file_desc %d returns %d\n",
          handle, status);

    if (status < 0) {
        *ppszError = getLastError("storageClose()");
    }

    /* File is successfully closed, decrement the count */
    if (midpDecResourceCount(RSC_TYPE_FILE, 1) == 0) {
        REPORT_INFO(LC_CORE, "FILE: resource"
                             " limit update error");
    }
}
Exemplo n.º 8
0
/**
 * Gets a resource for pointed resource identifier and locale.
 *
 * @param resource      buffer for the resource
 * @param res_len       length of the resource buffer
 * @param resource_id   resource identifier
 * @param locale_index  index of the locale
 * @return 0 in case successful operation and -1 if something is wrong
 */
JSR238_STATUSCODE jsr238_get_resource(jbyte* resource, jint res_len, jint resource_id, jint locale_index) {
    void * handle;
    ResourceTableEntryType entry;
    unsigned char buf[4];
    int res = JSR238_STATUSCODE_FAIL;

    REPORT_CALL_TRACE(LC_LOWUI, "LF:STUB:jsr238_get_resource()\n");
    if (jsr238_devresource_file_open(locale_index, &handle) >= 0)
    {
        pcsl_file_read(handle, (char*)&ResourceFileHeader, 4);
        pcsl_file_read(handle, buf, 4);
        jsr238_fillInt(&ResourceFileHeader.headerLength, buf);
        if (jsr238_seekEntry(handle, resource_id, ResourceFileHeader.headerLength / 8, &entry)){
            pcsl_file_seek(handle, entry.resourceOffset, 0);
            pcsl_file_read(handle, resource, res_len);
            res = JSR238_STATUSCODE_OK;
        }
        pcsl_file_close(handle);
    }
    return res;
}
Exemplo n.º 9
0
/**
 * Gets a locale name for device resources for the index.
 *
 * @param loc    buffer for the locale
 * @param index  index of the locale
 * @return 0 on success, -1 otherwise
 */
JSR238_STATUSCODE jsr238_get_resource_locale(jbyte* loc, jint index) {
    int res = 0;
    int i;
    void *handle;

    REPORT_CALL_TRACE(LC_LOWUI, "LF:STUB:jsr238_get_resource_locale()\n");
    jsr238_file_open(JSR238_METAFILENAME, 0, &handle);
    if (handle != NULL) {
        for (i = 0; i < index; i++) {
            res = jsr238_read_word(handle, NULL);
        }
        if (res >= 0) {
            res = jsr238_read_word(handle, loc);
            if (res > 0) {
                res = JSR238_STATUSCODE_OK;
            }
        } else {
            res = JSR238_STATUSCODE_FAIL;
        }

        pcsl_file_close(handle);
    }
    return res;
}
Exemplo n.º 10
0
int OsFile_close(OsFile_Handle handle) {
  int code = pcsl_file_close(handle->pcsl_handle);
  pcsl_mem_free((void*)handle);
  return code;
}
Exemplo n.º 11
0
/**
 * Tests for pcsl_file_get_attribute() and pcsl_file_set_attribute().
 */
void testAttributes() {
    int res;
    int fileID;
    int attr;

    res = pcsl_file_open(&file1, PCSL_FILE_O_RDWR | PCSL_FILE_O_TRUNC | PCSL_FILE_O_CREAT, (void **)&fileID);
    pcsl_file_close((void *)fileID);
    assertTrue("File creation failed", res == 0);

    /* All files are considered readable on win32 */
    res = pcsl_file_set_attribute(&file1, PCSL_FILE_ATTR_READ, 0);
    assertTrue("Attributes setting failed", res == 0);
    res = pcsl_file_get_attribute(&file1, PCSL_FILE_ATTR_READ, &attr);
    assertTrue("Attributes query failed", res == 0);
    assertTrue("File isn't reported as readable", attr == 1);

    res = pcsl_file_set_attribute(&file1, PCSL_FILE_ATTR_READ, 1);
    assertTrue("Attributes setting failed", res == 0);
    res = pcsl_file_get_attribute(&file1, PCSL_FILE_ATTR_READ, &attr);
    assertTrue("Attributes query failed", res == 0);
    assertTrue("File isn't reported as readable", attr == 1);

    res = pcsl_file_set_attribute(&file1, PCSL_FILE_ATTR_WRITE, 0);
    assertTrue("Attributes setting failed", res == 0);
    res = pcsl_file_get_attribute(&file1, PCSL_FILE_ATTR_WRITE, &attr);
    assertTrue("Attributes query failed", res == 0);
    assertTrue("Read-only file is reported as writable", attr == 0);

    res = pcsl_file_set_attribute(&file1, PCSL_FILE_ATTR_WRITE, 1);
    assertTrue("Attributes setting failed", res == 0);
    res = pcsl_file_get_attribute(&file1, PCSL_FILE_ATTR_WRITE, &attr);
    assertTrue("Attributes query failed", res == 0);
    assertTrue("Writable file is reported as read-only", attr == 1);

    /* All files are considered executable on win32 */
    res = pcsl_file_set_attribute(&file1, PCSL_FILE_ATTR_EXECUTE, 0);
    assertTrue("Attributes setting failed", res == 0);
    res = pcsl_file_get_attribute(&file1, PCSL_FILE_ATTR_EXECUTE, &attr);
    assertTrue("Attributes query failed", res == 0);
    assertTrue("File isn't reported as executable", attr == 1);

    res = pcsl_file_set_attribute(&file1, PCSL_FILE_ATTR_EXECUTE, 1);
    assertTrue("Attributes setting failed", res == 0);
    res = pcsl_file_get_attribute(&file1, PCSL_FILE_ATTR_EXECUTE, &attr);
    assertTrue("Attributes query failed", res == 0);
    assertTrue("File isn't reported as executable", attr == 1);

    res = pcsl_file_set_attribute(&file1, PCSL_FILE_ATTR_HIDDEN, 1);
    assertTrue("Attributes setting failed", res == 0);
    res = pcsl_file_get_attribute(&file1, PCSL_FILE_ATTR_HIDDEN, &attr);
    assertTrue("Attributes query failed", res == 0);
    assertTrue("File is reported as executable", attr == 1);

    res = pcsl_file_set_attribute(&file1, PCSL_FILE_ATTR_HIDDEN, 0);
    assertTrue("Attributes setting failed", res == 0);
    res = pcsl_file_get_attribute(&file1, PCSL_FILE_ATTR_HIDDEN, &attr);
    assertTrue("Attributes query failed", res == 0);
    assertTrue("File is reported as executable", attr == 0);

    pcsl_file_unlink(&file1);
}