fopen fails with errno = 13

3,573 views
Skip to first unread message

Heinrich Koutcherouk

unread,
Mar 12, 2012, 5:24:36 AM3/12/12
to android-ndk
Hello everydoby.

I'm trying to execute simple native code:

FILE * fout = fopen("/sdcard/foo.out","w");
if (fout==NULL)
{
char s[128];
sprintf(s,"errno = %d",errno);
return (*env)->NewStringUTF(env,s);
}

(this is just the prototype so the code is a bit awkward...)

fopen returns NULL and errno = 13, meaning there is a permission
problem.
I tried using adb to write a file at the location and it is writeable
indeed.
Anybody has a clue what might be the problem?

How do I check my application permissions?

Thanks,
Heinrich

Baodong Chen

unread,
Mar 12, 2012, 5:44:38 AM3/12/12
to andro...@googlegroups.com
On Mon, Mar 12, 2012 at 5:24 PM, Heinrich Koutcherouk
<pe.gad...@gmail.com> wrote:
> Hello everydoby.
>
> I'm trying to execute simple native code:
>
> FILE * fout = fopen("/sdcard/foo.out","w");
> if (fout==NULL)
> {
>        char s[128];
>        sprintf(s,"errno = %d",errno);
>        return (*env)->NewStringUTF(env,s);
> }
>
> (this is just the prototype so the code is a bit awkward...)
>
> fopen returns NULL and errno = 13, meaning there is a permission
> problem.
> I tried using adb to write a file at the location and it is writeable
> indeed.
> Anybody has a clue what might be the problem?
>
you should add <uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> to your
AndroidManifest.xml

> How do I check my application permissions?
>
> Thanks,
> Heinrich
>

> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
>

王老七

unread,
Aug 26, 2014, 10:07:40 PM8/26/14
to andro...@googlegroups.com, pe.gad...@gmail.com
hi, have you solved the problem?
I have the same question now.

在 2012年3月12日星期一UTC+8下午5时24分36秒,Heinrich Koutcherouk写道:
Reply all
Reply to author
Forward
0 new messages