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

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