ftwin 0.8.10
ft_file.c File Reference

Functions for file comparison, checksum calculation (XXH128), and I/O handling. More...

#include <apr_file_io.h>
#include <apr_mmap.h>
#include "checksum.h"
#include "debug.h"
#include "ft_file.h"
#include "ft_config.h"
Include dependency graph for ft_file.c:

Go to the source code of this file.

Functions

apr_status_t checksum_file (const char *filename, apr_off_t size, apr_off_t excess_size, ft_hash_t *hash_out, apr_pool_t *gc_pool)
 Calculates the XXH128 checksum of a file.
 
apr_status_t filecmp (apr_pool_t *pool, const char *fname1, const char *fname2, apr_off_t size, apr_off_t excess_size, int *result_out)
 Compares two files byte-by-byte to determine if they are identical.
 

Variables

static const size_t HUGE_LEN = 64 * 1024
 The chunk size for processing large files.
 

Detailed Description

Functions for file comparison, checksum calculation (XXH128), and I/O handling.

Definition in file ft_file.c.

Function Documentation

◆ checksum_file()

apr_status_t checksum_file ( const char *  filename,
apr_off_t  size,
apr_off_t  excess_size,
ft_hash_t hash_out,
apr_pool_t *  gc_pool 
)
extern

Calculates the XXH128 checksum of a file.

This function handles both small files (using memory-mapping for efficiency if possible) and large files (using buffered reading). The determination is based on the excess_size parameter.

Parameters
[in]filenameThe path to the file.
[in]sizeThe size of the file.
[in]excess_sizeThe file size threshold above which buffered reading is used instead of mmap.
[out]hash_outPointer to a ft_hash_t structure to store the resulting checksum.
[in]gc_poolAn APR pool for temporary allocations during the operation.
Returns
APR_SUCCESS on success, or an APR error code on failure.

Definition at line 134 of file ft_file.c.

◆ filecmp()

apr_status_t filecmp ( apr_pool_t *  pool,
const char *  fname1,
const char *  fname2,
apr_off_t  size,
apr_off_t  excess_size,
int *  result_out 
)
extern

Compares two files byte-by-byte to determine if they are identical.

This function intelligently chooses between memory-mapping for smaller files and buffered reading for larger files, based on the excess_size threshold.

Parameters
[in]poolThe APR pool to use for allocations.
[in]fname1The path to the first file.
[in]fname2The path to the second file.
[in]sizeThe size of the files (assumed to be identical).
[in]excess_sizeThe file size threshold to switch from mmap to buffered I/O.
[out]iPointer to an integer that will be set to 0 if the files are identical, or a non-zero value otherwise.
Returns
APR_SUCCESS on successful comparison, or an APR error code if a file cannot be read.

Definition at line 285 of file ft_file.c.

Referenced by ft_report_json().

Here is the caller graph for this function:

Variable Documentation

◆ HUGE_LEN

const size_t HUGE_LEN = 64 * 1024
static

The chunk size for processing large files.

This constant defines the size of the data chunk (in bytes) used for reading and comparing large files. Using a larger chunk size can improve I/O performance but will increase memory usage.

Definition at line 41 of file ft_file.c.