GNU Octave 11.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
oct-syscalls.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2026 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 "oct-syscalls.h"
37#include "oct-sysdep.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
49
50int
51dup2 (int old_fd, int new_fd)
52{
53 std::string msg;
54 return sys::dup2 (old_fd, new_fd, msg);
55}
56
57int
58dup2 (int old_fd, int new_fd, std::string& msg)
59{
60 msg = "";
61
62 int status = -1;
63
64 status = octave_dup2_wrapper (old_fd, new_fd);
65
66 if (status < 0)
67 msg = std::strerror (errno);
68
69 return status;
70}
71
72int
73execvp (const std::string& file, const string_vector& argv)
74{
75 std::string msg;
76 return sys::execvp (file, argv, msg);
77}
78
79int
80execvp (const std::string& file, const string_vector& args,
81 std::string& msg)
82{
83 msg = "";
84
85 char **argv = args.c_str_vec ();
86
87 int status = octave_execvp_wrapper (file.c_str (), argv);
88
90
91 if (status < 0)
92 msg = std::strerror (errno);
93
94 return status;
95}
96
97pid_t
98fork (std::string& msg)
99{
100 pid_t status = -1;
101
102 if (octave_have_fork ())
103 {
104 status = octave_fork_wrapper ();
105
106 if (status < 0)
107 msg = std::strerror (errno);
108 }
109 else
110 msg = NOT_SUPPORTED ("fork");
111
112 return status;
113}
114
115pid_t
116vfork (std::string& msg)
117{
118 pid_t status = -1;
119
121 {
122 if (octave_have_vfork ())
123 status = octave_vfork_wrapper ();
124 else
125 status = octave_fork_wrapper ();
126
127 if (status < 0)
128 msg = std::strerror (errno);
129 }
130 else
131 msg = NOT_SUPPORTED ("vfork");
132
133 return status;
134}
135
136pid_t
137getpgrp (std::string& msg)
138{
139 pid_t status = octave_getpgrp_wrapper ();
140
141 if (status < 0)
142 msg = std::strerror (errno);
143
144 return status;
145}
146
147pid_t
149{
150 return octave_getpid_wrapper ();
151}
152
153pid_t
155{
156 return octave_getppid_wrapper ();
157}
158
159gid_t
161{
162 return octave_getgid_wrapper ();
163}
164
165gid_t
167{
168 return octave_getegid_wrapper ();
169}
170
171uid_t
173{
174 return octave_getuid_wrapper ();
175}
176
177uid_t
179{
180 return octave_geteuid_wrapper ();
181}
182
183int
184pipe (int *fildes)
185{
186 std::string msg;
187 return sys::pipe (fildes, msg);
188}
189
190int
191pipe (int *fildes, std::string& msg)
192{
193 msg = "";
194
195 int status = -1;
196
197 status = octave_pipe_wrapper (fildes);
198
199 if (status < 0)
200 msg = std::strerror (errno);
201
202 return status;
203}
204
205pid_t
206waitpid (pid_t pid, int *status, int options)
207{
208 std::string msg;
209 return sys::waitpid (pid, status, options, msg);
210}
211
212pid_t
213waitpid (pid_t pid, int *status, int options,
214 std::string& msg)
215{
216 pid_t retval = -1;
217 msg = "";
218
219 retval = octave_waitpid_wrapper (pid, status, options);
220
221 if (retval < 0)
222 msg = std::strerror (errno);
223
224 return retval;
225}
226
227int
229{
230 return octave_wcontinue_wrapper ();
231}
232
233int
234wcoredump (int status)
235{
236 return octave_wcoredump_wrapper (status);
237}
238
239bool
240wifcontinued (int status)
241{
242 return octave_wifcontinued_wrapper (status);
243}
244
245bool
246wifexited (int status)
247{
248 return octave_wifexited_wrapper (status);
249}
250
251bool
252wifsignaled (int status)
253{
254 return octave_wifsignaled_wrapper (status);
255}
256
257bool
258wifstopped (int status)
259{
260 return octave_wifstopped_wrapper (status);
261}
262
263int
264wexitstatus (int status)
265{
266 return octave_wexitstatus_wrapper (status);
267}
268
269int
271{
272 return octave_wnohang_wrapper ();
273}
274
275int
276wstopsig (int status)
277{
278 return octave_wstopsig_wrapper (status);
279}
280
281int
282wtermsig (int status)
283{
284 return octave_wtermsig_wrapper (status);
285}
286
287int
289{
290 return octave_wuntraced_wrapper ();
291}
292
293int
294kill (pid_t pid, int sig)
295{
296 std::string msg;
297 return sys::kill (pid, sig, msg);
298}
299
300int
301kill (pid_t pid, int sig, std::string& msg)
302{
303 msg = "";
304
305 int status = -1;
306
307 if (octave_have_kill ())
308 {
309 status = octave_kill_wrapper (pid, sig);
310
311 if (status < 0)
312 msg = std::strerror (errno);
313 }
314 else
315 msg = NOT_SUPPORTED ("kill");
316
317 return status;
318}
319
320pid_t
321popen2 (const std::string& cmd, const string_vector& args,
322 bool sync_mode, int *fildes)
323{
324 std::string msg;
325 return sys::popen2 (cmd, args, sync_mode, fildes, msg);
326}
327
328pid_t
329popen2 (const std::string& cmd, const string_vector& args,
330 bool sync_mode, int *fildes, std::string& msg)
331{
332 char **argv = args.c_str_vec ();
333 const char *errmsg;
334
335 pid_t pid = octave_popen2 (cmd.c_str (), argv, sync_mode, fildes, &errmsg);
336
338
339 if (pid < 0)
340 msg = errmsg;
341
342 return pid;
343}
344
345int
346fcntl (int fd, int cmd, long arg)
347{
348 std::string msg;
349 return sys::fcntl (fd, cmd, arg, msg);
350}
351
352int
353fcntl (int fd, int cmd, long arg, std::string& msg)
354{
355 msg = "";
356
357 int status = -1;
358
359 status = octave_fcntl_wrapper (fd, cmd, arg);
360
361 if (status < 0)
362 msg = std::strerror (errno);
363
364 return status;
365}
366
367OCTAVE_END_NAMESPACE(sys)
368OCTAVE_END_NAMESPACE(octave)
static void delete_c_str_vec(const char *const *)
Definition str-vec.cc:185
char ** c_str_vec() const
Definition str-vec.cc:157
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
int octave_fcntl_wrapper(int fd, int cmd, int arg)
bool wifexited(int status)
int pipe(int *fildes)
pid_t fork(std::string &msg)
int execvp(const std::string &file, const string_vector &argv)
int wstopsig(int status)
int kill(pid_t pid, int sig)
pid_t getppid()
int wexitstatus(int status)
pid_t getpgrp(std::string &msg)
pid_t waitpid(pid_t pid, int *status, int options)
bool wifstopped(int status)
bool wifcontinued(int status)
bool wifsignaled(int status)
gid_t getegid()
int wtermsig(int status)
int wuntraced()
uid_t getuid()
#define NOT_SUPPORTED(nm)
gid_t getgid()
int wnohang()
int wcoredump(int status)
int fcntl(int fd, int cmd, long arg)
pid_t vfork(std::string &msg)
pid_t getpid()
uid_t geteuid()
pid_t popen2(const std::string &cmd, const string_vector &args, bool sync_mode, int *fildes)
int dup2(int old_fd, int new_fd)
int wcontinue()
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)
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)