Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!ccu.umanitoba.ca!umochock From: umochock@ccu.umanitoba.ca (Russell Ochocki) Newsgroups: comp.sys.atari.st.tech Subject: Problem with my C program to copy files between floppies Message-ID: <1991Apr21.210056.5685@ccu.umanitoba.ca> Date: 21 Apr 91 21:00:56 GMT Organization: University of Manitoba, Winnipeg, Canada Lines: 43 For my first useful C program on my STe, I wrote a program to copy files from one disk to another. I was tired of using a ram disk every time I wanted to copy a file to a different disk (since I have only one disk drive). I'm using Sozobon C with gulam as my shell. I try to Malloc a buffer equal to the size of the file being copyied. Then I do a Fread from the source file, prompt the user to swap disks, fopen the destination file, and Fwrite the contents of the buffer. And, fclose both files. Note: I needed to use Malloc, Fread, and Fwrite since I required long ints (not the short expected by malloc, fread, and fwrite). If I can't Malloc the space I need, I try to Malloc 1/2 as much, and then Fread the first half, Fwrite the first half, Fread the last half (and this is where my problem is), and Fwrite the last half. (I do it in two passes.) I tested the thing to death and it works under the following situations: o Copy a file that is smaller than available memory (i.e. only one disk swap needed). o Copy a file larger than available memory from a ram disk to drive a:. This works with two or even 10 swaps. The swapping is simulated here but does verify that my code to read and write the file in as many pieces as needed works just fine. It doesn't work when you: o Copy a file from disk to disk than requires two or more passes. The second Fread on the source file returns 0 bytes read. Checked ferror but it is also zero. So (and here's my point), I have two files open simulatiously, both in drive a:, but on different disks. And the ST does not seem to like it. Anyone ever try this? Does TOS allow this? Or, is it a bug in my program? Any help would be appreciated. -- | | \/ Russell Ochocki, University of Manitoba | _/\_ Winnipeg, Manitoba, Canada (umochock@ccu.umanitoba.ca) |