190 |
char * |
char * |
191 |
external_program(int *rs, char *path, char *src, char *dst, int dstsize) |
external_program(int *rs, char *path, char *src, char *dst, int dstsize) |
192 |
{ |
{ |
193 |
int status; |
char *ret; |
|
int fd; |
|
|
int n; |
|
194 |
char tmp[LINEBUFFER+1]; |
char tmp[LINEBUFFER+1]; |
|
char *buf = 0; |
|
195 |
char **args = 0; |
char **args = 0; |
196 |
char *a = 0; /* args */ |
char *a = 0; /* args */ |
197 |
char *p = 0; /* path */ |
char *p = 0; /* path */ |
216 |
else |
else |
217 |
a = path; |
a = path; |
218 |
} |
} |
219 |
|
|
220 |
args = gen_execargs(a); |
args = gen_execargs(a); |
221 |
fd = make_local_connection(p, args); |
ret = exec_argv(rs, args, src, dst, dstsize); |
222 |
xfree_pptr(args); |
xfree_pptr(args); |
223 |
|
return ret; |
224 |
|
} |
225 |
|
|
226 |
|
char * |
227 |
|
exec_argv(int *rs, char **argv, char *src, char *dst, int dstsize) |
228 |
|
{ |
229 |
|
int status; |
230 |
|
int fd; |
231 |
|
int n; |
232 |
|
char *buf; |
233 |
|
|
234 |
|
fd = make_local_connection(argv[0], argv); |
235 |
if (fd == -1) { |
if (fd == -1) { |
236 |
*rs = -1; |
*rs = -1; |
237 |
return 0; |
return 0; |
250 |
memset(dst, 0, dstsize); |
memset(dst, 0, dstsize); |
251 |
|
|
252 |
if (dst && dstsize) { /* static array */ |
if (dst && dstsize) { /* static array */ |
253 |
while ((n = read(fd, buf, DATABUFFER)) > 0) |
while ((n = read(fd, buf, DATABUFFER)) > 0) { |
|
{ |
|
254 |
strncat(dst, buf, dstsize); |
strncat(dst, buf, dstsize); |
255 |
memset(buf, 0, DATABUFFER + 1); |
memset(buf, 0, DATABUFFER + 1); |
256 |
dstsize -= n; |
dstsize -= n; |
257 |
if (dstsize < 1) |
if (dstsize < 1) |
258 |
break; |
break; |
259 |
} |
} |
260 |
} |
} else { /* dynamic array */ |
|
else { /* dynamic array */ |
|
261 |
dst = (char *)xmalloc(1); |
dst = (char *)xmalloc(1); |
262 |
while ((n = read(fd, buf, DATABUFFER)) > 0) |
while ((n = read(fd, buf, DATABUFFER)) > 0) { |
263 |
{ |
dst = xrealloc(dst, strlen(dst) + n + 1); |
|
dst = (char *)xrealloc((char *)dst, strlen(dst) + n + 1); |
|
264 |
strncat(dst, buf, n); |
strncat(dst, buf, n); |
265 |
memset(buf, 0, DATABUFFER + 1); |
memset(buf, 0, DATABUFFER + 1); |
266 |
} |
} |