Is there a C function to copy f iles?? I hate to use a shell command in my
program in order to do it… anyone know??
ran zhang <rzhang@vamcointernational.com> wrote:
Is there a C function to copy f iles?? I hate to use a shell command in my
program in order to do it… anyone know??
No, there is no C function that does this.
cp is implemented as, essentially,
open(“file1”, …);
open(“file2”,…, O_CREAT);
while( read(fd1, buf, bytes) )
write(fd2, buf, bytes );
-David
QNX Training Services
dagibbs@qnx.com
David Gibbs <dagibbs@qnx.com> wrote:
ran zhang <> rzhang@vamcointernational.com> > wrote:
Is there a C function to copy f iles?? I hate to use a shell command in my
program in order to do it… anyone know??No, there is no C function that does this.
cp is implemented as, essentially,
open(“file1”, …);
open(“file2”,…, O_CREAT);
You would probably want O_TRUNC (or an unlink() first) here as well
while( read(fd1, buf, bytes) )
write(fd2, buf, bytes );
You might also want to maintain permissions. Do a stat() on the original, then use
chmod() and possibly chown() as well.
“Colin Burgess” <cburgess@qnx.com> wrote in message
news:9q4vt2$pq7$1@nntp.qnx.com…
David Gibbs <> dagibbs@qnx.com> > wrote:
ran zhang <> rzhang@vamcointernational.com> > wrote:
Is there a C function to copy f iles?? I hate to use a shell command
in my
program in order to do it… anyone know??No, there is no C function that does this.
cp is implemented as, essentially,
open(“file1”, …);
open(“file2”,…, O_CREAT);You would probably want O_TRUNC (or an unlink() first) here as well
while( read(fd1, buf, bytes) )
write(fd2, buf, bytes );You might also want to maintain permissions. Do a stat() on the original,
then use
chmod() and possibly chown() as well.Yes, do this. This is where most of thre work is. Dealing with the
directory enrty, permissions, links, etc.
Bill Caroselli