delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2007/09/20/20:17:14

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: "MikeC" <My_address AT end DOT of DOT post>
Newsgroups: comp.os.msdos.djgpp
Subject: How to copy a file?
Lines: 70
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138
Message-ID: <B1EIi.52071$rr5.11613@newsfe1-win.ntli.net>
Date: Fri, 21 Sep 2007 00:14:25 GMT
NNTP-Posting-Host: 86.13.147.52
X-Complaints-To: http://netreport.virginmedia.com
X-Trace: newsfe1-win.ntli.net 1190333665 86.13.147.52 (Fri, 21 Sep 2007 01:14:25 BST)
NNTP-Posting-Date: Fri, 21 Sep 2007 01:14:25 BST
Organization: ntl Cablemodem News Service
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Good people,

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.

I can't see any function included with DJGPP that will copy files, so I 
wrote one (copied below).
It copies 0x10000 byte buffers from the source file and dumps them to the 
destination file, and it works OK, but when copying a 10meg file from a 
network drive, it takes 2 min 19 secs, where a straight DOS copy takes 1 min 
9 secs.

I tried doing it with a system call, by putting "copy <source path> 
<destination path>" into a string, the executing
system(string);
- but it doesn't work, and I don't know why.

Here's the function I wrote, that works slowly

void file_copy(char *path_i, char *path_o)
{ FILE *fpi, *fpo;
  long bufsize = 0x10000;
  int f_handle;
  unsigned char buf[bufsize];
  long long file_len;
  struct ftime ft;

  fpi = fopen(path_i, "rb");
  fpo = fopen(path_o, "wb+");

  file_len = (long long)filelength(fileno(fpi));
  while(file_len > bufsize)
  { fread(buf, bufsize, 1, fpi);
    fwrite(buf, bufsize, 1, fpo);
    file_len -= bufsize;
  }
  fread(buf, file_len, 1, fpi);
  fwrite(buf, file_len, 1, fpo);

  f_handle = fileno(fpi);
  getftime(f_handle, &ft);

  fclose(fpi);
  fclose(fpo);

  fpo = fopen(path_o, "r");
  f_handle = fileno(fpo);
  setftime(f_handle, &ft);
  fclose(fpo);
}

Thanks,

MikeC

-- 
Mental decryption required to bamboozle spam robots:

mike_best$ntlworld*com
$ = @
* = dot 


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019