I am writing a program that improves file portability by merging multiple files into one (much like winzip/7zip).
My question is: is there any way that I can modify the unpacked files' file stats to match the ones before packing? (Not just times.)
The main directly changeable stats are user and group permissions, which you can change with the chmod
system call (consult the man page). Actual owner and group can be set with chown
(man page) - note that you can only change the owner, or change the group to one for whom the current user is not a member, if running as the superuser (i.e. root). The times can be set with utimes
(man). Extended file attributes (used for access control lists etc) can be set using setxattr
(man).
Other file attributes - number of hard links, inode, etc - cannot be set directly.
In any case, you will need to read the attributes of the file when you archive it, serialise them into your archive along with the file contents and other metadata, and use the system calls listed to restore them upon extraction.