Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
56 user(s) are online (33 user(s) are browsing Forums)

Members: 0
Guests: 56

more...

Support us!

Headlines

 
  Register To Post  

Best way to copy a file in C?
Just can't stay away
Just can't stay away


See User information
I checked dos.library autodocs but couldn't spot a function to copy some file. Is there any ?

Go to top
Re: Best way to copy a file in C?
Just can't stay away
Just can't stay away


See User information
@Capehill
Quote:
I checked dos.library autodocs but couldn't spot a function to copy some file. Is there any ?
No.

Easiest way is probably something like
STRPTR cmd IUtility->ASPrintf("Copy CLONE BUFFER=32768 %s %s"sourcefilenamedestfilename);
if (
NULL == cmd)
{
   
error
} else {
   if (
!= IDOS->SystemTags(cmd, ...))
   {
      
error
   
}
   
IExec->FreeVec(cmd);
}

Or allocate a MEMF_SHARED buffer, for example 16 MB, fopen() source and dest files, fread()/fwrite() buffer size loop until done, fclose() source and dest files (or IDOS->FOpen()/FRead()/FWrite()/FClose() instead of the C library functions) and copy the protection bits, user/group and comment with IDOS->SetProtection(), IDOS->SetOwnerInfo() and IDOS->SetComment().

Go to top
Re: Best way to copy a file in C?
Not too shy to talk
Not too shy to talk


See User information
ask chatGPT, it knows Amiga stuff!

Go to top
Re: Best way to copy a file in C?
Just can't stay away
Just can't stay away


See User information
@joerg

Quote:
Or allocate a MEMF_SHARED buffer, for example 16 MB, fopen() source and dest files, fread()/fwrite() buffer size loop until done, fclose() source and dest files (or IDOS->FOpen()/FRead()/FWrite()/FClose() instead of the C library functions) and copy the protection bits, user/group and comment with IDOS->SetProtection(), IDOS->SetOwnerInfo() and IDOS->SetComment().
Don't forget to set/clone the datestamp as well.

Best regards,

Niels

Go to top
Re: Best way to copy a file in C?
Just can't stay away
Just can't stay away


See User information
@NinjaCyborg

Quote:
ask chatGPT, it knows Amiga stuff!
No need to mess with an AI when we have an RI (Jörg) at hand .

Best regards,

Niels

Go to top
Re: Best way to copy a file in C?
Not too shy to talk
Not too shy to talk


See User information
There's not AFAIK. I would have thought a copy function would be in place, to standardise this, with an optional hook to account for progress bars.

So there's only the old fashioned way. Open, read, write, rinse and repeat. Just using newer functions to examine file info. Not sure about being able to open file for write with specific attributes, to avoid resetting it later and causing wear.

Go to top
Re: Best way to copy a file in C?
Just can't stay away
Just can't stay away


See User information
@nbache
Quote:
Don't forget to set/clone the datestamp as well.
Yes, and there is something else I forgot to mention:
After opening the dest file and before the first write to it use IDOS->ChangeFileSize() to set the size of the dest file to the one of the source file. Requires using dos.library functions for everything instead of C library functions.
Using ChangeFileSize() minimizes the fragmentation of the new file, in best case it's just a single contiguous space, at least on SFS partitions that's important.
Even on SSD unfragmented files can be read and written much faster than fragmented ones.

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project