1 | /* Reentrant versions of execution system calls. These |
---|
2 | implementations just call the usual system calls. */ |
---|
3 | |
---|
4 | #include <reent.h> |
---|
5 | #include <unistd.h> |
---|
6 | #include <sys/wait.h> |
---|
7 | #include <_syslist.h> |
---|
8 | |
---|
9 | /* Some targets provides their own versions of these functions. Those |
---|
10 | targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ |
---|
11 | |
---|
12 | #ifdef _REENT_ONLY |
---|
13 | #ifndef REENTRANT_SYSCALLS_PROVIDED |
---|
14 | #define REENTRANT_SYSCALLS_PROVIDED |
---|
15 | #endif |
---|
16 | #endif |
---|
17 | |
---|
18 | /* If NO_EXEC is defined, we don't need these functions. */ |
---|
19 | |
---|
20 | #if defined (REENTRANT_SYSCALLS_PROVIDED) || defined (NO_EXEC) |
---|
21 | |
---|
22 | int _dummy_exec_syscalls = 1; |
---|
23 | |
---|
24 | #else |
---|
25 | |
---|
26 | /* We use the errno variable used by the system dependent layer. */ |
---|
27 | #undef errno |
---|
28 | extern int errno; |
---|
29 | |
---|
30 | /* |
---|
31 | FUNCTION |
---|
32 | <<_execve_r>>---Reentrant version of execve |
---|
33 | INDEX |
---|
34 | _execve_r |
---|
35 | |
---|
36 | SYNOPSIS |
---|
37 | #include <reent.h> |
---|
38 | int _execve_r(struct _reent *<[ptr]>, const char *<[name]>, |
---|
39 | char *const <[argv]>[], char *const <[env]>[]); |
---|
40 | |
---|
41 | DESCRIPTION |
---|
42 | This is a reentrant version of <<execve>>. It |
---|
43 | takes a pointer to the global data block, which holds |
---|
44 | <<errno>>. |
---|
45 | */ |
---|
46 | |
---|
47 | int |
---|
48 | _execve_r (struct _reent *ptr, |
---|
49 | const char *name, |
---|
50 | char *const argv[], |
---|
51 | char *const env[]) |
---|
52 | { |
---|
53 | int ret; |
---|
54 | |
---|
55 | errno = 0; |
---|
56 | if ((ret = _execve (name, argv, env)) == -1 && errno != 0) |
---|
57 | ptr->_errno = errno; |
---|
58 | return ret; |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | /* |
---|
63 | NEWPAGE |
---|
64 | FUNCTION |
---|
65 | <<_fork_r>>---Reentrant version of fork |
---|
66 | |
---|
67 | INDEX |
---|
68 | _fork_r |
---|
69 | |
---|
70 | SYNOPSIS |
---|
71 | #include <reent.h> |
---|
72 | int _fork_r(struct _reent *<[ptr]>); |
---|
73 | |
---|
74 | DESCRIPTION |
---|
75 | This is a reentrant version of <<fork>>. It |
---|
76 | takes a pointer to the global data block, which holds |
---|
77 | <<errno>>. |
---|
78 | */ |
---|
79 | |
---|
80 | #ifndef NO_FORK |
---|
81 | |
---|
82 | int |
---|
83 | _fork_r (struct _reent *ptr) |
---|
84 | { |
---|
85 | int ret; |
---|
86 | |
---|
87 | errno = 0; |
---|
88 | if ((ret = _fork ()) == -1 && errno != 0) |
---|
89 | ptr->_errno = errno; |
---|
90 | return ret; |
---|
91 | } |
---|
92 | |
---|
93 | #endif |
---|
94 | |
---|
95 | /* |
---|
96 | NEWPAGE |
---|
97 | FUNCTION |
---|
98 | <<_wait_r>>---Reentrant version of wait |
---|
99 | |
---|
100 | INDEX |
---|
101 | _wait_r |
---|
102 | |
---|
103 | SYNOPSIS |
---|
104 | #include <reent.h> |
---|
105 | int _wait_r(struct _reent *<[ptr]>, int *<[status]>); |
---|
106 | |
---|
107 | DESCRIPTION |
---|
108 | This is a reentrant version of <<wait>>. It |
---|
109 | takes a pointer to the global data block, which holds |
---|
110 | <<errno>>. |
---|
111 | */ |
---|
112 | |
---|
113 | int |
---|
114 | _wait_r (struct _reent *ptr, |
---|
115 | int *status) |
---|
116 | { |
---|
117 | int ret; |
---|
118 | |
---|
119 | errno = 0; |
---|
120 | if ((ret = _wait (status)) == -1 && errno != 0) |
---|
121 | ptr->_errno = errno; |
---|
122 | return ret; |
---|
123 | } |
---|
124 | |
---|
125 | #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ |
---|