Skip to content

Instantly share code, notes, and snippets.

@mondain
Created January 14, 2020 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mondain/9ba53a100019406d29dd1299819013d5 to your computer and use it in GitHub Desktop.
Save mondain/9ba53a100019406d29dd1299819013d5 to your computer and use it in GitHub Desktop.
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