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