Sujet : Re: how copy file on linux?
De : lew.pitcher (at) *nospam* digitalfreehold.ca (Lew Pitcher)
Groupes : comp.lang.cSuivi-à : comp.unix.programmerDate : 27. Jun 2024, 00:24:47
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v5i7vu$28id7$1@dont-email.me>
References : 1 2
User-Agent : Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2)
(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.
HTH
-- Lew Pitcher"In Skills We Trust"