Lines Matching refs:obj

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