Page 1 of 1

Can't get (f)truncate working

Posted: Fri Aug 21, 2009 2:34 pm
by hamm
I want to reduce the size of a file without copying and tried the following.

Code: Select all

#include <nds.h>
#include <fat.h>
#include <stdio.h>
#include <unistd.h>

int main(void) {

fatInitDefault();
truncate("test.dat", 123);

while(1) {
      swiWaitForVBlank();
   }

   return 0;
} 
I also added -lfat in LIBS.

The problem is the filesize is the same like before after running the code.
Can anybody help me please?

Re: Can't get (f)truncate working

Posted: Fri Aug 21, 2009 4:20 pm
by Sylus101
I honestly don't know anything about that function... so I'm shooting in the dark here.

Did you test on hardware? That wouldn't work with an emulator.

Do you have to have opened the file perhaps first?

Re: Can't get (f)truncate working

Posted: Fri Aug 21, 2009 5:35 pm
by hamm
I tested it directly on the dsl hardware.

It's not necessary to open the file before. I tested it but it doesn't change anything.

Re: Can't get (f)truncate working

Posted: Fri Aug 21, 2009 7:40 pm
by elhobbs
if you are using ftruncate then may also need to use fsync to commit the changes to disk. didn't test this myself though...