home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 1.ddi / CLIB1.ZIP / EXECLPE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  5.8 KB  |  123 lines

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