home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / PROCESS / SYSTEM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-03  |  969 b   |  47 lines

  1. /* system.c (emx+gcc) -- Copyright (c) 1990-1993 by Eberhard Mattes */
  2.  
  3. #include <process.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <io.h>
  7. #include <errno.h>
  8.  
  9. int system (const char *name)
  10. {
  11.   int rc;
  12.   char *tmp, *sh;
  13.   const char *add = " /c ";
  14.   char **argv;
  15.  
  16.   tmp = NULL; argv = NULL;
  17.   sh = getenv ("COMSPEC");
  18.   if (sh == NULL)
  19.     {
  20.       errno = ENOENT;
  21.       return (-1);
  22.     }
  23.   if (name == NULL)   /* Check for command interpreter */
  24.     return (access (sh, 0) == 0);
  25.   if (*name == 0)
  26.     add = "";
  27.   tmp = malloc (strlen (sh) + strlen (add) + strlen (name) + 1);
  28.   if (tmp == NULL)
  29.     {
  30.       errno = ENOMEM;
  31.       return (-1);
  32.     }
  33.   strcpy (tmp, sh);
  34.   strcat (tmp, add);
  35.   strcat (tmp, name);
  36.   argv = _splitargs (tmp, NULL);
  37.   free (tmp);
  38.   if (argv == NULL)
  39.     rc = -1;
  40.   else
  41.     {
  42.       rc = spawnvp (P_WAIT, argv[0], (char const * const *)argv);
  43.       free (argv);
  44.     }
  45.   return (rc);
  46. }
  47.