Android的NDK崩溃读/写文件时 [英] Android NDK crash when reading/writing files

查看:449
本文介绍了Android的NDK崩溃读/写文件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经移植了非常大的应用程序到Android。它通过TCP / IP接收的二进制数据,并将其写入到它现在,然后使用在应用程序的文件。它所保存文件的目录默认设置为./file_cache。它去错在这里:

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");

文件名,在这种情况下是file_i在那里我从0递增启动每个文件。

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

在编写程序崩溃,并且它没有崩溃的第一个文件,有时远至10日文件获取。当它崩溃的文件句柄最终为NULL。

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.

的文件名是最初在WCHAR,但(我打印出来的记录,以确认它是正确的)之前被转换。

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

我曾尝试:


  • 我补充说,似乎有什么做的所有权限
    文件的读/写外部存储。

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

我曾尝试不同的位置/ SD卡/文件和
/数据/数据​​/<包装及GT; /文件

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

问题:


  1. 什么是当前目录,即你在哪里的文件确实结束
    在默认设置?

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

有什么可以引起的fopen返回NULL,这又是飞机坠毁的原因是什么?

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

有任何想法非常感谢。

推荐答案

我发现这个问题,虽然这是一个一般的程序错误。文件名file_i,是由于一些复杂的code被分配大小为1,这自然太小,造成分段错误。所以它有无关的fopen。实际上,所有的分割故障我有已经被一个类似的故障引起的,因此它可以是真正值得你的审议code,只要你用炭/ WCHAR搞乱。

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.

此外,我用的/数据/数据​​/ ..文件夹中的正常工作,有没有真正尝试过的SD卡一个,但不明白为什么它是行不通的。

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.

这篇关于Android的NDK崩溃读/写文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆