Question

I have ported a very large application to Android. It receives binary data over TCP/IP, and writes it to files which it uses now and then in the application. The directory to which it saves the files is by default set to ./file_cache. It goes wrong here:

fileHandle = fopen(filename,"wb");

filename in this case is "file_i" where i starts from 0 and increments for every file.

The program crashes on writing, and it doesn't have to crash on the first file, sometimes it gets as far as the 10th file. When it crashes the fileHandle ends up as NULL.

The filename is initially in wchar, but is converted before (I print it out in the logger to confirm that it is correct).

What I have tried:

  • I have added all permissions that seem to have anything to do with file read/write external storage.

  • I have tried different locations /sdcard/files and /data/data/<package>/files

Questions:

  1. What is the current directory, i.e. where do the files really end up on the default setting?

  2. What can be causing fopen to return null, which in turn is the cause of the crash?

Very thankful for any ideas.

Was it helpful?

Solution

I found the problem, though it was a general program error. The filename "file_i" was due some complicated code being assigned size 1, which naturally was too small, causing the segmentation fault. So it had nothing to do with fopen. Actually, all segmentation faults I've had have been caused by a fault similar to this so it can be worth really scrutinizing your code whenever you are messing with char/wchar.

Moreover, I use the /data/data/.. folder which works fine, haven't actually tried the sdcard one but can't see why it would not work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top