2941
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2941
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include <cerrno> |
|
29 |
|
30 #include <string.h> |
|
31 |
|
32 #ifdef HAVE_SYS_TYPES_H |
|
33 #include <sys/types.h> |
|
34 #endif |
|
35 |
|
36 #ifdef HAVE_UNISTD_H |
|
37 #include <unistd.h> |
|
38 #endif |
|
39 |
|
40 #ifdef HAVE_FCNTL_H |
|
41 #include <fcntl.h> |
|
42 #endif |
|
43 |
4299
|
44 // We can't use csignal as kill is not in the std namespace, and picky |
|
45 // compiler runtimes will also exclude it from global scope as well. |
|
46 |
|
47 #include <signal.h> |
|
48 |
5453
|
49 #include "lo-utils.h" |
2941
|
50 #include "oct-syscalls.h" |
|
51 #include "str-vec.h" |
|
52 |
|
53 #define NOT_SUPPORTED(nm) \ |
4062
|
54 nm ": not supported on this system" |
2941
|
55 |
|
56 int |
|
57 octave_syscalls::dup2 (int old_fd, int new_fd) |
|
58 { |
3504
|
59 std::string msg; |
2941
|
60 return dup2 (old_fd, new_fd, msg); |
|
61 } |
|
62 |
|
63 int |
3504
|
64 octave_syscalls::dup2 (int old_fd, int new_fd, std::string& msg) |
2941
|
65 { |
3504
|
66 msg = std::string (); |
2941
|
67 |
|
68 int status = -1; |
|
69 |
|
70 #if defined (HAVE_DUP2) |
|
71 status = ::dup2 (old_fd, new_fd); |
|
72 |
|
73 if (status < 0) |
3504
|
74 { |
|
75 using namespace std; |
|
76 msg = ::strerror (errno); |
|
77 } |
2941
|
78 #else |
|
79 msg = NOT_SUPPORTED ("dup2"); |
|
80 #endif |
|
81 |
|
82 return status; |
|
83 } |
|
84 |
|
85 int |
3504
|
86 octave_syscalls::execvp (const std::string& file, const string_vector& argv) |
2941
|
87 { |
3504
|
88 std::string msg; |
2941
|
89 return execvp (file, argv, msg); |
|
90 } |
|
91 |
|
92 int |
3504
|
93 octave_syscalls::execvp (const std::string& file, const string_vector& args, |
|
94 std::string& msg) |
2941
|
95 { |
3504
|
96 msg = std::string (); |
2941
|
97 |
|
98 int status = -1; |
|
99 |
|
100 #if defined (HAVE_EXECVP) |
|
101 char **argv = args.c_str_vec (); |
|
102 |
|
103 status = ::execvp (file.c_str (), argv); |
|
104 |
|
105 string_vector::delete_c_str_vec (argv); |
|
106 |
|
107 if (status < 0) |
3504
|
108 { |
|
109 using namespace std; |
|
110 msg = ::strerror (errno); |
|
111 } |
2941
|
112 #else |
|
113 msg = NOT_SUPPORTED ("execvp"); |
|
114 #endif |
|
115 |
|
116 return status; |
|
117 } |
|
118 |
|
119 int |
|
120 octave_syscalls::fcntl (int fd, int cmd, long arg) |
|
121 { |
3504
|
122 std::string msg; |
2941
|
123 return fcntl (fd, cmd, arg, msg); |
|
124 } |
|
125 |
|
126 int |
3504
|
127 octave_syscalls::fcntl (int fd, int cmd, long arg, std::string& msg) |
2941
|
128 { |
3504
|
129 msg = std::string (); |
2941
|
130 |
|
131 int status = -1; |
|
132 |
|
133 #if defined (HAVE_FCNTL) |
|
134 status = ::fcntl (fd, cmd, arg); |
|
135 |
|
136 if (status < 0) |
3504
|
137 { |
|
138 using namespace std; |
|
139 msg = ::strerror (errno); |
|
140 } |
2941
|
141 #else |
|
142 msg = NOT_SUPPORTED ("fcntl"); |
|
143 #endif |
|
144 |
|
145 return status; |
|
146 } |
|
147 |
|
148 pid_t |
3504
|
149 octave_syscalls::fork (std::string& msg) |
2941
|
150 { |
|
151 pid_t status = -1; |
|
152 |
|
153 #if defined (HAVE_FORK) |
|
154 status = ::fork (); |
|
155 |
|
156 if (status < 0) |
3504
|
157 { |
|
158 using namespace std; |
|
159 msg = ::strerror (errno); |
|
160 } |
2941
|
161 #else |
|
162 msg = NOT_SUPPORTED ("fork"); |
|
163 #endif |
|
164 |
|
165 return status; |
|
166 } |
|
167 |
|
168 pid_t |
3504
|
169 octave_syscalls::vfork (std::string& msg) |
3147
|
170 { |
|
171 pid_t status = -1; |
|
172 |
|
173 #if defined (HAVE_VFORK) || defined (HAVE_FORK) |
|
174 #if defined (HAVE_VFORK) |
|
175 status = ::vfork (); |
|
176 #else |
3148
|
177 status = ::fork (); |
3147
|
178 #endif |
|
179 |
|
180 if (status < 0) |
3504
|
181 { |
|
182 using namespace std; |
|
183 msg = ::strerror (errno); |
|
184 } |
3147
|
185 #else |
|
186 msg = NOT_SUPPORTED ("vfork"); |
|
187 #endif |
|
188 |
|
189 return status; |
|
190 } |
|
191 |
|
192 pid_t |
3504
|
193 octave_syscalls::getpgrp (std::string& msg) |
2941
|
194 { |
|
195 pid_t status = -1; |
|
196 |
|
197 #if defined (HAVE_GETPGRP) |
|
198 status = ::getpgrp (); |
|
199 |
|
200 if (status < 0) |
3504
|
201 { |
|
202 using namespace std; |
|
203 msg = ::strerror (errno); |
|
204 } |
2941
|
205 #else |
|
206 msg = NOT_SUPPORTED ("getpgrp"); |
|
207 #endif |
|
208 |
|
209 return status; |
|
210 } |
|
211 |
|
212 pid_t |
|
213 octave_syscalls::getpid (void) |
|
214 { |
|
215 #if defined (HAVE_GETPID) |
|
216 return ::getpid (); |
|
217 #else |
|
218 return 0; |
|
219 #endif |
|
220 } |
|
221 |
|
222 pid_t |
|
223 octave_syscalls::getppid (void) |
|
224 { |
|
225 #if defined (HAVE_GETPPID) |
|
226 return ::getppid (); |
|
227 #else |
|
228 return 0; |
|
229 #endif |
|
230 } |
|
231 |
|
232 gid_t |
|
233 octave_syscalls::getgid (void) |
|
234 { |
|
235 #if defined (HAVE_GETGID) |
|
236 return ::getgid (); |
|
237 #else |
|
238 return 0; |
|
239 #endif |
|
240 } |
|
241 |
|
242 gid_t |
|
243 octave_syscalls::getegid (void) |
|
244 { |
|
245 #if defined (HAVE_GETEGID) |
|
246 return ::getegid (); |
|
247 #else |
|
248 return 0; |
|
249 #endif |
|
250 } |
|
251 |
|
252 uid_t |
|
253 octave_syscalls::getuid (void) |
|
254 { |
|
255 #if defined (HAVE_GETUID) |
|
256 return ::getuid (); |
|
257 #else |
|
258 return 0; |
|
259 #endif |
|
260 } |
|
261 |
|
262 uid_t |
|
263 octave_syscalls::geteuid (void) |
|
264 { |
|
265 #if defined (HAVE_GETEUID) |
|
266 return ::geteuid (); |
|
267 #else |
|
268 return 0; |
|
269 #endif |
|
270 } |
|
271 |
|
272 int |
|
273 octave_syscalls::pipe (int *fildes) |
|
274 { |
3504
|
275 std::string msg; |
6123
|
276 return pipe (fildes, msg); |
2941
|
277 } |
|
278 |
|
279 int |
3504
|
280 octave_syscalls::pipe (int *fildes, std::string& msg) |
2941
|
281 { |
3504
|
282 msg = std::string (); |
2941
|
283 |
|
284 int status = -1; |
|
285 |
|
286 #if defined (HAVE_PIPE) |
|
287 status = ::pipe (fildes); |
|
288 |
|
289 if (status < 0) |
3504
|
290 { |
|
291 using namespace std; |
|
292 msg = ::strerror (errno); |
|
293 } |
2941
|
294 #else |
|
295 msg = NOT_SUPPORTED ("pipe"); |
|
296 #endif |
|
297 |
|
298 return status; |
|
299 } |
|
300 |
|
301 pid_t |
5453
|
302 octave_syscalls::waitpid (pid_t pid, int *status, int options) |
2941
|
303 { |
3504
|
304 std::string msg; |
5453
|
305 return waitpid (pid, status, options, msg); |
2941
|
306 } |
|
307 |
|
308 pid_t |
5453
|
309 octave_syscalls::waitpid (pid_t pid, int *status, int options, |
|
310 std::string& msg) |
2941
|
311 { |
6060
|
312 pid_t retval = -1; |
3504
|
313 msg = std::string (); |
2941
|
314 |
5453
|
315 #if defined (HAVE_WAITPID) |
6060
|
316 retval = ::octave_waitpid (pid, status, options); |
2941
|
317 |
5453
|
318 if (retval < 0) |
3504
|
319 { |
|
320 using namespace std; |
|
321 msg = ::strerror (errno); |
|
322 } |
2941
|
323 #else |
|
324 msg = NOT_SUPPORTED ("waitpid"); |
|
325 #endif |
|
326 |
5453
|
327 return retval; |
2941
|
328 } |
|
329 |
4294
|
330 int |
|
331 octave_syscalls::kill (pid_t pid, int sig) |
|
332 { |
|
333 std::string msg; |
|
334 return kill (pid, sig, msg); |
|
335 } |
|
336 |
|
337 int |
|
338 octave_syscalls::kill (pid_t pid, int sig, std::string& msg) |
|
339 { |
|
340 msg = std::string (); |
|
341 |
|
342 int status = -1; |
|
343 |
|
344 #if defined (HAVE_KILL) |
|
345 status = ::kill (pid, sig); |
|
346 |
|
347 if (status < 0) |
|
348 { |
|
349 using namespace std; |
|
350 msg = ::strerror (errno); |
|
351 } |
|
352 #else |
|
353 msg = NOT_SUPPORTED ("kill"); |
|
354 #endif |
|
355 |
|
356 return status; |
|
357 } |
|
358 |
2941
|
359 /* |
|
360 ;;; Local Variables: *** |
|
361 ;;; mode: C++ *** |
|
362 ;;; End: *** |
|
363 */ |