Hi,
I'm using Build r1000.
It seems to me, that the MAfs Library is missing unlink() to delete a file.
Additionally, fflush() is referenced in the .h file but not implemented, as it seems (at least a stub that returns 0 would be desirable).
So I implemented by own version of unlink, which basically just truncates the file (any better ideas?):
// MoSync doesn't have unlink, so we truncate the file by opening it.
int unlink(const char *pszFile)
{
FILE *fp = fopen(pszFile, "w");
if (fp)
{
fclose(fp);
return 0;
}
return 1;
}
Now it seems to me that the FS library has a bug on handling 0 byte files and gets stuck on fwrite.
Here are my assumptions about the things happening:
File.c:
static MA_FILE* openReadWrite(const char *filename, int modeFlags) {
...
if(modeFlags&(MODE_READ|MODE_APPEND)) {
data = maCreatePlaceholder();
maReadStore(store, data);
realLength = size = maGetDataSize(data); // size = 0 on 0 byte files?
}
...
file->bufferStart = 0;
file->bufferSize = size;
}Now on fwrite:
size_t MA_fwrite ( const void * ptr, size_t size, size_t count, MA_FILE * stream) {
...
int lastBufferSize = stream->bufferSize;
while(stream->filePtr+bytesToWrite > vol->dataOffset+stream->bufferSize) stream->bufferSize<<=1;
...
}0<<1 = 0<<1 = 0<<1 = 0<<1 = 0...
Seems buggy to me. Is this a real bug or are my assumptions wrong? Nevertheless, it hangs here in fwrite and loops forever.
Regards,
Ludwig