home *** CD-ROM | disk | FTP | other *** search
/ Mega CD-ROM 1 / megacd_rom_1.zip / megacd_rom_1 / GNUISH / SWALIB0.ZIP / SW_SPLP.C < prev    next >
C/C++ Source or Header  |  1990-09-10  |  2KB  |  92 lines

  1. /* sw_splp.c - spawn a child process.
  2.    Copyright (C) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  3.  
  4.    This file is part of SWAPLIB (the library), a library for efficient
  5.    execution of child processes under MS-DOS.
  6.  
  7.    The library is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 1, or (at your option)
  10.    any later version.
  11.  
  12.    The library is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with the library; if not, write to the Free Software
  19.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.    $Header: e:/gnu/swaplib/RCS/sw_splp.c'v 0.9 90/09/09 21:44:15 tho Stable $
  22.  */
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <errno.h>
  27. #include <stdarg.h>
  28.  
  29. #include "swaplib.h"
  30.  
  31. extern void *xmalloc (size_t size);
  32.  
  33. int
  34. swap_spawnlp (char *cmd, char *argv0, ...)
  35. {
  36.   char **argv;
  37.   int i;
  38.   int rc;
  39.   int argc = 1;
  40.  
  41.   va_list ap;
  42.  
  43.  
  44.   if (argv0)
  45.     {
  46.       /* Count the arguments */
  47.  
  48.       va_start (ap, argv0);
  49.       while (va_arg (ap, char *))
  50.     argc++;
  51.       va_end (ap);
  52.  
  53.       argv = (char **) xmalloc ((argc + 1) * sizeof (char *));
  54.  
  55.  
  56.       /* Set up the pointers. */
  57.  
  58.       argv[0] = argv0;
  59.  
  60.       va_start (ap, argv0);
  61.       for (i = 1; i < argc; i++)
  62.     argv[i] = va_arg (ap, char *);
  63.       va_end (ap);
  64.  
  65.       argv[argc] = NULL;
  66.  
  67.  
  68.       /* Call the workhorse.  */
  69.  
  70.       rc = swap_spawnvpe (cmd, argv, NULL);
  71.  
  72.       free (argv);
  73.     }
  74.   else
  75.     {
  76.       /* Invalid arguments.  */
  77.  
  78.       rc = -1;
  79.       errno = EINVAL;
  80.     }
  81.  
  82.   return rc;
  83. }
  84.  
  85. /* 
  86.  * Local Variables:
  87.  * mode:C
  88.  * ChangeLog:ChangeLog
  89.  * compile-command:make
  90.  * End:
  91.  */
  92.