home *** CD-ROM | disk | FTP | other *** search
- /* system.c (emx+gcc) -- Copyright (c) 1990-1993 by Eberhard Mattes */
-
- #include <process.h>
- #include <stdlib.h>
- #include <string.h>
- #include <io.h>
- #include <errno.h>
-
- int system (const char *name)
- {
- int rc;
- char *tmp, *sh;
- const char *add = " /c ";
- char **argv;
-
- tmp = NULL; argv = NULL;
- sh = getenv ("COMSPEC");
- if (sh == NULL)
- {
- errno = ENOENT;
- return (-1);
- }
- if (name == NULL) /* Check for command interpreter */
- return (access (sh, 0) == 0);
- if (*name == 0)
- add = "";
- tmp = malloc (strlen (sh) + strlen (add) + strlen (name) + 1);
- if (tmp == NULL)
- {
- errno = ENOMEM;
- return (-1);
- }
- strcpy (tmp, sh);
- strcat (tmp, add);
- strcat (tmp, name);
- argv = _splitargs (tmp, NULL);
- free (tmp);
- if (argv == NULL)
- rc = -1;
- else
- {
- rc = spawnvp (P_WAIT, argv[0], (char const * const *)argv);
- free (argv);
- }
- return (rc);
- }
-