perl hack to pack an Intel HEX format output file
[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
15 #include <unistd.h>
16 #include <sys/wait.h>
17 #include "spawn.h"
18
19 /**[txh]********************************************************************
20
21   Description:
22   That's a replacement for the DOS spawnv function which was POSIX during
23 the drafts but then was removed. It avoids the need of the fork/exec/wait
24 sequence which doesn't work for djgpp.
25
26 ***************************************************************************/
27
28 int spawnv(int mode, const char *path, char *const argv[])
29 {
30  int pStatus;
31
32  if (mode==P_OVERLAY)
33     return execv(path,argv);
34  if (!fork())
35    {
36     if (execv(path,argv))
37        return -1;
38    }
39  if (mode==P_WAIT)
40     wait(&pStatus);
41  return 0;
42 }
43
44 /**[txh]********************************************************************
45
46   Description:
47   Same as spawnv but using execvp. @x{spawnv}.
48
49 ***************************************************************************/
50
51 int spawnvp(int mode, const char *path, char *const argv[])
52 {
53  int pStatus;
54
55  if (mode==P_OVERLAY)
56     return execv(path,argv);
57  if (!fork())
58    {
59     if (execvp(path,argv))
60        return -1;
61    }
62  if (mode==P_WAIT)
63     wait(&pStatus);
64  return 0;
65 }
66 #endif