GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
oct-syscalls.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include <cerrno>
31#include <cstdlib>
32#include <cstring>
33
34#include "fcntl-wrappers.h"
35#include "lo-utils.h"
36#include "lo-sysdep.h"
37#include "oct-syscalls.h"
38#include "octave-popen2.h"
39#include "signal-wrappers.h"
40#include "str-vec.h"
41#include "unistd-wrappers.h"
42#include "wait-wrappers.h"
43
44#define NOT_SUPPORTED(nm) \
45 nm ": not supported on this system"
46
47namespace octave
48{
49 namespace sys
50 {
51 int
52 dup2 (int old_fd, int new_fd)
53 {
54 std::string msg;
55 return sys::dup2 (old_fd, new_fd, msg);
56 }
57
58 int
59 dup2 (int old_fd, int new_fd, std::string& msg)
60 {
61 msg = "";
62
63 int status = -1;
64
65 status = octave_dup2_wrapper (old_fd, new_fd);
66
67 if (status < 0)
68 msg = std::strerror (errno);
69
70 return status;
71 }
72
73 int
74 execvp (const std::string& file, const string_vector& argv)
75 {
76 std::string msg;
77 return sys::execvp (file, argv, msg);
78 }
79
80 int
81 execvp (const std::string& file, const string_vector& args,
82 std::string& msg)
83 {
84 msg = "";
85
86 char **argv = args.c_str_vec ();
87
88 int status = octave_execvp_wrapper (file.c_str (), argv);
89
91
92 if (status < 0)
93 msg = std::strerror (errno);
94
95 return status;
96 }
97
98 pid_t
99 fork (std::string& msg)
100 {
101 pid_t status = -1;
102
103 if (octave_have_fork ())
104 {
105 status = octave_fork_wrapper ();
106
107 if (status < 0)
108 msg = std::strerror (errno);
109 }
110 else
111 msg = NOT_SUPPORTED ("fork");
112
113 return status;
114 }
115
116 pid_t
117 vfork (std::string& msg)
118 {
119 pid_t status = -1;
120
122 {
123 if (octave_have_vfork ())
124 status = octave_vfork_wrapper ();
125 else
126 status = octave_fork_wrapper ();
127
128 if (status < 0)
129 msg = std::strerror (errno);
130 }
131 else
132 msg = NOT_SUPPORTED ("vfork");
133
134 return status;
135 }
136
137 pid_t
138 getpgrp (std::string& msg)
139 {
140 pid_t status = octave_getpgrp_wrapper ();
141
142 if (status < 0)
143 msg = std::strerror (errno);
144
145 return status;
146 }
147
148 pid_t
149 getpid (void)
150 {
151 return octave_getpid_wrapper ();
152 }
153
154 pid_t
155 getppid (void)
156 {
157 return octave_getppid_wrapper ();
158 }
159
160 gid_t
161 getgid (void)
162 {
163 return octave_getgid_wrapper ();
164 }
165
166 gid_t
167 getegid (void)
168 {
169 return octave_getegid_wrapper ();
170 }
171
172 uid_t
173 getuid (void)
174 {
175 return octave_getuid_wrapper ();
176 }
177
178 uid_t
179 geteuid (void)
180 {
181 return octave_geteuid_wrapper ();
182 }
183
184 int
185 pipe (int *fildes)
186 {
187 std::string msg;
188 return sys::pipe (fildes, msg);
189 }
190
191 int
192 pipe (int *fildes, std::string& msg)
193 {
194 msg = "";
195
196 int status = -1;
197
198 status = octave_pipe_wrapper (fildes);
199
200 if (status < 0)
201 msg = std::strerror (errno);
202
203 return status;
204 }
205
206 pid_t
207 waitpid (pid_t pid, int *status, int options)
208 {
209 std::string msg;
210 return sys::waitpid (pid, status, options, msg);
211 }
212
213 pid_t
214 waitpid (pid_t pid, int *status, int options,
215 std::string& msg)
216 {
217 pid_t retval = -1;
218 msg = "";
219
220 retval = octave_waitpid_wrapper (pid, status, options);
221
222 if (retval < 0)
223 msg = std::strerror (errno);
224
225 return retval;
226 }
227
228 int
230 {
231 return octave_wcontinue_wrapper ();
232 }
233
234 int
235 wcoredump (int status)
236 {
237 return octave_wcoredump_wrapper (status);
238 }
239
240 bool
241 wifcontinued (int status)
242 {
243 return octave_wifcontinued_wrapper (status);
244 }
245
246 bool
247 wifexited (int status)
248 {
249 return octave_wifexited_wrapper (status);
250 }
251
252 bool
253 wifsignaled (int status)
254 {
255 return octave_wifsignaled_wrapper (status);
256 }
257
258 bool
259 wifstopped (int status)
260 {
261 return octave_wifstopped_wrapper (status);
262 }
263
264 int
265 wexitstatus (int status)
266 {
267 return octave_wexitstatus_wrapper (status);
268 }
269
270 int
271 wnohang (void)
272 {
273 return octave_wnohang_wrapper ();
274 }
275
276 int
277 wstopsig (int status)
278 {
279 return octave_wstopsig_wrapper (status);
280 }
281
282 int
283 wtermsig (int status)
284 {
285 return octave_wtermsig_wrapper (status);
286 }
287
288 int
290 {
291 return octave_wuntraced_wrapper ();
292 }
293
294 int
295 kill (pid_t pid, int sig)
296 {
297 std::string msg;
298 return sys::kill (pid, sig, msg);
299 }
300
301 int
302 kill (pid_t pid, int sig, std::string& msg)
303 {
304 msg = "";
305
306 int status = -1;
307
308 if (octave_have_kill ())
309 {
310 status = octave_kill_wrapper (pid, sig);
311
312 if (status < 0)
313 msg = std::strerror (errno);
314 }
315 else
316 msg = NOT_SUPPORTED ("kill");
317
318 return status;
319 }
320
321 pid_t
322 popen2 (const std::string& cmd, const string_vector& args,
323 bool sync_mode, int *fildes)
324 {
325 std::string msg;
326 return sys::popen2 (cmd, args, sync_mode, fildes, msg);
327 }
328
329 pid_t
330 popen2 (const std::string& cmd, const string_vector& args,
331 bool sync_mode, int *fildes, std::string& msg)
332 {
333 char **argv = args.c_str_vec ();
334 const char *errmsg;
335
336 pid_t pid = octave_popen2 (cmd.c_str (), argv, sync_mode, fildes,
337 &errmsg);
338
340
341 if (pid < 0)
342 msg = errmsg;
343
344 return pid;
345 }
346
347 int
348 fcntl (int fd, int cmd, long arg)
349 {
350 std::string msg;
351 return sys::fcntl (fd, cmd, arg, msg);
352 }
353
354 int
355 fcntl (int fd, int cmd, long arg, std::string& msg)
356 {
357 msg = "";
358
359 int status = -1;
360
361 status = octave_fcntl_wrapper (fd, cmd, arg);
362
363 if (status < 0)
364 msg = std::strerror (errno);
365
366 return status;
367 }
368 }
369}
char ** c_str_vec(void) const
Definition: str-vec.cc:157
static void delete_c_str_vec(const char *const *)
Definition: str-vec.cc:185
int octave_fcntl_wrapper(int fd, int cmd, int arg)
pid_t getppid(void)
int wexitstatus(int status)
int wtermsig(int status)
pid_t getpid(void)
int pipe(int *fildes)
gid_t getegid(void)
gid_t getgid(void)
pid_t getpgrp(std::string &msg)
bool wifstopped(int status)
pid_t popen2(const std::string &cmd, const string_vector &args, bool sync_mode, int *fildes)
int execvp(const std::string &file, const string_vector &argv)
Definition: oct-syscalls.cc:74
int wstopsig(int status)
bool wifsignaled(int status)
int kill(pid_t pid, int sig)
pid_t waitpid(pid_t pid, int *status, int options)
bool wifcontinued(int status)
int wcontinue(void)
uid_t getuid(void)
int fcntl(int fd, int cmd, long arg)
int dup2(int old_fd, int new_fd)
Definition: oct-syscalls.cc:52
int wnohang(void)
bool wifexited(int status)
uid_t geteuid(void)
int wcoredump(int status)
pid_t fork(std::string &msg)
Definition: oct-syscalls.cc:99
int wuntraced(void)
pid_t vfork(std::string &msg)
#define NOT_SUPPORTED(nm)
Definition: oct-syscalls.cc:44
pid_t octave_popen2(const char *cmd, char *const *args, bool sync_mode, int *fildes, const char **errmsg)
int octave_kill_wrapper(pid_t pid, int signum)
bool octave_have_kill(void)
gid_t octave_getgid_wrapper(void)
uid_t octave_geteuid_wrapper(void)
pid_t octave_fork_wrapper(void)
pid_t octave_getpgrp_wrapper(void)
pid_t octave_getppid_wrapper(void)
bool octave_have_vfork(void)
int octave_execvp_wrapper(const char *file, char *const *argv)
gid_t octave_getegid_wrapper(void)
pid_t octave_getpid_wrapper(void)
uid_t octave_getuid_wrapper(void)
pid_t octave_vfork_wrapper(void)
bool octave_have_fork(void)
int octave_dup2_wrapper(int fd1, int fd2)
int octave_pipe_wrapper(int *fd)
int octave_wuntraced_wrapper(void)
pid_t octave_waitpid_wrapper(pid_t pid, int *statusp, int options)
Definition: wait-wrappers.c:61
int octave_wcoredump_wrapper(int status)
bool octave_wifsignaled_wrapper(int status)
bool octave_wifcontinued_wrapper(int status)
bool octave_wifstopped_wrapper(int status)
int octave_wexitstatus_wrapper(int status)
int octave_wcontinue_wrapper(void)
bool octave_wifexited_wrapper(int status)
int octave_wtermsig_wrapper(int status)
int octave_wstopsig_wrapper(int status)
int octave_wnohang_wrapper(void)