home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 1.ddi / CLIBSRC.ZIP / EXECLPE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  5.5 KB  |  120 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - execlpe.c
  3.  *
  4.  * function(s)
  5.  *        execlpe - load and execute a program
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #include <process.h>
  18. #include <_process.h>
  19. #include <stddef.h>
  20.  
  21. /*---------------------------------------------------------------------------*
  22.  
  23. Name            exec... - functions that load and run other programs
  24.  
  25. Usage           int  execlpe(char *pathname, char *arg0, char *arg1, ...,
  26.                            char *argn, NULL, char *envp[]);
  27.  
  28. Prototype in    process.h
  29.  
  30. Description     The functions in the exec...  family load and run (execute)
  31.                 other programs,  known as child processes.  When an exec...
  32.                 call is  successful, the child process  overlays the parent
  33.                 process.  There  must  be  sufficient  memory available for
  34.                 loading and executing the child process.
  35.  
  36.                 pathname is the file name  of the called child process. The
  37.                 exec...  functions search  for pathname  using the standard
  38.                 MS-DOS search algorithm:
  39.  
  40.                         . If no explicit extension is given, the function
  41.                           will search for the file as given. If that one is
  42.                           not found, the function will add .COM and search
  43.                           again. If that's not found, it will add .EXE and
  44.                           search one last time.
  45.  
  46.                         . If an explicit extension or period is given, the
  47.                           function will search for the file as given.
  48.  
  49.                 The suffixes l,  v, p and e added to  exec... "family name"
  50.                 specify that  the named function will  operate with certain
  51.                 capabilities.
  52.  
  53.                         p specifies  that the function will  search for the
  54.                           child in  those directories specified by  the DOS
  55.                           PATH environment variable. If pathname does not
  56.                           contain an explicit directory the function will
  57.                           search first the current directory then in the
  58.                           directory specified by the path. Without the p
  59.                           suffix, the  function only  searches the current
  60.                           working directory.
  61.  
  62.                         l specifies that the argument pointers (arg0, arg1,
  63.                           ...,  argn)  are  passed  as  separate arguments.
  64.                           Typically, the l suffix is  used when you know in
  65.                           advance the  number of arguments to  be passed. A
  66.                           mandatory  NULL following  argn marks  the end of
  67.                           the list.
  68.  
  69.                         v specifies  that  the argument  pointers (argv[0],
  70.                           argv[1], ..., argv[n]) are  passed as an array of
  71.                           pointers.  Typically,  the  v  suffix  is  used a
  72.                           variable number of arguments is to be passed.
  73.  
  74.                         e specifies that the  argument envp maybe passed to
  75.                           the  child  process,  allowing  you  to alter the
  76.                           environment for the child  process. Without the e
  77.                           suffix, child process inherits the environment of
  78.                           the parent process.  This environment argument is
  79.                           an  array of  char *.  Each element  points to  a
  80.                           null-terminated character string of the form:
  81.  
  82.                                 envar=value
  83.  
  84.                           where  envar  is  the   name  of  an  environment
  85.                           variable, and value is  the string value to which
  86.                           envar is set. The last element of envp[] is NULL.
  87.                           When  envp[0]  is  NULL,  the  child inherits the
  88.                           parent's environment settings.
  89.  
  90.                 The  exec... functions  must at  least one  argument to the
  91.                 child process. This  argument is, by convention, a  copy of
  92.                 pathname.  Under MS-DOS  3.x, pathname is available for the
  93.                 child process; under earlier versions, the child cannot use
  94.                 the passed value of arg0 (or argv[0]).
  95.  
  96.                 When  an exec...  function call   is made,  any open  files
  97.                 remain open in the child process.
  98.  
  99. Return value    If  successful, the  exec...  functions  do not  return. On
  100.                 error, the exec... functions return -1, and errno is set to
  101.                 one of the following:
  102.                         E2BIG   Argument list too long
  103.                         EACCES  Permission denied
  104.                         EMFILE  Too many open files
  105.                         ENOENT  Path or file name not found
  106.                         ENOEXEC Exec format error
  107.                         ENOMEM  Not enough core
  108.  
  109. *----------------------------------------------------------------------------*/
  110. int execlpe(char *pathP, char *arg0,...)
  111. {
  112.         register char   **p;
  113.  
  114.         /* Find the end of the argument list */
  115.  
  116.         for (p = &arg0; *p++ != NULL; );
  117.         return(_LoadProg(_exec, pathP, &arg0, (char **)*p, 1));
  118. }
  119.  
  120.