URL
https://opencores.org/ocsvn/open8_urisc/open8_urisc/trunk
Subversion Repositories open8_urisc
[/] [open8_urisc/] [trunk/] [gnu/] [binutils/] [libiberty/] [pexecute.txh] - Rev 165
Go to most recent revision | Compare with Previous | Blame | View Log
@c -*- mode: texinfo -*-@deftypefn Extension {struct pex_obj *} pex_init (int @var{flags}, @const char *@var{pname}, const char *@var{tempbase})Prepare to execute one or more programs, with standard output of eachprogram fed to standard input of the next. This is a systemindependent interface to execute a pipeline.@var{flags} is a bitwise combination of the following:@table @code@vindex PEX_RECORD_TIMES@item PEX_RECORD_TIMESRecord subprocess times if possible.@vindex PEX_USE_PIPES@item PEX_USE_PIPESUse pipes for communication between processes, if possible.@vindex PEX_SAVE_TEMPS@item PEX_SAVE_TEMPSDon't delete temporary files used for communication betweenprocesses.@end table@var{pname} is the name of program to be executed, used in errormessages. @var{tempbase} is a base name to use for any requiredtemporary files; it may be @code{NULL} to use a randomly chosen name.@end deftypefn@deftypefn Extension {const char *} pex_run (struct pex_obj *@var{obj}, @int @var{flags}, const char *@var{executable}, char * const *@var{argv}, @const char *@var{outname}, const char *@var{errname}, int *@var{err})Execute one program in a pipeline. On success this returns@code{NULL}. On failure it returns an error message, a staticallyallocated string.@var{obj} is returned by a previous call to @code{pex_init}.@var{flags} is a bitwise combination of the following:@table @code@vindex PEX_LAST@item PEX_LASTThis must be set on the last program in the pipeline. In particular,it should be set when executing a single program. The standard outputof the program will be sent to @var{outname}, or, if @var{outname} is@code{NULL}, to the standard output of the calling program. Do @emph{not}set this bit if you want to call @code{pex_read_output}(described below). After a call to @code{pex_run} with this bit set,@var{pex_run} may no longer be called with the same @var{obj}.@vindex PEX_SEARCH@item PEX_SEARCHSearch for the program using the user's executable search path.@vindex PEX_SUFFIX@item PEX_SUFFIX@var{outname} is a suffix. See the description of @var{outname},below.@vindex PEX_STDERR_TO_STDOUT@item PEX_STDERR_TO_STDOUTSend the program's standard error to standard output, if possible.@vindex PEX_BINARY_INPUT@vindex PEX_BINARY_OUTPUT@vindex PEX_BINARY_ERROR@item PEX_BINARY_INPUT@itemx PEX_BINARY_OUTPUT@itemx PEX_BINARY_ERRORThe standard input (output or error) of the program should be read (written) inbinary mode rather than text mode. These flags are ignored on systemswhich do not distinguish binary mode and text mode, such as Unix. Forproper behavior these flags should match appropriately---a call to@code{pex_run} using @code{PEX_BINARY_OUTPUT} should be followed by acall using @code{PEX_BINARY_INPUT}.@vindex PEX_STDERR_TO_PIPE@item PEX_STDERR_TO_PIPESend the program's standard error to a pipe, if possible. This flagcannot be specified together with @code{PEX_STDERR_TO_STDOUT}. Thisflag can be specified only on the last program in pipeline.@end table@var{executable} is the program to execute. @var{argv} is the set ofarguments to pass to the program; normally @code{@var{argv}[0]} willbe a copy of @var{executable}.@var{outname} is used to set the name of the file to use for standardoutput. There are two cases in which no output file will be used:@enumerate@itemif @code{PEX_LAST} is not set in @var{flags}, and @code{PEX_USE_PIPES}was set in the call to @code{pex_init}, and the system supports pipes@itemif @code{PEX_LAST} is set in @var{flags}, and @var{outname} is@code{NULL}@end enumerate@noindentOtherwise the code will use a file to hold standardoutput. If @code{PEX_LAST} is not set, this file is considered to bea temporary file, and it will be removed when no longer needed, unless@code{PEX_SAVE_TEMPS} was set in the call to @code{pex_init}.There are two cases to consider when setting the name of the file tohold standard output.@enumerate@item@code{PEX_SUFFIX} is set in @var{flags}. In this case@var{outname} may not be @code{NULL}. If the @var{tempbase} parameterto @code{pex_init} was not @code{NULL}, then the output file name isthe concatenation of @var{tempbase} and @var{outname}. If@var{tempbase} was @code{NULL}, then the output file name is a randomfile name ending in @var{outname}.@item@code{PEX_SUFFIX} was not set in @var{flags}. In thiscase, if @var{outname} is not @code{NULL}, it is used as the outputfile name. If @var{outname} is @code{NULL}, and @var{tempbase} wasnot NULL, the output file name is randomly chosen using@var{tempbase}. Otherwise the output file name is chosen completelyat random.@end enumerate@var{errname} is the file name to use for standard error output. Ifit is @code{NULL}, standard error is the same as the caller's.Otherwise, standard error is written to the named file.On an error return, the code sets @code{*@var{err}} to an @code{errno}value, or to 0 if there is no relevant @code{errno}.@end deftypefn@deftypefn Extension {const char *} pex_run_in_environment (struct pex_obj *@var{obj}, @int @var{flags}, const char *@var{executable}, char * const *@var{argv}, @char * const *@var{env}, int @var{env_size}, const char *@var{outname}, @const char *@var{errname}, int *@var{err})Execute one program in a pipeline, permitting the environment for theprogram to be specified. Behaviour and parameters not listed below areas for @code{pex_run}.@var{env} is the environment for the child process, specified as an array ofcharacter pointers. Each element of the array should point to a string of theform @code{VAR=VALUE}, with the exception of the last element that must be@code{NULL}.@end deftypefn@deftypefn Extension {FILE *} pex_input_file (struct pex_obj *@var{obj}, @int @var{flags}, const char *@var{in_name})Return a stream for a temporary file to pass to the first program inthe pipeline as input.The name of the input file is chosen according to the same rules@code{pex_run} uses to choose output file names, based on@var{in_name}, @var{obj} and the @code{PEX_SUFFIX} bit in @var{flags}.Don't call @code{fclose} on the returned stream; the first call to@code{pex_run} closes it automatically.If @var{flags} includes @code{PEX_BINARY_OUTPUT}, open the stream inbinary mode; otherwise, open it in the default mode. Including@code{PEX_BINARY_OUTPUT} in @var{flags} has no effect on Unix.@end deftypefn@deftypefn Extension {FILE *} pex_input_pipe (struct pex_obj *@var{obj}, @int @var{binary})Return a stream @var{fp} for a pipe connected to the standard input ofthe first program in the pipeline; @var{fp} is opened for writing.You must have passed @code{PEX_USE_PIPES} to the @code{pex_init} callthat returned @var{obj}.You must close @var{fp} using @code{fclose} yourself when you havefinished writing data to the pipeline.The file descriptor underlying @var{fp} is marked not to be inheritedby child processes.On systems that do not support pipes, this function returns@code{NULL}, and sets @code{errno} to @code{EINVAL}. If you wouldlike to write code that is portable to all systems the @code{pex}functions support, consider using @code{pex_input_file} instead.There are two opportunities for deadlock using@code{pex_input_pipe}:@itemize @bullet@itemMost systems' pipes can buffer only a fixed amount of data; a processthat writes to a full pipe blocks. Thus, if you write to @file{fp}before starting the first process, you run the risk of blocking whenthere is no child process yet to read the data and allow you tocontinue. @code{pex_input_pipe} makes no promises about thesize of the pipe's buffer, so if you need to write any data at allbefore starting the first process in the pipeline, consider using@code{pex_input_file} instead.@itemUsing @code{pex_input_pipe} and @code{pex_read_output} togethermay also cause deadlock. If the output pipe fills up, so that eachprogram in the pipeline is waiting for the next to read more data, andyou fill the input pipe by writing more data to @var{fp}, then thereis no way to make progress: the only process that could read data fromthe output pipe is you, but you are blocked on the input pipe.@end itemize@end deftypefn@deftypefn Extension {FILE *} pex_read_output (struct pex_obj *@var{obj}, @int @var{binary})Returns a @code{FILE} pointer which may be used to read the standardoutput of the last program in the pipeline. When this is used,@code{PEX_LAST} should not be used in a call to @code{pex_run}. Afterthis is called, @code{pex_run} may no longer be called with the same@var{obj}. @var{binary} should be non-zero if the file should beopened in binary mode. Don't call @code{fclose} on the returned file;it will be closed by @code{pex_free}.@end deftypefn@deftypefn Extension {FILE *} pex_read_err (struct pex_obj *@var{obj}, @int @var{binary})Returns a @code{FILE} pointer which may be used to read the standarderror of the last program in the pipeline. When this is used,@code{PEX_LAST} should not be used in a call to @code{pex_run}. Afterthis is called, @code{pex_run} may no longer be called with the same@var{obj}. @var{binary} should be non-zero if the file should beopened in binary mode. Don't call @code{fclose} on the returned file;it will be closed by @code{pex_free}.@end deftypefn@deftypefn Extension int pex_get_status (struct pex_obj *@var{obj}, @int @var{count}, int *@var{vector})Returns the exit status of all programs run using @var{obj}.@var{count} is the number of results expected. The results will beplaced into @var{vector}. The results are in the order of the callsto @code{pex_run}. Returns 0 on error, 1 on success.@end deftypefn@deftypefn Extension int pex_get_times (struct pex_obj *@var{obj}, @int @var{count}, struct pex_time *@var{vector})Returns the process execution times of all programs run using@var{obj}. @var{count} is the number of results expected. Theresults will be placed into @var{vector}. The results are in theorder of the calls to @code{pex_run}. Returns 0 on error, 1 onsuccess.@code{struct pex_time} has the following fields of the type@code{unsigned long}: @code{user_seconds},@code{user_microseconds}, @code{system_seconds},@code{system_microseconds}. On systems which do not support reportingprocess times, all the fields will be set to @code{0}.@end deftypefn@deftypefn Extension void pex_free (struct pex_obj @var{obj})Clean up and free all data associated with @var{obj}. If you have notyet called @code{pex_get_times} or @code{pex_get_status}, this willtry to kill the subprocesses.@end deftypefn@deftypefn Extension {const char *} pex_one (int @var{flags}, @const char *@var{executable}, char * const *@var{argv}, @const char *@var{pname}, const char *@var{outname}, const char *@var{errname}, @int *@var{status}, int *@var{err})An interface to permit the easy execution of asingle program. The return value and most of the parameters are asfor a call to @code{pex_run}. @var{flags} is restricted to acombination of @code{PEX_SEARCH}, @code{PEX_STDERR_TO_STDOUT}, and@code{PEX_BINARY_OUTPUT}. @var{outname} is interpreted as if@code{PEX_LAST} were set. On a successful return, @code{*@var{status}} willbe set to the exit status of the program.@end deftypefn@deftypefn Extension int pexecute (const char *@var{program}, @char * const *@var{argv}, const char *@var{this_pname}, @const char *@var{temp_base}, char **@var{errmsg_fmt}, @char **@var{errmsg_arg}, int @var{flags})This is the old interface to execute one or more programs. It isstill supported for compatibility purposes, but is no longerdocumented.@end deftypefn@deftypefn Extension int pwait (int @var{pid}, int *@var{status}, int @var{flags})Another part of the old execution interface.@end deftypefn
Go to most recent revision | Compare with Previous | Blame | View Log
