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->count = 0; in pex_init_common()
66 obj->children = NULL; in pex_init_common()
67 obj->status = NULL; in pex_init_common()
68 obj->time = NULL; in pex_init_common()
69 obj->number_waited = 0; in pex_init_common()
70 obj->input_file = NULL; in pex_init_common()
71 obj->read_output = NULL; in pex_init_common()
72 obj->remove_count = 0; in pex_init_common()
73 obj->remove = NULL; in pex_init_common()
74 obj->funcs = funcs; in pex_init_common()
75 obj->sysdep = NULL; in pex_init_common()
76 return obj; in pex_init_common()
82 pex_add_remove (struct pex_obj *obj, const char *name, int allocated) in pex_add_remove() argument
86 ++obj->remove_count; in pex_add_remove()
87 obj->remove = XRESIZEVEC (char *, obj->remove, obj->remove_count); in pex_add_remove()
92 obj->remove[obj->remove_count - 1] = add; in pex_add_remove()
101 temp_file (struct pex_obj *obj, int flags, char *name) in temp_file() argument
105 if (obj->tempbase == NULL) in temp_file()
111 int len = strlen (obj->tempbase); in temp_file()
115 && strcmp (obj->tempbase + len - 6, "XXXXXX") == 0) in temp_file()
116 name = xstrdup (obj->tempbase); in temp_file()
118 name = concat (obj->tempbase, "XXXXXX", NULL); in temp_file()
136 if (obj->tempbase == NULL) in temp_file()
139 name = concat (obj->tempbase, name, NULL); in temp_file()
150 pex_run_in_environment (struct pex_obj *obj, int flags, const char *executable, in pex_run_in_environment() argument
170 if (obj->input_file) in pex_run_in_environment()
172 if (fclose (obj->input_file) == EOF) in pex_run_in_environment()
177 obj->input_file = NULL; in pex_run_in_environment()
182 if (obj->next_input_name != NULL) in pex_run_in_environment()
186 if (!pex_get_status_and_time (obj, 0, &errmsg, err)) in pex_run_in_environment()
189 in = obj->funcs->open_read (obj, obj->next_input_name, in pex_run_in_environment()
197 if (obj->next_input_name_allocated) in pex_run_in_environment()
199 free (obj->next_input_name); in pex_run_in_environment()
200 obj->next_input_name_allocated = 0; in pex_run_in_environment()
202 obj->next_input_name = NULL; in pex_run_in_environment()
206 in = obj->next_input; in pex_run_in_environment()
223 outname = concat (obj->tempbase, outname, NULL); in pex_run_in_environment()
226 obj->next_input = -1; in pex_run_in_environment()
228 else if ((obj->flags & PEX_USE_PIPES) == 0) in pex_run_in_environment()
230 outname = temp_file (obj, flags, outname); in pex_run_in_environment()
241 if ((obj->flags & PEX_SAVE_TEMPS) == 0) in pex_run_in_environment()
243 pex_add_remove (obj, outname, outname_allocated); in pex_run_in_environment()
248 obj->next_input_name = outname; in pex_run_in_environment()
249 obj->next_input_name_allocated = outname_allocated; in pex_run_in_environment()
254 if (obj->funcs->pipe (obj, p, (flags & PEX_BINARY_OUTPUT) != 0) < 0) in pex_run_in_environment()
262 obj->next_input = p[READ_PORT]; in pex_run_in_environment()
267 out = obj->funcs->open_write (obj, outname, in pex_run_in_environment()
292 errdes = obj->funcs->open_write (obj, errname, 0); in pex_run_in_environment()
304 if ((obj->flags & PEX_USE_PIPES) == 0) in pex_run_in_environment()
307 toclose = obj->next_input; in pex_run_in_environment()
311 pid = obj->funcs->exec_child (obj, flags, executable, argv, env, in pex_run_in_environment()
316 ++obj->count; in pex_run_in_environment()
317 obj->children = XRESIZEVEC (long, obj->children, obj->count); in pex_run_in_environment()
318 obj->children[obj->count - 1] = pid; in pex_run_in_environment()
324 obj->funcs->close (obj, in); in pex_run_in_environment()
326 obj->funcs->close (obj, out); in pex_run_in_environment()
328 obj->funcs->close (obj, errdes); in pex_run_in_environment()
337 pex_run (struct pex_obj *obj, int flags, const char *executable, in pex_run() argument
341 return pex_run_in_environment (obj, flags, executable, argv, NULL, in pex_run()
348 pex_input_file (struct pex_obj *obj, int flags, const char *in_name) in pex_input_file() argument
355 if (obj->count != 0 in pex_input_file()
356 || (obj->next_input >= 0 && obj->next_input != STDIN_FILE_NO) in pex_input_file()
357 || obj->next_input_name) in pex_input_file()
363 name = temp_file (obj, flags, name); in pex_input_file()
374 obj->input_file = f; in pex_input_file()
375 obj->next_input_name = name; in pex_input_file()
376 obj->next_input_name_allocated = (name != in_name); in pex_input_file()
384 pex_input_pipe (struct pex_obj *obj, int binary) in pex_input_pipe() argument
390 if (obj->count > 0) in pex_input_pipe()
395 if (! (obj->flags & PEX_USE_PIPES)) in pex_input_pipe()
400 if ((obj->next_input >= 0 && obj->next_input != STDIN_FILE_NO) in pex_input_pipe()
401 || obj->next_input_name) in pex_input_pipe()
404 if (obj->funcs->pipe (obj, p, binary != 0) < 0) in pex_input_pipe()
407 f = obj->funcs->fdopenw (obj, p[WRITE_PORT], binary != 0); in pex_input_pipe()
411 obj->funcs->close (obj, p[READ_PORT]); in pex_input_pipe()
412 obj->funcs->close (obj, p[WRITE_PORT]); in pex_input_pipe()
417 obj->next_input = p[READ_PORT]; in pex_input_pipe()
430 pex_read_output (struct pex_obj *obj, int binary) in pex_read_output() argument
432 if (obj->next_input_name != NULL) in pex_read_output()
439 if (!pex_get_status_and_time (obj, 0, &errmsg, &err)) in pex_read_output()
445 obj->read_output = fopen (obj->next_input_name, binary ? "rb" : "r"); in pex_read_output()
447 if (obj->next_input_name_allocated) in pex_read_output()
449 free (obj->next_input_name); in pex_read_output()
450 obj->next_input_name_allocated = 0; in pex_read_output()
452 obj->next_input_name = NULL; in pex_read_output()
458 o = obj->next_input; in pex_read_output()
461 obj->read_output = obj->funcs->fdopenr (obj, o, binary); in pex_read_output()
462 obj->next_input = -1; in pex_read_output()
465 return obj->read_output; in pex_read_output()
472 pex_get_status_and_time (struct pex_obj *obj, int done, const char **errmsg, in pex_get_status_and_time() argument
478 if (obj->number_waited == obj->count) in pex_get_status_and_time()
481 obj->status = XRESIZEVEC (int, obj->status, obj->count); in pex_get_status_and_time()
482 if ((obj->flags & PEX_RECORD_TIMES) != 0) in pex_get_status_and_time()
483 obj->time = XRESIZEVEC (struct pex_time, obj->time, obj->count); in pex_get_status_and_time()
486 for (i = obj->number_waited; i < obj->count; ++i) in pex_get_status_and_time()
488 if (obj->funcs->wait (obj, obj->children[i], &obj->status[i], in pex_get_status_and_time()
489 obj->time == NULL ? NULL : &obj->time[i], in pex_get_status_and_time()
493 obj->number_waited = i; in pex_get_status_and_time()
501 pex_get_status (struct pex_obj *obj, int count, int *vector) in pex_get_status() argument
503 if (obj->status == NULL) in pex_get_status()
508 if (!pex_get_status_and_time (obj, 0, &errmsg, &err)) in pex_get_status()
512 if (count > obj->count) in pex_get_status()
514 memset (vector + obj->count, 0, (count - obj->count) * sizeof (int)); in pex_get_status()
515 count = obj->count; in pex_get_status()
518 memcpy (vector, obj->status, count * sizeof (int)); in pex_get_status()
526 pex_get_times (struct pex_obj *obj, int count, struct pex_time *vector) in pex_get_times() argument
528 if (obj->status == NULL) in pex_get_times()
533 if (!pex_get_status_and_time (obj, 0, &errmsg, &err)) in pex_get_times()
537 if (obj->time == NULL) in pex_get_times()
540 if (count > obj->count) in pex_get_times()
542 memset (vector + obj->count, 0, in pex_get_times()
543 (count - obj->count) * sizeof (struct pex_time)); in pex_get_times()
544 count = obj->count; in pex_get_times()
547 memcpy (vector, obj->time, count * sizeof (struct pex_time)); in pex_get_times()
555 pex_free (struct pex_obj *obj) in pex_free() argument
557 if (obj->next_input >= 0 && obj->next_input != STDIN_FILE_NO) in pex_free()
558 obj->funcs->close (obj, obj->next_input); in pex_free()
562 if (obj->status == NULL) in pex_free()
567 obj->flags &= ~ PEX_RECORD_TIMES; in pex_free()
568 pex_get_status_and_time (obj, 1, &errmsg, &err); in pex_free()
571 if (obj->next_input_name_allocated) in pex_free()
572 free (obj->next_input_name); in pex_free()
573 if (obj->children != NULL) in pex_free()
574 free (obj->children); in pex_free()
575 if (obj->status != NULL) in pex_free()
576 free (obj->status); in pex_free()
577 if (obj->time != NULL) in pex_free()
578 free (obj->time); in pex_free()
579 if (obj->read_output != NULL) in pex_free()
580 fclose (obj->read_output); in pex_free()
582 if (obj->remove_count > 0) in pex_free()
586 for (i = 0; i < obj->remove_count; ++i) in pex_free()
588 remove (obj->remove[i]); in pex_free()
589 free (obj->remove[i]); in pex_free()
591 free (obj->remove); in pex_free()
594 if (obj->funcs->cleanup != NULL) in pex_free()
595 obj->funcs->cleanup (obj); in pex_free()
597 free (obj); in pex_free()