Sujet : Re: how copy file on linux?
De : thiago.adams (at) *nospam* gmail.com (Thiago Adams)
Groupes : comp.unix.programmerDate : 27. Jun 2024, 01:40:06
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v5icd7$2d3iu$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
Em 6/26/2024 8:24 PM, Lew Pitcher escreveu:
(Followup set to comp.unix.programmer)
On Wed, 26 Jun 2024 15:35:00 -0700, Keith Thompson wrote:
Thiago Adams <thiago.adams@gmail.com> writes:
How to copy a file on linux keeping the original file information?
timestamp etc?
>
Or in other words the equivalent of CopyFileA from windows.
>
comp.unix.programmer is likely to give you better answers. I don't
think POSIX defines any functions that copy files.
No, AFAIK, POSIX doesn't define an "all-in-one" file copy function.
However, Linux (the OS Thiago asks about) defines a number of them.
If I uunderstand correctly, you want to do the equivalent of "cp -p",
Which /can/ be accomplished with POSIX calls
- the standard I/O functions (fopen()/open(), fread()/read(),
fwrite()/write(), fclose()/close() ) to copy the file data
- stat() to obtain the "original file information", and
- utime() to set the copy timestamps,
- chmod() to set the copy file permissions
- chown() to set the file ownership
But, perhaps Thiago would be satisfied with just a hardlinked file.
but from C rather than from a shell. You might consider using system(),
but that has some drawbacks, and there are probably better ways.
I am using this to create a "deploy" folder with all files necessary to run a program. So on windows I am coping dlls and I think it is a good idea to keep the original file attributes . (I am not sure if zip files keep that.. I need to check)
On linux I may need to copy some files and I think is is a good idea to keep the original attributes as well.