Mail Archives: djgpp/2007/09/21/02:34:44
MikeC wrote:
>
> I know this is probably a C question, but I'm asking it here
> because DJGPP is DOS-centric, and I'm trying to execute a system
> call. My question: What's the best way to copy a file?
>
> The file I want to copy is on a Unix server. Under DOS, if I try
> to cd to it, it gives an error message "UNC paths are not
> supported". I find that I can sense it OK with findfirst(), and
> I can do what I want, but I have a performance problem.
The slowest thing is the external network link, so you needn't
worry about the actual copying speed. Thus use a simple mechanism
(untested):
int fcopy(FILE *ffrom, FILE *fto) {
int ch;
while (EOF != (ch = getc(ffrom)) putc(ch);
return ch;
}
Now you can isolate the file opening in a controlling routine:
void pathcopy(char *infile, char *outfile) {
FILE *ffrom, *fto;
if (ffrom = fopen(infile, "r") {
if (fto = fopen(outfile, "w") fcopy(ffrom, fto); /* work */
else /* some error message about outfile */;
}
else {
/* some error message about infile */
fto = null;
}
if (ffrom) fclose(ffrom);
if (fto)
if (fclose(fto)) /* error message on fclose */;
}
All totally untested code. No buffers needed. The file system
does all necessary buffering automatically. The only thing needed
is the ability to describe the file paths.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com
- Raw text -