home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / spawnvp.c < prev    next >
C/C++ Source or Header  |  1993-05-25  |  1KB  |  50 lines

  1. /* spawnvp, spawnlp: try to execute a program on the default system
  2.    execution path. WARNING: the current directory is always searched
  3.    first.
  4.  
  5.    Written by Eric R. Smith and placed in the public domain.
  6.  
  7.    Rehacked by Uwe Ohse, 3.5.93: uses buffindfile
  8.  
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <process.h>
  13. #include <stdarg.h>
  14. #include <errno.h>
  15. #include <support.h>
  16. #include <limits.h>
  17.  
  18. static char *extensions[] = { "ttp", "prg", "tos", NULL };
  19.  
  20. #ifdef __STDC__
  21. int spawnvp(int mode, char *name, char **argv)
  22. #else
  23. int spawnvp(mode, name, argv) int mode; char *name; char **argv;
  24. #endif
  25. {
  26.     char *execname;
  27.       char buffer[PATH_MAX];
  28.       execname = buffindfile(name, getenv("PATH"), extensions,buffer);
  29.     if (!execname) {
  30.         errno = ENOENT;
  31.         return -1;        /* file not found */
  32.     }
  33.     return spawnve(mode, execname, argv, (char **)NULL);
  34. }
  35.  
  36. #ifdef __STDC__
  37. int spawnlp(int mode, char *name, ...)
  38. #else
  39. int spawnlp(mode, name) int mode; char *name;
  40. #endif
  41. {
  42.     va_list args;
  43.     int r;
  44.  
  45.     va_start(args, name);
  46.     r = spawnvp(mode, name, (char **)args);
  47.     va_end(args);
  48.     return r;
  49. }
  50.