home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / PROCESS / SPAWNVE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  1.3 KB  |  56 lines

  1. /* spawnve.c (emx+gcc) -- Copyright (c) 1990-1993 by Eberhard Mattes */
  2.  
  3. #include <sys/emx.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <process.h>
  7. #include <errno.h>
  8.  
  9. int spawnve (int mode, const char *name, const char * const *argv,
  10.              const char * const *envp)
  11. {
  12.   struct _new_proc np;
  13.   int i, size, n;
  14.   const char * const *p;
  15.   char *d;
  16.   char exe[512];
  17.  
  18.   np.mode = mode;
  19.   if (envp == NULL) envp = (const char * const *)environ;
  20.   strcpy (exe, name);
  21.   _defext (exe, "exe");
  22.   np.fname_off = (unsigned long)exe;
  23.   size = 1; n = 0;
  24.   for (p = envp; *p != NULL; ++p)
  25.     {
  26.       ++n; size += 1 + strlen (*p);
  27.     }
  28.   d = alloca (size);
  29.   np.env_count = n; np.env_size = size;
  30.   np.env_off = (unsigned long)d;
  31.   for (p = envp; *p != NULL; ++p)
  32.     {
  33.       i = strlen (*p);
  34.       memcpy (d, *p, i+1);
  35.       d += i+1;
  36.     }
  37.   *d = 0;
  38.   size = 0; n = 0;
  39.   for (p = argv; *p != NULL; ++p)
  40.     {
  41.       ++n; size += 2 + strlen (*p);
  42.     }
  43.   d = alloca (size);
  44.   np.arg_count = n; np.arg_size = size;
  45.   np.arg_off = (unsigned long)d;
  46.   for (p = argv; *p != NULL; ++p)
  47.     {
  48.       i = strlen (*p);
  49.       *d++ = (char)(_ARG_DQUOTE|_ARG_NONZERO);
  50.       memcpy (d, *p, i+1);
  51.       d += i+1;
  52.     }
  53.   i = __spawnve (&np);
  54.   return (i);
  55. }
  56.