GNU Octave 10.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-2025 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
48
50
51int
52dup2 (int old_fd, int new_fd)
53{
54 std::string msg;
55 return sys::dup2 (old_fd, new_fd, msg);
56}
57
58int
59dup2 (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
73int
74execvp (const std::string& file, const string_vector& argv)
75{
76 std::string msg;
77 return sys::execvp (file, argv, msg);
78}
79
80int
81execvp (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
98pid_t
99fork (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
116pid_t
117vfork (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
137pid_t
138getpgrp (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
148pid_t
150{
151 return octave_getpid_wrapper ();
152}
153
154pid_t
156{
157 return octave_getppid_wrapper ();
158}
159
160gid_t
162{
163 return octave_getgid_wrapper ();
164}
165
166gid_t
168{
169 return octave_getegid_wrapper ();
170}
171
172uid_t
174{
175 return octave_getuid_wrapper ();
176}
177
178uid_t
180{
181 return octave_geteuid_wrapper ();
182}
183
184int
185pipe (int *fildes)
186{
187 std::string msg;
188 return sys::pipe (fildes, msg);
189}
190
191int
192pipe (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
206pid_t
207waitpid (pid_t pid, int *status, int options)
208{
209 std::string msg;
210 return sys::waitpid (pid, status, options, msg);
211}
212
213pid_t
214waitpid (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
228int
230{
231 return octave_wcontinue_wrapper ();
232}
233
234int
235wcoredump (int status)
236{
237 return octave_wcoredump_wrapper (status);
238}
239
240bool
241wifcontinued (int status)
242{
243 return octave_wifcontinued_wrapper (status);
244}
245
246bool
247wifexited (int status)
248{
249 return octave_wifexited_wrapper (status);
250}
251
252bool
253wifsignaled (int status)
254{
255 return octave_wifsignaled_wrapper (status);
256}
257
258bool
259wifstopped (int status)
260{
261 return octave_wifstopped_wrapper (status);
262}
263
264int
265wexitstatus (int status)
266{
267 return octave_wexitstatus_wrapper (status);
268}
269
270int
272{
273 return octave_wnohang_wrapper ();
274}
275
276int
277wstopsig (int status)
278{
279 return octave_wstopsig_wrapper (status);
280}
281
282int
283wtermsig (int status)
284{
285 return octave_wtermsig_wrapper (status);
286}
287
288int
290{
291 return octave_wuntraced_wrapper ();
292}
293
294int
295kill (pid_t pid, int sig)
296{
297 std::string msg;
298 return sys::kill (pid, sig, msg);
299}
300
301int
302kill (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
321pid_t
322popen2 (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
329pid_t
330popen2 (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
347int
348fcntl (int fd, int cmd, long arg)
349{
350 std::string msg;
351 return sys::fcntl (fd, cmd, arg, msg);
352}
353
354int
355fcntl (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
369OCTAVE_END_NAMESPACE(sys)
370OCTAVE_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)