FreeBSD/contrib/subversion/subversion/libsvn_fs_x/index.c
/* Create and open a packed number stream reading from offsets START to
 * END in FILE and return it in *STREAM.  Access the file in chunks of
 * BLOCK_SIZE bytes.  Expect the stream to be prefixed by STREAM_PREFIX.
 * Allocate *STREAM in RESULT_POOL and use SCRATCH_POOL for temporaries.
 */
Create and open a packed number stream reading from offsets START to
END in FILE and return it in *STREAM.  Access the file in chunks of
BLOCK_SIZE bytes.  Expect the stream to be prefixed by STREAM_PREFIX.
Allocate *STREAM in RESULT_POOL and use SCRATCH_POOL for temporaries.
Create and open a packed number stream reading from offsets START to END in FILE and return it in * STREAM . Access the file in chunks of BLOCK_SIZE bytes . Expect the stream to be prefixed by STREAM_PREFIX . Allocate * STREAM in RESULT_POOL and use SCRATCH_POOL for temporaries .
static svn_error_t *
packed_stream_open(svn_fs_x__packed_number_stream_t **stream,
                   apr_file_t *file,
                   apr_off_t start,
                   apr_off_t end,
                   const char *stream_prefix,
                   apr_size_t block_size,
                   apr_pool_t *result_pool,
                   apr_pool_t *scratch_pool)
{
  char buffer[STREAM_PREFIX_LEN + 1] = { 0 };
  apr_size_t len = strlen(stream_prefix);
  svn_fs_x__packed_number_stream_t *result;
  SVN_ERR_ASSERT(len < sizeof(buffer));
  SVN_ERR(svn_io_file_aligned_seek(file, block_size, NULL, start,
                                   scratch_pool));
  SVN_ERR(svn_io_file_read_full2(file, buffer, len, NULL, NULL,
                                 scratch_pool));
  if (strncmp(buffer, stream_prefix, len))
    return svn_error_createf(SVN_ERR_FS_INDEX_CORRUPTION, NULL,
                             _("Index stream header prefix mismatch.\n"
                               "  expected: %s"
                               "  found: %s"), stream_prefix, buffer);
  result = apr_palloc(result_pool, sizeof(*result));
  result->pool = result_pool;
  result->file = file;
  result->stream_start = start + len;
  result->stream_end = end;
  result->used = 0;
  result->current = 0;
  result->start_offset = result->stream_start;
  result->next_offset = result->stream_start;
  result->block_size = block_size;
  *stream = result;
  return SVN_NO_ERROR;
}
static svn_error_t * packed_stream_open ( svn_fs_x__packed_number_stream_t * * stream , apr_file_t * file , apr_off_t start , apr_off_t end , const char * stream_prefix , apr_size_t block_size , apr_pool_t * result_pool , apr_pool_t * scratch_pool ) { char buffer [ STREAM_PREFIX_LEN + 1 ] = { 0 } ; apr_size_t len = strlen ( stream_prefix ) ; svn_fs_x__packed_number_stream_t * result ; SVN_ERR_ASSERT ( len < sizeof ( buffer ) ) ; SVN_ERR ( svn_io_file_aligned_seek ( file , block_size , NULL , start , scratch_pool ) ) ; SVN_ERR ( svn_io_file_read_full2 ( file , buffer , len , NULL , NULL , scratch_pool ) ) ; if ( strncmp ( buffer , stream_prefix , len ) ) return svn_error_createf ( SVN_ERR_FS_INDEX_CORRUPTION , NULL , _ ( " \n " " " " " ) , stream_prefix , buffer ) ; result = apr_palloc ( result_pool , sizeof ( * result ) ) ; result -> pool = result_pool ; result -> file = file ; result -> stream_start = start + len ; result -> stream_end = end ; result -> used = 0 ; result -> current = 0 ; result -> start_offset = result -> stream_start ; result -> next_offset = result -> stream_start ; result -> block_size = block_size ; * stream = result ; return SVN_NO_ERROR ; }
Create and open a packed number stream reading from offsets START to
 END in FILE and return it in *STREAM.
Create and open a packed number stream reading from offsets START to END in FILE and return it in * STREAM .
/* If this is violated, we forgot to adjust STREAM_PREFIX_LEN after
   * changing the index header prefixes. */ /* Read the header prefix and compare it with the expected prefix */ /* Construct the actual stream object. */