Branch data Line data Source code
1 : : #include "precizer.h"
2 : :
3 : : /**
4 : : * @brief Copies essential elements from a `struct stat` to a `CmpctStat` structure
5 : : *
6 : : * This function performs a selective copy of key fields from the source `struct stat`
7 : : * object to the destination `CmpctStat` object. The copied fields include logical
8 : : * file size, allocated block count, device/inode identifiers, modification time
9 : : * (seconds and nanoseconds), and status change time (seconds and nanoseconds)
10 : : *
11 : : * The `CmpctStat` structure is designed to contain only the minimal necessary data
12 : : * required for comparison purposes, making it significantly more space-efficient
13 : : * compared to the full `struct stat`. This compact representation is particularly
14 : : * advantageous when storing large amounts of file metadata in a database,
15 : : * where storage optimization are critical.
16 : : *
17 : : * @param source A pointer to the source `struct stat` object containing the original file metadata
18 : : * Must not be NULL. If NULL is provided, the function will fail
19 : : * @param destination A pointer to the destination `CmpctStat` object where the selected
20 : : * fields will be copied
21 : : *
22 : : */
23 : 3870 : Return stat_copy(
24 : : const struct stat *source,
25 : : CmpctStat *destination)
26 : : {
27 : : /* Status returned by this function through provide()
28 : : Default value assumes successful completion */
29 : 3870 : Return status = SUCCESS;
30 : :
31 [ + - - + ]: 3870 : if(source == NULL || destination == NULL)
32 : : {
33 : 0 : provide(FAILURE);
34 : : }
35 : :
36 : : /* Copying essential elements from the stat structure to the new one */
37 : 3870 : destination->st_size = source->st_size;
38 : 3870 : destination->st_blocks = source->st_blocks;
39 : 3870 : destination->st_dev = source->st_dev;
40 : 3870 : destination->st_ino = source->st_ino;
41 : 3870 : destination->mtim_tv_sec = source->st_mtim.tv_sec;
42 : 3870 : destination->mtim_tv_nsec = source->st_mtim.tv_nsec;
43 : 3870 : destination->ctim_tv_sec = source->st_ctim.tv_sec;
44 : 3870 : destination->ctim_tv_nsec = source->st_ctim.tv_nsec;
45 : :
46 : 3870 : provide(status);
47 : : }
|