Lines Matching refs:obj
57 struct pex_obj *obj; in pex_init_common() local
59 obj = XNEW (struct pex_obj); in pex_init_common()
60 obj->flags = flags; in pex_init_common()
61 obj->pname = pname; in pex_init_common()
62 obj->tempbase = tempbase; in pex_init_common()
63 obj->next_input = STDIN_FILE_NO; in pex_init_common()
64 obj->next_input_name = NULL; in pex_init_common()
65 obj->next_input_name_allocated = 0; 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->remove_count = 0; in pex_init_common()
74 obj->remove = NULL; in pex_init_common()
75 obj->funcs = funcs; in pex_init_common()
76 obj->sysdep = NULL; in pex_init_common()
77 return obj; in pex_init_common()
83 pex_add_remove (struct pex_obj *obj, const char *name, int allocated) in pex_add_remove() argument
87 ++obj->remove_count; in pex_add_remove()
88 obj->remove = XRESIZEVEC (char *, obj->remove, obj->remove_count); in pex_add_remove()
93 obj->remove[obj->remove_count - 1] = add; in pex_add_remove()
102 temp_file (struct pex_obj *obj, int flags, char *name) in temp_file() argument
106 if (obj->tempbase == NULL) in temp_file()
112 int len = strlen (obj->tempbase); in temp_file()
116 && strcmp (obj->tempbase + len - 6, "XXXXXX") == 0) in temp_file()
117 name = xstrdup (obj->tempbase); in temp_file()
119 name = concat (obj->tempbase, "XXXXXX", NULL); in temp_file()
137 if (obj->tempbase == NULL) in temp_file()
140 name = concat (obj->tempbase, name, NULL); in temp_file()
151 pex_run_in_environment (struct pex_obj *obj, int flags, const char *executable, in pex_run_in_environment() argument
171 if (obj->input_file) in pex_run_in_environment()
173 if (fclose (obj->input_file) == EOF) in pex_run_in_environment()
178 obj->input_file = NULL; in pex_run_in_environment()
183 if (obj->next_input_name != NULL) in pex_run_in_environment()
187 if (!pex_get_status_and_time (obj, 0, &errmsg, err)) in pex_run_in_environment()
190 in = obj->funcs->open_read (obj, obj->next_input_name, in pex_run_in_environment()
198 if (obj->next_input_name_allocated) in pex_run_in_environment()
200 free (obj->next_input_name); in pex_run_in_environment()
201 obj->next_input_name_allocated = 0; in pex_run_in_environment()
203 obj->next_input_name = NULL; in pex_run_in_environment()
207 in = obj->next_input; in pex_run_in_environment()
224 outname = concat (obj->tempbase, outname, NULL); in pex_run_in_environment()
227 obj->next_input = -1; in pex_run_in_environment()
229 else if ((obj->flags & PEX_USE_PIPES) == 0) in pex_run_in_environment()
231 outname = temp_file (obj, flags, outname); in pex_run_in_environment()
242 if ((obj->flags & PEX_SAVE_TEMPS) == 0) in pex_run_in_environment()
244 pex_add_remove (obj, outname, outname_allocated); in pex_run_in_environment()
249 obj->next_input_name = outname; in pex_run_in_environment()
250 obj->next_input_name_allocated = outname_allocated; in pex_run_in_environment()
255 if (obj->funcs->pipe (obj, p, (flags & PEX_BINARY_OUTPUT) != 0) < 0) in pex_run_in_environment()
263 obj->next_input = p[READ_PORT]; in pex_run_in_environment()
268 out = obj->funcs->open_write (obj, outname, in pex_run_in_environment()
293 errdes = obj->funcs->open_write (obj, errname, 0); in pex_run_in_environment()
305 if ((obj->flags & PEX_USE_PIPES) == 0) in pex_run_in_environment()
308 toclose = obj->next_input; in pex_run_in_environment()
312 pid = obj->funcs->exec_child (obj, flags, executable, argv, env, in pex_run_in_environment()
317 ++obj->count; in pex_run_in_environment()
318 obj->children = XRESIZEVEC (long, obj->children, obj->count); in pex_run_in_environment()
319 obj->children[obj->count - 1] = pid; in pex_run_in_environment()
325 obj->funcs->close (obj, in); in pex_run_in_environment()
327 obj->funcs->close (obj, out); in pex_run_in_environment()
329 obj->funcs->close (obj, errdes); in pex_run_in_environment()
338 pex_run (struct pex_obj *obj, int flags, const char *executable, in pex_run() argument
342 return pex_run_in_environment (obj, flags, executable, argv, NULL, in pex_run()
349 pex_input_file (struct pex_obj *obj, int flags, const char *in_name) in pex_input_file() argument
356 if (obj->count != 0 in pex_input_file()
357 || (obj->next_input >= 0 && obj->next_input != STDIN_FILE_NO) in pex_input_file()
358 || obj->next_input_name) in pex_input_file()
364 name = temp_file (obj, flags, name); in pex_input_file()
375 obj->input_file = f; in pex_input_file()
376 obj->next_input_name = name; in pex_input_file()
377 obj->next_input_name_allocated = (name != in_name); in pex_input_file()
385 pex_input_pipe (struct pex_obj *obj, int binary) in pex_input_pipe() argument
391 if (obj->count > 0) in pex_input_pipe()
396 if (! (obj->flags & PEX_USE_PIPES)) in pex_input_pipe()
401 if ((obj->next_input >= 0 && obj->next_input != STDIN_FILE_NO) in pex_input_pipe()
402 || obj->next_input_name) in pex_input_pipe()
405 if (obj->funcs->pipe (obj, p, binary != 0) < 0) in pex_input_pipe()
408 f = obj->funcs->fdopenw (obj, p[WRITE_PORT], binary != 0); in pex_input_pipe()
412 obj->funcs->close (obj, p[READ_PORT]); in pex_input_pipe()
413 obj->funcs->close (obj, p[WRITE_PORT]); in pex_input_pipe()
418 obj->next_input = p[READ_PORT]; in pex_input_pipe()
431 pex_read_output (struct pex_obj *obj, int binary) in pex_read_output() argument
433 if (obj->next_input_name != NULL) in pex_read_output()
440 if (!pex_get_status_and_time (obj, 0, &errmsg, &err)) in pex_read_output()
446 obj->read_output = fopen (obj->next_input_name, binary ? "rb" : "r"); in pex_read_output()
448 if (obj->next_input_name_allocated) in pex_read_output()
450 free (obj->next_input_name); in pex_read_output()
451 obj->next_input_name_allocated = 0; in pex_read_output()
453 obj->next_input_name = NULL; in pex_read_output()
459 o = obj->next_input; in pex_read_output()
462 obj->read_output = obj->funcs->fdopenr (obj, o, binary); in pex_read_output()
463 obj->next_input = -1; in pex_read_output()
466 return obj->read_output; in pex_read_output()
473 pex_get_status_and_time (struct pex_obj *obj, int done, const char **errmsg, in pex_get_status_and_time() argument
479 if (obj->number_waited == obj->count) in pex_get_status_and_time()
482 obj->status = XRESIZEVEC (int, obj->status, obj->count); in pex_get_status_and_time()
483 if ((obj->flags & PEX_RECORD_TIMES) != 0) in pex_get_status_and_time()
484 obj->time = XRESIZEVEC (struct pex_time, obj->time, obj->count); in pex_get_status_and_time()
487 for (i = obj->number_waited; i < obj->count; ++i) in pex_get_status_and_time()
489 if (obj->funcs->wait (obj, obj->children[i], &obj->status[i], in pex_get_status_and_time()
490 obj->time == NULL ? NULL : &obj->time[i], in pex_get_status_and_time()
494 obj->number_waited = i; in pex_get_status_and_time()
502 pex_get_status (struct pex_obj *obj, int count, int *vector) in pex_get_status() argument
504 if (obj->status == NULL) in pex_get_status()
509 if (!pex_get_status_and_time (obj, 0, &errmsg, &err)) in pex_get_status()
513 if (count > obj->count) in pex_get_status()
515 memset (vector + obj->count, 0, (count - obj->count) * sizeof (int)); in pex_get_status()
516 count = obj->count; in pex_get_status()
519 memcpy (vector, obj->status, count * sizeof (int)); in pex_get_status()
527 pex_get_times (struct pex_obj *obj, int count, struct pex_time *vector) in pex_get_times() argument
529 if (obj->status == NULL) in pex_get_times()
534 if (!pex_get_status_and_time (obj, 0, &errmsg, &err)) in pex_get_times()
538 if (obj->time == NULL) in pex_get_times()
541 if (count > obj->count) in pex_get_times()
543 memset (vector + obj->count, 0, in pex_get_times()
544 (count - obj->count) * sizeof (struct pex_time)); in pex_get_times()
545 count = obj->count; in pex_get_times()
548 memcpy (vector, obj->time, count * sizeof (struct pex_time)); in pex_get_times()
556 pex_free (struct pex_obj *obj) in pex_free() argument
558 if (obj->next_input >= 0 && obj->next_input != STDIN_FILE_NO) in pex_free()
559 obj->funcs->close (obj, obj->next_input); in pex_free()
563 if (obj->status == NULL) in pex_free()
568 obj->flags &= ~ PEX_RECORD_TIMES; in pex_free()
569 pex_get_status_and_time (obj, 1, &errmsg, &err); in pex_free()
572 if (obj->next_input_name_allocated) in pex_free()
573 free (obj->next_input_name); in pex_free()
574 if (obj->children != NULL) in pex_free()
575 free (obj->children); in pex_free()
576 if (obj->status != NULL) in pex_free()
577 free (obj->status); in pex_free()
578 if (obj->time != NULL) in pex_free()
579 free (obj->time); in pex_free()
580 if (obj->read_output != NULL) in pex_free()
581 fclose (obj->read_output); in pex_free()
583 if (obj->remove_count > 0) in pex_free()
587 for (i = 0; i < obj->remove_count; ++i) in pex_free()
589 remove (obj->remove[i]); in pex_free()
590 free (obj->remove[i]); in pex_free()
592 free (obj->remove); in pex_free()
595 if (obj->funcs->cleanup != NULL) in pex_free()
596 obj->funcs->cleanup (obj); in pex_free()
598 free (obj); in pex_free()