Properly install packihx utility
[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 spawnv(int mode, const char *path, char *const argv[])
30 {
31  int pStatus;
32
33  if (mode==P_OVERLAY)
34     return execv(path,argv);
35  if (!fork())
36    {
37     if (execv(path,argv))
38        return -1;
39    }
40  if (mode==P_WAIT)
41     wait(&pStatus);
42  return 0;
43 }
44
45 /**[txh]********************************************************************
46
47   Description:
48   Same as spawnv but using execvp. @x{spawnv}.
49
50 ***************************************************************************/
51
52 int spawnvp(int mode, const char *path, char *const argv[])
53 {
54  int pStatus;
55
56  if (mode==P_OVERLAY)
57     return execv(path,argv);
58  if (!fork())
59    {
60     if (execvp(path,argv))
61        return -1;
62    }
63  if (mode==P_WAIT)
64     wait(&pStatus);
65  return 0;
66 }
67 #endif
68 #endif