Skip to content

Instantly share code, notes, and snippets.

@mondain mondain/j2c_string.c
Created Jan 14, 2020

Embed
What would you like to do?
JNI example of a java string into a c string
/* Java String to C String */
static int jstr_to_cstr(JNIEnv *env, jstring jstr, char *cstr) {
jsize jlen, clen;
clen = env->GetStringUTFLength(jstr);
jlen = env->GetStringLength(jstr);
env->GetStringUTFRegion(jstr, 0, jlen, cstr);
if (env->ExceptionCheck()) {
return -EIO;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.