home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2290 / shell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  854 b   |  50 lines

  1. /*
  2.  * Copyright 1989, 1990, John F. Haugh II
  3.  * All rights reserved.
  4.  *
  5.  * Use, duplication, and disclosure prohibited without
  6.  * the express written permission of the author.
  7.  */
  8.  
  9. #include <stdio.h>
  10. #ifndef    BSD
  11. #include <string.h>
  12. #include <memory.h>
  13. #else
  14. #include <strings.h>
  15. #define    strchr    index
  16. #define    strrchr    rindex
  17. #endif
  18. #include "config.h"
  19.  
  20. #ifndef    lint
  21. static    char    _sccsid[] = "@(#)shell.c    2.2    19:24:15    7/29/90";
  22. #endif
  23.  
  24. extern    char    *newenvp[];
  25.  
  26. void    shell (file)
  27. char    *file;
  28. {
  29.     char    arg0[BUFSIZ];
  30.     char    *path;
  31.     extern    int    errno;
  32.  
  33.     if (file == (char *) 0)
  34.         exit (1);
  35.  
  36.     if (path = strrchr (file, '/'))
  37.         path++;
  38.     else
  39.         path = file;
  40.  
  41.     (void) strcpy (arg0 + 1, path);
  42.     arg0[0] = '-';
  43. #ifndef    NDEBUG
  44.     printf ("Executing shell %s\n", file);
  45. #endif
  46.     execle (file, arg0, (char *) 0, newenvp);
  47.     printf ("Can't execute %s\n", file);
  48.     exit (errno);
  49. }
  50.