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