0

I was wondering whether the calling of a libc function in a native function done via JNI with the Android NDK, e.g.

FILE* file = fopen("sdcard/hello.txt","w+");

is actually going directly to the actual libc function or whether there is some proxy/wrapper between the call and the native function.

Does anyone have an idea?

JoachimR
  • 5,150
  • 7
  • 45
  • 50

1 Answers1

0

It works as expected and no performance issues when I do that.

For your code, you need to add a / before sdcard though.

Getting the right path to you sdcard might be tricky:

How can I get external SD card path for Android 4.0+?

Community
  • 1
  • 1
Dannie
  • 2,430
  • 14
  • 16
  • how do you know that the function is called directly? I built a custom android emulator: I log in fopen.c when the function is called. When I do call it from my NDK App, nothing gets logged, on other occasions from the System, it does get logged. See http://stackoverflow.com/q/21136622/883083 – JoachimR Jan 18 '14 at 09:19
  • Directly means without going through the JVM? The NDK could have its own native implementation of `fopen`... – Dannie Jan 18 '14 at 10:27
  • Thanks for your help. Well with "directly" I meant that the App uid is the one that will be found when calling getuid() in fopen(). However it seems that fopen does not really get called. I looked for other declarations of fopen but no luck. There are similar methods like fopen (e.g. qemu_fopen() in external/qemu ) but all of them end up calling fopen() of stdio.h – JoachimR Jan 18 '14 at 12:39