示例#1
0
/**
 * Writes the contents of the given buffer into the given file.
 *
 * Note that if the length of the input buffer is zero or less,
 * the file will be truncated.
 *
 * @param ppszError pointer to character string pointer to accept an error
 * @param fileName file to write
 * @param inBuffer buffer with data that will be stored
 * @param inBufferLen length of the inBuffer
 *
 * @return status code (ALL_OK if there was no errors)
 */
MIDPError
write_file(char** ppszError, const pcsl_string* fileName,
           char* inBuffer, long inBufferLen) {
    int handle, status = ALL_OK;
    char* pszTemp;

    *ppszError  = NULL;

    /* open the file */
    handle = storage_open(ppszError, fileName, OPEN_WRITE);
    if (*ppszError != NULL) {
        return IO_ERROR;
    }

    /* write the whole buffer */
    if (inBufferLen > 0) {
        storageWrite(ppszError, handle, inBuffer, inBufferLen);
    } else {
        storageTruncate(ppszError, handle, 0);
    }

    if (*ppszError != NULL) {
        status = IO_ERROR;
    }

    /* close the file */
    storageClose(&pszTemp, handle);
    storageFreeError(pszTemp);

    return status;
}
示例#2
0
/**
 * Deletes content handler information from a registry.
 *
 * @param handler_id content handler ID
 * @return JSR211_OK if content handler unregistered successfully
 */
jsr211_result jsr211_unregister_handler(const pcsl_string* handler_id) {
  long current_position, file_size, buffer_size;
  int record_size;
  char *buffer;

  if (open_table_file(1) != JSR211_OK) {
    return JSR211_FAILED;
  }
  if (find_next_by_field(NULL, JSR211_FIELD_ID, handler_id, JSR211_TRUE,
                                                            find_exact) == -1) {
    close_table_file();
    return JSR211_FAILED;
  }
  
  storageRead(&io_error_message, table_file, (char *)&record_size, sizeof(int));
  current_position = storageRelativePosition(&io_error_message, table_file, 
                                                            -(long)sizeof(int));
  file_size = storageSizeOf(&io_error_message, table_file);
  goto_next_record();
  
  if (!(buffer = JSR211_MALLOC((buffer_size = file_size - current_position - 
                                                            record_size)))) {
    close_table_file();
    return JSR211_FAILED;
  }
  
  storageRead(&io_error_message, table_file, buffer, buffer_size);
  storagePosition(&io_error_message, table_file, current_position);
  storageWrite(&io_error_message, table_file, buffer, buffer_size);
  JSR211_FREE(buffer);
  storageTruncate(&io_error_message, table_file, current_position + 
                                                                   buffer_size);
  
  close_table_file();
  return JSR211_OK;
}