* src/Makefile.in: remove spawn.o
[fw/sdcc] / src / spawn.c
1 /**[txh]********************************************************************
2
3   Module: Spawn replacement for UNIXes
4   Description:
5   This module provides spawnv and spawnvp functions for UNIX.@*
6   Copyright 1999 by Salvador E. Tropea. You can use it under the terms of
7 the GPL license. e-mail: salvador@inti.gov.ar, set@computer.org
8
9   Include: spawn.h
10
11 ***************************************************************************/
12
13 #ifndef __DJGPP__
14 #ifndef __MINGW32__
15
16 #include <unistd.h>
17 #include <sys/wait.h>
18 #include "spawn.h"
19
20 /**[txh]********************************************************************
21
22   Description:
23   That's a replacement for the DOS spawnv function which was POSIX during
24 the drafts but then was removed. It avoids the need of the fork/exec/wait
25 sequence which doesn't work for djgpp.
26
27 ***************************************************************************/
28
29 int 
30 spawnv (int mode, const char *path, char *const argv[])
31 {
32   int pStatus;
33
34   if (mode == P_OVERLAY)
35     return execv (path, argv);
36   if (!fork ())
37     {
38       if (execv (path, argv))
39         return -1;
40     }
41   if (mode == P_WAIT)
42     wait (&pStatus);
43   return 0;
44 }
45
46 /**[txh]********************************************************************
47
48   Description:
49   Same as spawnv but using execvp. @x{spawnv}.
50
51 ***************************************************************************/
52
53 int 
54 spawnvp (int mode, const char *path, char *const argv[])
55 {
56   int pStatus;
57
58   if (mode == P_OVERLAY)
59     return execv (path, argv);
60   if (!fork ())
61     {
62       if (execvp (path, argv))
63         return -1;
64     }
65   if (mode == P_WAIT)
66     wait (&pStatus);
67   return 0;
68 }
69 #endif
70 #endif