home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / libsrc87 / exec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-30  |  1.6 KB  |  72 lines

  1. /*
  2.  * exec.c:: various execXX emulations. If we're in a child that has been
  3.  * forked, then we restore our parent's data area and shrink the
  4.  * fork information block to the minimum. If we're not in any child, then
  5.  * we just wing it (we probably should shrink the text+data+bss block to
  6.  * give more room, but that would be rather difficult to do properly).
  7.  *
  8.  * the real work is done in spawnve.c.
  9.  */
  10.  
  11. #include <osbind.h>
  12. #include <basepage.h>
  13. #include <process.h>
  14. #include <file.h>
  15. #include <stdarg.h>
  16. #include <unistd.h>
  17.  
  18. extern int _x_Bit_set_in_stat; /* in stat.c */
  19.  
  20. int
  21. execve(path, argv, envp)
  22.     char *path, **argv, **envp;
  23. {
  24.     int savex = _x_Bit_set_in_stat;
  25.  
  26. /* check to make sure that the file is executable. alas, this is not
  27.    foolproof, since .g and .sh files are marked as executable even though
  28.    they're not, really.
  29.  */
  30.     _x_Bit_set_in_stat = 1;
  31.     if (access(path, X_OK)) {
  32.             _x_Bit_set_in_stat = savex;
  33.         return -1;
  34.     }
  35.         _x_Bit_set_in_stat = savex;
  36. /*
  37.  * the call to spawnve shouldn't return unless there is an error
  38.  */
  39.     return spawnve(P_OVERLAY, path, argv, envp);
  40. }
  41.  
  42. int
  43. execv(path, argv)
  44.     char *path, **argv;
  45. {
  46.     return execve(path, argv, (char **)0);
  47. }
  48.  
  49. int
  50. execvp(name, argv)
  51.     char *name;
  52.     char **argv;
  53. {
  54.     /* note: we cannot check x bit here as we dont know the full path.
  55.      * we flag spawnvp to do this by passing it -ve mode
  56.      */
  57.     return spawnvp(-P_OVERLAY, name, argv);
  58. }
  59.  
  60. #ifdef __STDC__
  61. int execl(char *path, ...)
  62. #else
  63. int execl(path)
  64.     char    *path;
  65. #endif
  66. {
  67.     va_list args;
  68.  
  69.     va_start(args, path);
  70.     return execve(path, (char **)args, (char **)0);
  71. }
  72.