X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f Message-ID: <46F35F0A.84D98A1E@yahoo.com> Date: Fri, 21 Sep 2007 02:04:58 -0400 From: CBFalconer Organization: Ched Research http://cbfalconer.home.att.net X-Mailer: Mozilla 4.75 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: How to copy a file? References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 53 NNTP-Posting-Date: 21 Sep 2007 05:30:20 GMT X-Complaints-To: abuse AT teranews DOT com X-Original-Lines: 50 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com 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. -- Posted via a free Usenet account from http://www.teranews.com