Lines Matching refs:obj
56 struct pex_obj *obj; in pex_init_common() local
58 obj = XNEW (struct pex_obj); in pex_init_common()
59 obj->flags = flags; in pex_init_common()
60 obj->pname = pname; in pex_init_common()
61 obj->tempbase = tempbase; in pex_init_common()
62 obj->next_input = STDIN_FILE_NO; in pex_init_common()
63 obj->next_input_name = NULL; in pex_init_common()
64 obj->next_input_name_allocated = 0; in pex_init_common()
65 obj->stderr_pipe = -1; in pex_init_common()
66 obj->count = 0; in pex_init_common()
67 obj->children = NULL; in pex_init_common()
68 obj->status = NULL; in pex_init_common()
69 obj->time = NULL; in pex_init_common()
70 obj->number_waited = 0; in pex_init_common()
71 obj->input_file = NULL; in pex_init_common()
72 obj->read_output = NULL; in pex_init_common()
73 obj->read_err = NULL; in pex_init_common()
74 obj->remove_count = 0; in pex_init_common()
75 obj->remove = NULL; in pex_init_common()
76 obj->funcs = funcs; in pex_init_common()
77 obj->sysdep = NULL; in pex_init_common()
78 return obj; in pex_init_common()
84 pex_add_remove (struct pex_obj *obj, const char *name, int allocated) in pex_add_remove() argument
88 ++obj->remove_count; in pex_add_remove()
89 obj->remove = XRESIZEVEC (char *, obj->remove, obj->remove_count); in pex_add_remove()
94 obj->remove[obj->remove_count - 1] = add; in pex_add_remove()
103 temp_file (struct pex_obj *obj, int flags, char *name) in temp_file() argument
107 if (obj->tempbase == NULL) in temp_file()
113 int len = strlen (obj->tempbase); in temp_file()
117 && strcmp (obj->tempbase + len - 6, "XXXXXX") == 0) in temp_file()
118 name = xstrdup (obj->tempbase); in temp_file()
120 name = concat (obj->tempbase, "XXXXXX", NULL); in temp_file()
138 if (obj->tempbase == NULL) in temp_file()
141 name = concat (obj->tempbase, name, NULL); in temp_file()
152 pex_run_in_environment (struct pex_obj *obj, int flags, const char *executable, in pex_run_in_environment() argument
172 if (obj->input_file) in pex_run_in_environment()
174 if (fclose (obj->input_file) == EOF) in pex_run_in_environment()
179 obj->input_file = NULL; in pex_run_in_environment()
184 if (obj->next_input_name != NULL) in pex_run_in_environment()
188 if (!pex_get_status_and_time (obj, 0, &errmsg, err)) in pex_run_in_environment()
191 in = obj->funcs->open_read (obj, obj->next_input_name, in pex_run_in_environment()
199 if (obj->next_input_name_allocated) in pex_run_in_environment()
201 free (obj->next_input_name); in pex_run_in_environment()
202 obj->next_input_name_allocated = 0; in pex_run_in_environment()
204 obj->next_input_name = NULL; in pex_run_in_environment()
208 in = obj->next_input; in pex_run_in_environment()
225 outname = concat (obj->tempbase, outname, NULL); in pex_run_in_environment()
228 obj->next_input = -1; in pex_run_in_environment()
230 else if ((obj->flags & PEX_USE_PIPES) == 0) in pex_run_in_environment()
232 outname = temp_file (obj, flags, outname); in pex_run_in_environment()
243 if ((obj->flags & PEX_SAVE_TEMPS) == 0) in pex_run_in_environment()
245 pex_add_remove (obj, outname, outname_allocated); in pex_run_in_environment()
250 obj->next_input_name = outname; in pex_run_in_environment()
251 obj->next_input_name_allocated = outname_allocated; in pex_run_in_environment()
256 if (obj->funcs->pipe (obj, p, (flags & PEX_BINARY_OUTPUT) != 0) < 0) in pex_run_in_environment()
264 obj->next_input = p[READ_PORT]; in pex_run_in_environment()
269 out = obj->funcs->open_write (obj, outname, in pex_run_in_environment()
295 if (obj->stderr_pipe != -1) in pex_run_in_environment()
306 if (obj->funcs->pipe (obj, p, (flags & PEX_BINARY_ERROR) != 0) < 0) in pex_run_in_environment()
314 obj->stderr_pipe = p[READ_PORT]; in pex_run_in_environment()
323 errdes = obj->funcs->open_write (obj, errname, in pex_run_in_environment()
337 if ((obj->flags & PEX_USE_PIPES) == 0) in pex_run_in_environment()
340 toclose = obj->next_input; in pex_run_in_environment()
344 pid = obj->funcs->exec_child (obj, flags, executable, argv, env, in pex_run_in_environment()
349 ++obj->count; in pex_run_in_environment()
350 obj->children = XRESIZEVEC (pid_t, obj->children, obj->count); in pex_run_in_environment()
351 obj->children[obj->count - 1] = pid; in pex_run_in_environment()
357 obj->funcs->close (obj, in); in pex_run_in_environment()
359 obj->funcs->close (obj, out); in pex_run_in_environment()
361 obj->funcs->close (obj, errdes); in pex_run_in_environment()
370 pex_run (struct pex_obj *obj, int flags, const char *executable, in pex_run() argument
374 return pex_run_in_environment (obj, flags, executable, argv, NULL, in pex_run()
381 pex_input_file (struct pex_obj *obj, int flags, const char *in_name) in pex_input_file() argument
388 if (obj->count != 0 in pex_input_file()
389 || (obj->next_input >= 0 && obj->next_input != STDIN_FILE_NO) in pex_input_file()
390 || obj->next_input_name) in pex_input_file()
396 name = temp_file (obj, flags, name); in pex_input_file()
407 obj->input_file = f; in pex_input_file()
408 obj->next_input_name = name; in pex_input_file()
409 obj->next_input_name_allocated = (name != in_name); in pex_input_file()
417 pex_input_pipe (struct pex_obj *obj, int binary) in pex_input_pipe() argument
423 if (obj->count > 0) in pex_input_pipe()
428 if (! (obj->flags & PEX_USE_PIPES)) in pex_input_pipe()
433 if ((obj->next_input >= 0 && obj->next_input != STDIN_FILE_NO) in pex_input_pipe()
434 || obj->next_input_name) in pex_input_pipe()
437 if (obj->funcs->pipe (obj, p, binary != 0) < 0) in pex_input_pipe()
440 f = obj->funcs->fdopenw (obj, p[WRITE_PORT], binary != 0); in pex_input_pipe()
444 obj->funcs->close (obj, p[READ_PORT]); in pex_input_pipe()
445 obj->funcs->close (obj, p[WRITE_PORT]); in pex_input_pipe()
450 obj->next_input = p[READ_PORT]; in pex_input_pipe()
463 pex_read_output (struct pex_obj *obj, int binary) in pex_read_output() argument
465 if (obj->next_input_name != NULL) in pex_read_output()
472 if (!pex_get_status_and_time (obj, 0, &errmsg, &err)) in pex_read_output()
478 obj->read_output = fopen (obj->next_input_name, binary ? "rb" : "r"); in pex_read_output()
480 if (obj->next_input_name_allocated) in pex_read_output()
482 free (obj->next_input_name); in pex_read_output()
483 obj->next_input_name_allocated = 0; in pex_read_output()
485 obj->next_input_name = NULL; in pex_read_output()
491 o = obj->next_input; in pex_read_output()
494 obj->read_output = obj->funcs->fdopenr (obj, o, binary); in pex_read_output()
495 obj->next_input = -1; in pex_read_output()
498 return obj->read_output; in pex_read_output()
502 pex_read_err (struct pex_obj *obj, int binary) in pex_read_err() argument
506 o = obj->stderr_pipe; in pex_read_err()
509 obj->read_err = obj->funcs->fdopenr (obj, o, binary); in pex_read_err()
510 obj->stderr_pipe = -1; in pex_read_err()
511 return obj->read_err; in pex_read_err()
518 pex_get_status_and_time (struct pex_obj *obj, int done, const char **errmsg, in pex_get_status_and_time() argument
524 if (obj->number_waited == obj->count) in pex_get_status_and_time()
527 obj->status = XRESIZEVEC (int, obj->status, obj->count); in pex_get_status_and_time()
528 if ((obj->flags & PEX_RECORD_TIMES) != 0) in pex_get_status_and_time()
529 obj->time = XRESIZEVEC (struct pex_time, obj->time, obj->count); in pex_get_status_and_time()
532 for (i = obj->number_waited; i < obj->count; ++i) in pex_get_status_and_time()
534 if (obj->funcs->wait (obj, obj->children[i], &obj->status[i], in pex_get_status_and_time()
535 obj->time == NULL ? NULL : &obj->time[i], in pex_get_status_and_time()
539 obj->number_waited = i; in pex_get_status_and_time()
547 pex_get_status (struct pex_obj *obj, int count, int *vector) in pex_get_status() argument
549 if (obj->status == NULL) in pex_get_status()
554 if (!pex_get_status_and_time (obj, 0, &errmsg, &err)) in pex_get_status()
558 if (count > obj->count) in pex_get_status()
560 memset (vector + obj->count, 0, (count - obj->count) * sizeof (int)); in pex_get_status()
561 count = obj->count; in pex_get_status()
564 memcpy (vector, obj->status, count * sizeof (int)); in pex_get_status()
572 pex_get_times (struct pex_obj *obj, int count, struct pex_time *vector) in pex_get_times() argument
574 if (obj->status == NULL) in pex_get_times()
579 if (!pex_get_status_and_time (obj, 0, &errmsg, &err)) in pex_get_times()
583 if (obj->time == NULL) in pex_get_times()
586 if (count > obj->count) in pex_get_times()
588 memset (vector + obj->count, 0, in pex_get_times()
589 (count - obj->count) * sizeof (struct pex_time)); in pex_get_times()
590 count = obj->count; in pex_get_times()
593 memcpy (vector, obj->time, count * sizeof (struct pex_time)); in pex_get_times()
601 pex_free (struct pex_obj *obj) in pex_free() argument
606 if (obj->next_input >= 0 && obj->next_input != STDIN_FILE_NO) in pex_free()
607 obj->funcs->close (obj, obj->next_input); in pex_free()
608 if (obj->stderr_pipe >= 0 && obj->stderr_pipe != STDIN_FILE_NO) in pex_free()
609 obj->funcs->close (obj, obj->stderr_pipe); in pex_free()
610 if (obj->read_output != NULL) in pex_free()
611 fclose (obj->read_output); in pex_free()
612 if (obj->read_err != NULL) in pex_free()
613 fclose (obj->read_err); in pex_free()
617 if (obj->status == NULL) in pex_free()
622 obj->flags &= ~ PEX_RECORD_TIMES; in pex_free()
623 pex_get_status_and_time (obj, 1, &errmsg, &err); in pex_free()
626 if (obj->next_input_name_allocated) in pex_free()
627 free (obj->next_input_name); in pex_free()
628 free (obj->children); in pex_free()
629 free (obj->status); in pex_free()
630 free (obj->time); in pex_free()
632 if (obj->remove_count > 0) in pex_free()
636 for (i = 0; i < obj->remove_count; ++i) in pex_free()
638 remove (obj->remove[i]); in pex_free()
639 free (obj->remove[i]); in pex_free()
641 free (obj->remove); in pex_free()
644 if (obj->funcs->cleanup != NULL) in pex_free()
645 obj->funcs->cleanup (obj); in pex_free()
647 free (obj); in pex_free()