We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello,
I have trouble writing an file-copy function. My fcopy-function should read data from a file into a buffer, then write the buffer to another file.
It works fine for several times in succession (see test_fcopy), but then the sourcefile suddenly can't be opend (fopen returns 0x00).
Heap size is 0x10000 (wich is very big, I guess). Any ideas?
Marco
int test_fcopy() { int rc; int i; for(i=0;i<100;i++) { rc = fcopy("F:dest.txt", "F:source.txt"); if(rc != FILESYSTEM_OK) { //rc != FILESYSTEM_OK after 10 cycles, //depending on file size break; } } } int fcopy(char *destinationfile, char *sourcefile) { #define COPY_BYTES 512 char copy_data[COPY_BYTES]; FILE *dest; FILE *source; int c_read; int c_write; int rc; rc = FILESYSTEM_OK; //open source file for reading source = fopen (sourcefile, "r"); //open destination file for writing dest = fopen (destinationfile, "w"); if((source) && (dest)) {//if both files could be opend while (!feof (source)) { //read bytes from source file to ram c_read = fread((void*)©_data, 1, COPY_BYTES, source); //write bytes from ram to destination file c_write = fwrite((void*)©_data, 1, c_read, dest); if(c_read != c_write) { rc = FILESYSTEM_ERROR; } } //Close files fclose(source); fclose(dest); } else { rc = FILESYSTEM_ERROR; } return(rc); }
Hi Per,
I certainly assume that the fdelete() function works for all drives, right? It returns 0, so no error occured. The FlashFS manages the deleting of blocks a.s.o.
Hope I'm right ...