Пример #1
0
long OsFile_seek(OsFile_Handle handle, long offset, int origin) {
  switch (origin) {
  case SEEK_END: origin = PCSL_FILE_SEEK_END; break;
  case SEEK_SET: origin = PCSL_FILE_SEEK_SET; break;
  case SEEK_CUR: origin = PCSL_FILE_SEEK_CUR; break;
  }
  return pcsl_file_seek(handle->pcsl_handle, offset, origin);
}
Пример #2
0
/**
 * The write function writes up to size bytes from buffer to the file 
 * with descriptor  identifier. 
 * The return value is the number of bytes actually written. 
 * This is normally the same as size, but might be less (for example, 
 * if the persistent storage being written to fills up).
 */
int pcsl_file_write(void *handle, unsigned char* buffer, long length)
{
    DWORD bytesWritten;
    PCSLFile* pFH = (PCSLFile*)handle;
    if (NULL == handle)
        return -1;

    if (PCSL_FILE_O_APPEND == (pFH->createFlags && PCSL_FILE_O_APPEND)) {
        if (!pcsl_file_seek(handle, 0, PCSL_FILE_SEEK_END))
            return -1;
    }

    if (!WriteFile(pFH->fileHandle, buffer, (DWORD)length, &bytesWritten, NULL))
        return -1;
    return bytesWritten;
}
Пример #3
0
/*
 * Change the read/write position of an open file in storage.
 * The position is a number of bytes from beginning of the file.
 *
 * If not successful *ppszError will set to point to an error string,
 * on success it will be set to NULL.
 */
void
storagePosition(char** ppszError, int handle, long absolutePosition) {
    long newPosition;

    newPosition = pcsl_file_seek((void *)handle, absolutePosition,
                                  PCSL_FILE_SEEK_SET);

    REPORT_INFO2(LC_CORE, "storagePostion on fd %d res = %d\n",
          handle, newPosition);

    if (-1 == newPosition) {
        *ppszError = getLastError("storagePosition()");
        return;
    }

    *ppszError = NULL;
}
Пример #4
0
/*
 * Change the read/write position of an open file in storage.
 * The position is a number of bytes from current position.
 *
 * If not successful *ppszError will set to point to an error string,
 * on success it will be set to NULL.
 *
 * @return new absolute read/write position
 */
long
storageRelativePosition(char** ppszError, int handle, long offset) {
    long newPosition;

    newPosition = pcsl_file_seek((void *)handle, offset, PCSL_FILE_SEEK_CUR);

    REPORT_INFO2(LC_CORE, "storageRelativePostion on fd %d res = %d\n",
         handle, newPosition);

    if (-1 == newPosition) {
        *ppszError = getLastError("storageRelativePosition()");
        return -1;
    }

    *ppszError = NULL;

    return newPosition;
}
Пример #5
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;
}