Author: CBFalconerCBFalconer Date: May 28, 2007 17:57
Avi wrote:
>
> Is there a UNIX C system command that will let me copy a file? I
> am looking for something similar to "cp" that can be called within
> a C program. I know of the "link" system call but this command
> will set a the second file as a link to the first file rather than
> an independent copy of the first file.
> (Windows has the CopyFile command but I didn't find anything that
> would work under UNIX)
>
> I am also looking for C commands to move files. Is the C system
> call "rename" equivalent to Window's specific MoveFileEx function?
So write them. They are very simple. For example, to copy a file:
/* first open the files in the calling function */
void fcopy(FILE *fromf, FILE *destf) {
int ch;
while (EOF != (ch = getc(fromf))) putc(ch, destf);
} /* untested */
/* now close both files */
|