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 file size,
8 : * modification time (seconds and nanoseconds), and status change time (seconds and nanoseconds)
9 : *
10 : * The `CmpctStat` structure is designed to contain only the minimal necessary data
11 : * required for comparison purposes, making it significantly more space-efficient
12 : * compared to the full `struct stat`. This compact representation is particularly
13 : * advantageous when storing large amounts of file metadata in a database,
14 : * where storage optimization are critical.
15 : *
16 : * @param source A pointer to the source `struct stat` object containing the original file metadata
17 : * Must not be NULL. If NULL is provided, the function will fail
18 : * @param destination A pointer to the destination `CmpctStat` object where the selected
19 : * fields will be copied
20 : *
21 : */
22 2618 : Return stat_copy(
23 : const struct stat *source,
24 : CmpctStat *destination)
25 : {
26 2618 : Return status = SUCCESS;
27 :
28 2618 : if(source == NULL || destination == NULL)
29 : {
30 0 : provide(FAILURE);
31 : }
32 :
33 : /* Copying essential elements from the stat structure to the new one */
34 2618 : destination->st_size = source->st_size;
35 2618 : destination->mtim_tv_sec = source->st_mtim.tv_sec;
36 2618 : destination->mtim_tv_nsec = source->st_mtim.tv_nsec;
37 2618 : destination->ctim_tv_sec = source->st_ctim.tv_sec;
38 2618 : destination->ctim_tv_nsec = source->st_ctim.tv_nsec;
39 :
40 2618 : provide(status);
41 : }
|