diff options
Diffstat (limited to 'utils/nwztools/plattools/nwz_lib.c')
-rw-r--r-- | utils/nwztools/plattools/nwz_lib.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/utils/nwztools/plattools/nwz_lib.c b/utils/nwztools/plattools/nwz_lib.c index 4f49bec909..087db8834a 100644 --- a/utils/nwztools/plattools/nwz_lib.c +++ b/utils/nwztools/plattools/nwz_lib.c | |||
@@ -30,7 +30,7 @@ const char *nwz_get_model_name(unsigned long model_id) | |||
30 | return NULL; | 30 | return NULL; |
31 | } | 31 | } |
32 | 32 | ||
33 | void nwz_run(const char *file, const char *args[], bool wait) | 33 | int nwz_run(const char *file, const char *args[], bool wait) |
34 | { | 34 | { |
35 | pid_t child_pid = fork(); | 35 | pid_t child_pid = fork(); |
36 | if(child_pid != 0) | 36 | if(child_pid != 0) |
@@ -39,7 +39,10 @@ void nwz_run(const char *file, const char *args[], bool wait) | |||
39 | { | 39 | { |
40 | int status; | 40 | int status; |
41 | waitpid(child_pid, &status, 0); | 41 | waitpid(child_pid, &status, 0); |
42 | return status; | ||
42 | } | 43 | } |
44 | else | ||
45 | return 0; | ||
43 | } | 46 | } |
44 | else | 47 | else |
45 | { | 48 | { |
@@ -48,6 +51,40 @@ void nwz_run(const char *file, const char *args[], bool wait) | |||
48 | } | 51 | } |
49 | } | 52 | } |
50 | 53 | ||
54 | char *nwz_run_pipe(const char *file, const char *args[], int *status) | ||
55 | { | ||
56 | int pipe_fds[2]; | ||
57 | pipe(pipe_fds); | ||
58 | pid_t child_pid = fork(); | ||
59 | if(child_pid == 0) | ||
60 | { | ||
61 | dup2(pipe_fds[1], 1); /* redirect stdout */ | ||
62 | dup2(pipe_fds[1], 2); /* redirect stderr */ | ||
63 | close(pipe_fds[0]); /* close reading */ | ||
64 | close(pipe_fds[1]); /* close writing */ | ||
65 | execvp(file, (char * const *)args); | ||
66 | _exit(1); | ||
67 | } | ||
68 | else | ||
69 | { | ||
70 | close(pipe_fds[1]); /* close writing */ | ||
71 | char buffer[1024]; | ||
72 | char *output = malloc(1); | ||
73 | ssize_t count; | ||
74 | size_t size = 0; | ||
75 | while((count = read(pipe_fds[0], buffer, sizeof(buffer))) > 0) | ||
76 | { | ||
77 | output = realloc(output, size + count + 1); | ||
78 | memcpy(output + size, buffer, count); | ||
79 | size += count; | ||
80 | } | ||
81 | close(pipe_fds[0]); | ||
82 | output[size] = 0; | ||
83 | waitpid(child_pid, status, 0); | ||
84 | return output; | ||
85 | } | ||
86 | } | ||
87 | |||
51 | void nwz_lcdmsg(bool clear, int x, int y, const char *msg) | 88 | void nwz_lcdmsg(bool clear, int x, int y, const char *msg) |
52 | { | 89 | { |
53 | const char *path_lcdmsg = "/usr/local/bin/lcdmsg"; | 90 | const char *path_lcdmsg = "/usr/local/bin/lcdmsg"; |