Lines Matching refs:obj

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