Skip to content

Commit

Permalink
maint: Reduce struct padding
Browse files Browse the repository at this point in the history
  • Loading branch information
andy5995 committed Nov 13, 2024
1 parent f5441fc commit b6da1fd
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 37 deletions.
11 changes: 7 additions & 4 deletions src/config_rmw.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ extern const char *expire_age_str;

typedef struct
{
char uid[10];
st_waste *st_waste_folder_props_head;
bool force_required;
int expire_age;
st_waste *st_waste_folder_props_head; // Pointer with high alignment requirements

int expire_age; // 4-byte alignment, placed next

bool force_required; // Minimal alignment, placed after the int
char uid[10]; // Character array, lower alignment, placed last
} st_config;


void print_config(FILE * restrict stream);

void
Expand Down
5 changes: 4 additions & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ struct st_loc
const char *home_dir;
const char *config_dir;
const char *config_file;

const char *data_dir;
const char *purge_time_file;
const char *mrl_file;
const st_dir *st_directory;

const st_dir *st_directory; // Pointer to another struct, placed at the end for clarity
};

12 changes: 8 additions & 4 deletions src/parse_cli_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/** CLI option switches for rmw. */
typedef struct
{
bool want_restore;
int want_purge;
int force;

/*! Alternate configuration file given at the command line with -c */
const char *alt_config_file;

bool want_restore;
bool want_empty_trash;
bool want_top_level_bypass;
bool want_orphan_chk;
bool want_selection_menu;
bool want_undo;
bool most_recent_list;
bool want_dry_run;
int force;

/*! list waste folder option */
bool list;
/*! Alternate configuration file given at the command line with -c */
const char *alt_config_file;
} rmw_options;



void init_rmw_options(rmw_options * options);

void
Expand Down
7 changes: 4 additions & 3 deletions src/time_rmw.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
typedef struct
{
char suffix_added_dup_exists[LEN_MAX_TIME_STR_SUFFIX];
time_t now; // Largest member, placed first to avoid alignment padding issues.
char deletion_date[LEN_MAX_DELETION_DATE]; // Grouped char arrays together.
char t_fmt[LEN_MAX_DELETION_DATE];
char deletion_date[LEN_MAX_DELETION_DATE];
time_t now;
char suffix_added_dup_exists[LEN_MAX_TIME_STR_SUFFIX];
} st_time;


void init_time_vars(st_time * st_time_var);

#endif
50 changes: 25 additions & 25 deletions src/trashinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,23 @@ struct st_waste
/** The parent directory, e.g. $HOME/.local/share/Trash */
char *parent;

/*! The info directory (where .trashinfo files are written) will be appended to the parent directory */
/** The info directory (where .trashinfo files are written) will be appended to the parent directory */
char *info;
int len_info;

/** Appended to the parent directory, where files are moved to when they are rmw'ed
*/
/** Appended to the parent directory, where files are moved to when they are rmw'ed */
char *files;
int len_files;

/** If a waste folder is at the top level, a relative path will be
* used (per the Freedesktop trash spec). See
* https://github.com/theimpossibleastronaut/rmw/issues/299 for more
* info */
char *media_root;

/** Points to the previous WASTE directory in the linked list */
st_waste *prev_node;

/** Points to the next WASTE directory in the linked list */
st_waste *next_node;

/** The device number of the filesystem on which the file resides. rmw does
* not copy files from one filesystem to another, but rather only moves them.
Expand All @@ -57,53 +66,44 @@ struct st_waste
*/
dev_t dev_num;

/** set to <tt>true</tt> if the parent directory is on a removable device,
int len_info;
int len_files;

/** Set to <tt>true</tt> if the parent directory is on a removable device,
* <tt>false</tt> otherwise.
*/
bool removable;

/*
* If a waste folder is at the top level, a relative path will be
* used (per the Freedesktop trash spec). See
https://github.com/theimpossibleastronaut/rmw/issues/299 for more
info */
char *media_root;

bool is_btrfs;

/** Points to the previous WASTE directory in the linked list
*/
st_waste *prev_node;

/** Points to the next WASTE directory in the linked list
*/
st_waste *next_node;
};


/** Holds information about a file that was specified for rmw'ing
*/
typedef struct
{
/** The absolute path to the file, stored later in a .trashinfo file */
char *real_path;

/** The basename of the target file, and used for the basename of it's corresponding
/** The basename of the target file, and used for the basename of its corresponding
* .trashinfo file */
const char *base_name;

/** The device number of the filesystem on which the file resides */
dev_t dev_num;

/** The destination file name. This may be different if a file of the same name already
* exists in the WASTE folder */
* exists in the WASTE folder */
char waste_dest_name[PATH_MAX];

dev_t dev_num;

/** Is <tt>true</tt> if the file exists in the destination WASTE/files folder,
* false otherwise. If it's a duplicate, a string based on the current time
* will be appended to \ref dest_name
*/
bool is_duplicate;
} rmw_target;


extern const char *lit_info;
extern const char *path_key;
extern const char *deletion_date_key;
Expand Down

0 comments on commit b6da1fd

Please sign in to comment.