diff options
author | pacien | 2018-02-10 14:16:15 +0100 |
---|---|---|
committer | pacien | 2018-02-10 14:16:15 +0100 |
commit | 87ec3620d2259064831356c2f4000ae591756fd2 (patch) | |
tree | 9312da1d357fdd3790d5b80af221653696b23089 /app/src/main/c/exec.c | |
parent | d1c39ba87bb32308c2d3a7a749abffeb773541ef (diff) | |
download | tincapp-87ec3620d2259064831356c2f4000ae591756fd2.tar.gz |
Reformat code
Diffstat (limited to 'app/src/main/c/exec.c')
-rw-r--r-- | app/src/main/c/exec.c | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/app/src/main/c/exec.c b/app/src/main/c/exec.c index fdaec0f..a9871a5 100644 --- a/app/src/main/c/exec.c +++ b/app/src/main/c/exec.c | |||
@@ -3,32 +3,32 @@ | |||
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | 4 | ||
5 | static inline const char **to_string_array(JNIEnv *env, jobjectArray ja) { | 5 | static inline const char **to_string_array(JNIEnv *env, jobjectArray ja) { |
6 | const int len = (*env)->GetArrayLength(env, ja); | 6 | const int len = (*env)->GetArrayLength(env, ja); |
7 | const char **ca = calloc((size_t) len + 1, sizeof(char *)); | 7 | const char **ca = calloc((size_t) len + 1, sizeof(char *)); |
8 | 8 | ||
9 | for (int i = 0; i < len; ++i) { | 9 | for (int i = 0; i < len; ++i) { |
10 | jstring jstr = (jstring) (*env)->GetObjectArrayElement(env, ja, i); | 10 | jstring jstr = (jstring) (*env)->GetObjectArrayElement(env, ja, i); |
11 | ca[i] = (*env)->GetStringUTFChars(env, jstr, NULL); | 11 | ca[i] = (*env)->GetStringUTFChars(env, jstr, NULL); |
12 | } | 12 | } |
13 | 13 | ||
14 | ca[len] = NULL; | 14 | ca[len] = NULL; |
15 | return ca; | 15 | return ca; |
16 | } | 16 | } |
17 | 17 | ||
18 | static inline void exec(const char **argcv) { | 18 | static inline void exec(const char **argcv) { |
19 | execv(argcv[0], (char *const *) argcv); | 19 | execv(argcv[0], (char *const *) argcv); |
20 | exit(1); | 20 | exit(1); |
21 | } | 21 | } |
22 | 22 | ||
23 | JNIEXPORT jint JNICALL | 23 | JNIEXPORT jint JNICALL |
24 | Java_org_pacien_tincapp_commands_Executor_forkExec(JNIEnv *env, jclass class, jobjectArray argcv) { | 24 | Java_org_pacien_tincapp_commands_Executor_forkExec(JNIEnv *env, jclass class, jobjectArray argcv) { |
25 | pid_t pid = fork(); | 25 | pid_t pid = fork(); |
26 | switch (pid) { | 26 | switch (pid) { |
27 | case 0: | 27 | case 0: |
28 | exec(to_string_array(env, argcv)); | 28 | exec(to_string_array(env, argcv)); |
29 | return 0; | 29 | return 0; |
30 | 30 | ||
31 | default: | 31 | default: |
32 | return pid; | 32 | return pid; |
33 | } | 33 | } |
34 | } | 34 | } |