Looking for a C system call to copy files
  Home FAQ Contact Sign in
comp.lang.c only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.c Profile…
 Up
Looking for a C system call to copy files         


Author: Avi
Date: May 28, 2007 16:34

Hi,

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?

Thanks,
Avner Moshkovitz
Research Analyst
Email: amoshkov@mda.ca
3 Comments
Re: Looking for a C system call to copy files         


Author: Ian Collins
Date: May 28, 2007 16:44

Avi wrote:
> Hi,
>
> 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?
>
comp.unix.programmer would be a better place for these questions. The
only standard C way would be to use the system() function to invoke the
appropriate commands.
Show full article (0.75Kb)
no comments
Re: Looking for a C system call to copy files         


Author: Richard Heathfield
Date: May 28, 2007 17:04

Avi said:
> Hi,
>
> 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.

#include

#define COPYFILE_OK 0
#define COPYFILE_READ_ERROR 1
#define COPYFILE_WRITE_ERROR 2
#define COPYFILE_OUTCLOSE_ERROR 4
#define COPYFILE_OUTOPEN_ERROR 8
#define COPYFILE_INCLOSE_ERROR 16
#define COPYFILE_INOPEN_ERROR 32
Show full article (1.98Kb)
no comments
Re: Looking for a C system call to copy files         


Author: CBFalconer
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 */
Show full article (1.28Kb)
no comments