| OLD | NEW |
| (Empty) |
| 1 #include "com_skia_SkiaIntentService.h" | |
| 2 | |
| 3 #include <stdint.h> | |
| 4 #include <stdio.h> | |
| 5 | |
| 6 extern int main(int argc, char * const argv[]); | |
| 7 | |
| 8 void cleanUp(JNIEnv* env, jobjectArray jstrs, const char** strs, int32_t count)
{ | |
| 9 for (int32_t i = 0; i < count; ++i) | |
| 10 env->ReleaseStringUTFChars( | |
| 11 (jstring) env->GetObjectArrayElement(jstrs, i), strs[i]); | |
| 12 } | |
| 13 | |
| 14 JNIEXPORT jint JNICALL Java_com_skia_SkiaIntentService_run( | |
| 15 JNIEnv* env, | |
| 16 jobject, | |
| 17 jobjectArray args) { | |
| 18 | |
| 19 // Convert command line arguments to C format. | |
| 20 int argc = env->GetArrayLength(args); | |
| 21 const char** argv = new const char*[argc]; | |
| 22 for (int32_t i = 0; i < argc; ++i) { | |
| 23 jstring str = (jstring) env->GetObjectArrayElement(args, i); | |
| 24 argv[i] = env->GetStringUTFChars(str, NULL); | |
| 25 if (NULL == argv[i]) { | |
| 26 cleanUp(env, args, argv, i - 1); | |
| 27 return 1; | |
| 28 } | |
| 29 } | |
| 30 | |
| 31 // Execute program main() | |
| 32 int retval = main(argc, (char* const*) argv); | |
| 33 | |
| 34 // Clean up temporaries and return the exit code. | |
| 35 cleanUp(env, args, argv, argc); | |
| 36 delete[] argv; | |
| 37 return retval; | |
| 38 } | |
| OLD | NEW |