GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
syscalls.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2021 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 // Thomas Baier <baier@ci.tuwien.ac.at> added the original versions of
27 // the following functions:
28 //
29 // mkfifo unlink waitpid
30 
31 #if defined (HAVE_CONFIG_H)
32 # include "config.h"
33 #endif
34 
35 #include <ctime>
36 #include <cstdio>
37 #include <cstring>
38 
39 #include "cmd-hist.h"
40 #include "fcntl-wrappers.h"
41 #include "file-ops.h"
42 #include "file-stat.h"
43 #include "lo-utils.h"
44 #include "oct-env.h"
45 #include "oct-syscalls.h"
46 #include "oct-uname.h"
47 
48 #include "defun.h"
49 #include "error.h"
50 #include "errwarn.h"
51 #include "event-manager.h"
52 #include "input.h"
53 #include "interpreter.h"
54 #include "oct-hist.h"
55 #include "oct-map.h"
56 #include "oct-stdstrm.h"
57 #include "oct-stream.h"
58 #include "ovl.h"
59 #include "sysdep.h"
60 #include "utils.h"
61 #include "variables.h"
62 
63 static octave_scalar_map
65 {
66  static bool have_rdev
68  static bool have_blksize
70  static bool have_blocks
72 
73  static double nan = octave::numeric_limits<double>::NaN ();
74 
76 
77  m.assign ("dev", static_cast<double> (fs.dev ()));
78  m.assign ("ino", fs.ino ());
79  m.assign ("mode", fs.mode ());
80  m.assign ("modestr", fs.mode_as_string ());
81  m.assign ("nlink", fs.nlink ());
82  m.assign ("uid", fs.uid ());
83  m.assign ("gid", fs.gid ());
84  m.assign ("rdev", have_rdev ? static_cast<double> (fs.rdev ()) : nan);
85  m.assign ("size", fs.size ());
86  m.assign ("atime", fs.atime ());
87  m.assign ("mtime", fs.mtime ());
88  m.assign ("ctime", fs.ctime ());
89 
90  if (have_blksize)
91  m.assign ("blksize", fs.blksize ());
92  else
93  m.assign ("blksize", nan);
94 
95  if (have_blocks)
96  m.assign ("blocks", fs.blocks ());
97  else
98  m.assign ("blocks", nan);
99 
100  return m;
101 }
102 
103 static octave_value_list
105 {
106  if (fs)
107  return ovl (octave_value (mk_stat_map (fs)), 0, "");
108  else
109  return ovl (Matrix (), -1, fs.error ());
110 }
111 
112 DEFMETHODX ("dup2", Fdup2, interp, args, ,
113  doc: /* -*- texinfo -*-
114 @deftypefn {} {[@var{fid}, @var{msg}] =} dup2 (@var{old}, @var{new})
115 Duplicate a file descriptor.
116 
117 If successful, @var{fid} is greater than zero and contains the new file ID@.
118 Otherwise, @var{fid} is negative and @var{msg} contains a system-dependent
119 error message.
120 @seealso{fopen, fclose, fcntl}
121 @end deftypefn */)
122 {
123  if (args.length () != 2)
124  print_usage ();
125 
126  octave::stream_list& streams = interp.get_stream_list ();
127 
128  octave::stream old_stream = streams.lookup (args(0), "dup2");
129 
130  octave::stream new_stream = streams.lookup (args(1), "dup2");
131 
132  int i_old = old_stream.file_number ();
133  int i_new = new_stream.file_number ();
134 
135  if (i_old >= 0 && i_new >= 0)
136  {
137  std::string msg;
138 
139  int status = octave::sys::dup2 (i_old, i_new, msg);
140 
141  return ovl (status, msg);
142  }
143  else
144  return ovl (-1, "");
145 }
146 
147 DEFMETHODX ("exec", Fexec, interp, args, ,
148  doc: /* -*- texinfo -*-
149 @deftypefn {} {[@var{err}, @var{msg}] =} exec (@var{file}, @var{args})
150 Replace current process with a new process.
151 
152 Calling @code{exec} without first calling @code{fork} will terminate your
153 current Octave process and replace it with the program named by @var{file}.
154 For example,
155 
156 @example
157 exec ("ls", "-l")
158 @end example
159 
160 @noindent
161 will run @code{ls} and return you to your shell prompt.
162 
163 If successful, @code{exec} does not return. If @code{exec} does return,
164 @var{err} will be nonzero, and @var{msg} will contain a system-dependent
165 error message.
166 @end deftypefn */)
167 {
168  int nargin = args.length ();
169 
170  if (nargin < 1 || nargin > 2)
171  print_usage ();
172 
173  std::string exec_file = args(0).xstring_value ("exec: FILE must be a string");
174 
175  string_vector exec_args;
176 
177  if (nargin == 2)
178  {
179  string_vector tmp = args(1).xstring_vector_value ("exec: all arguments must be strings");
180 
181  int len = tmp.numel ();
182 
183  exec_args.resize (len + 1);
184 
185  exec_args[0] = exec_file;
186 
187  for (int i = 0; i < len; i++)
188  exec_args[i+1] = tmp[i];
189  }
190  else
191  {
192  exec_args.resize (1);
193 
194  exec_args[0] = exec_file;
195  }
196 
197  octave::history_system& history_sys = interp.get_history_system ();
198 
199  history_sys.write_timestamp ();
200 
203 
204  std::string msg;
205 
206  int status = octave::sys::execvp (exec_file, exec_args, msg);
207 
208  return ovl (status, msg);
209 }
210 
211 DEFMETHODX ("popen2", Fpopen2, interp, args, ,
212  doc: /* -*- texinfo -*-
213 @deftypefn {} {[@var{in}, @var{out}, @var{pid}] =} popen2 (@var{command}, @var{args})
214 Start a subprocess with two-way communication.
215 
216 The name of the process is given by @var{command}, and @var{args} is an
217 array or cell array of strings containing options for the command.
218 
219 The file identifiers for the input and output streams of the subprocess are
220 returned in @var{in} and @var{out}. If execution of the command is
221 successful, @var{pid} contains the process ID of the subprocess. Otherwise,
222 @var{pid} is @minus{}1.
223 
224 For example:
225 
226 @example
227 [in, out, pid] = popen2 ("sort", "-r");
228 fputs (in, "these\nare\nsome\nstrings\n");
229 fclose (in);
230 EAGAIN = errno ("EAGAIN");
231 done = false;
232 do
233  s = fgets (out);
234  if (ischar (s))
235  fputs (stdout, s);
236  elseif (errno () == EAGAIN)
237  pause (0.1);
238  fclear (out);
239  else
240  done = true;
241  endif
242 until (done)
243 fclose (out);
244 waitpid (pid);
245 
246  @print{} these
247  @print{} strings
248  @print{} some
249  @print{} are
250 @end example
251 
252 Note that @code{popen2}, unlike @code{popen}, will not @nospell{"reap"}
253 the child process. If you don't use @code{waitpid} to check the child's
254 exit status, it will linger until Octave exits.
255 @seealso{popen, waitpid}
256 @end deftypefn */)
257 {
258  int nargin = args.length ();
259 
260  if (nargin < 1 || nargin > 3)
261  print_usage ();
262 
263  std::string exec_file = args(0).xstring_value ("popen2: COMMAND argument must be a string");
264 
265  string_vector arg_list;
266 
267  if (nargin >= 2)
268  {
269  string_vector tmp = args(1).xstring_vector_value ("popen2: all arguments must be strings");
270 
271  int len = tmp.numel ();
272 
273  arg_list.resize (len + 1);
274 
275  arg_list[0] = exec_file;
276 
277  for (int i = 0; i < len; i++)
278  arg_list[i+1] = tmp[i];
279  }
280  else
281  {
282  arg_list.resize (1);
283 
284  arg_list[0] = exec_file;
285  }
286 
287  bool sync_mode = (nargin == 3 ? args(2).bool_value () : false);
288 
289  int filedesc[2];
290  std::string msg;
291  pid_t pid;
292 
293  pid = octave::sys::popen2 (exec_file, arg_list, sync_mode, filedesc, msg);
294 
295  if (pid < 0)
296  error ("%s", msg.c_str ());
297 
298  FILE *ifile = fdopen (filedesc[1], "r");
299  FILE *ofile = fdopen (filedesc[0], "w");
300 
301  octave::stream is
302  = octave_stdiostream::create (exec_file + "-in", ifile, std::ios::in);
303 
304  octave::stream os
305  = octave_stdiostream::create (exec_file + "-out", ofile, std::ios::out);
306 
307  octave::stream_list& streams = interp.get_stream_list ();
308 
309  return ovl (streams.insert (os), streams.insert (is), pid);
310 }
311 
312 /*
313 
314 %!test # UNIX-style test
315 %! if (isunix () || ismac ())
316 %! [in, out, pid] = popen2 ("sort", "-r");
317 %! EAGAIN = errno ("EAGAIN");
318 %! fputs (in, "these\nare\nsome\nstrings\n");
319 %! fclose (in);
320 %! done = false;
321 %! str = {};
322 %! idx = 0;
323 %! errs = 0;
324 %! do
325 %! if (ismac ()) # FIXME: Is this necessary?
326 %! errno (0);
327 %! endif
328 %! s = fgets (out);
329 %! if (ischar (s))
330 %! idx++;
331 %! str{idx} = s;
332 %! elseif (errno () == EAGAIN)
333 %! fclear (out);
334 %! pause (0.1);
335 %! if (++errs == 100)
336 %! done = true;
337 %! endif
338 %! else
339 %! done = true;
340 %! endif
341 %! until (done)
342 %! fclose (out);
343 %! waitpid (pid);
344 %! assert (str, {"these\n","strings\n","some\n","are\n"});
345 %! endif
346 
347 %!test # Windows-style test
348 %! if (ispc () && ! isunix ())
349 %! [in, out, pid] = popen2 ('C:\Windows\system32\sort.exe', "/R");
350 %! EAGAIN = errno ("EINVAL");
351 %! fputs (in, "these\r\nare\r\nsome\r\nstrings\r\n");
352 %! fclose (in);
353 %! done = false;
354 %! str = {};
355 %! idx = 0;
356 %! errs = 0;
357 %! do
358 %! errno (0);
359 %! s = fgets (out);
360 %! if (ischar (s))
361 %! idx++;
362 %! str{idx} = s;
363 %! elseif (errno () == EAGAIN)
364 %! fclear (out);
365 %! pause (0.1);
366 %! if (++errs == 100)
367 %! done = true;
368 %! endif
369 %! else
370 %! done = true;
371 %! endif
372 %! until (done)
373 %! fclose (out);
374 %! waitpid (pid);
375 %! assert (str, {"these\r\n","strings\r\n","some\r\n","are\r\n"});
376 %! endif
377 
378 */
379 
380 DEFMETHODX ("fcntl", Ffcntl, interp, args, ,
381  doc: /* -*- texinfo -*-
382 @deftypefn {} {[@var{err}, @var{msg}] =} fcntl (@var{fid}, @var{request}, @var{arg})
383 Change the properties of the open file @var{fid}.
384 
385 The following values may be passed as @var{request}:
386 
387 @vtable @code
388 @item F_DUPFD
389 Return a duplicate file descriptor.
390 
391 @item F_GETFD
392 Return the file descriptor flags for @var{fid}.
393 
394 @item F_SETFD
395 Set the file descriptor flags for @var{fid}.
396 
397 @item F_GETFL
398 Return the file status flags for @var{fid}. The following codes may be
399 returned (some of the flags may be undefined on some systems).
400 
401 @vtable @code
402 @item O_RDONLY
403 Open for reading only.
404 
405 @item O_WRONLY
406 Open for writing only.
407 
408 @item O_RDWR
409 Open for reading and writing.
410 
411 @item O_APPEND
412 Append on each write.
413 
414 @item O_CREAT
415 Create the file if it does not exist.
416 
417 @item O_NONBLOCK
418 Non-blocking mode.
419 
420 @item O_SYNC
421 Wait for writes to complete.
422 
423 @item O_ASYNC
424 Asynchronous I/O.
425 @end vtable
426 
427 @item F_SETFL
428 Set the file status flags for @var{fid} to the value specified by @var{arg}.
429  The only flags that can be changed are @w{@code{O_APPEND}} and
430 @w{@code{O_NONBLOCK}}.
431 @end vtable
432 
433 If successful, @var{err} is 0 and @var{msg} is an empty string. Otherwise,
434 @var{err} is nonzero and @var{msg} contains a system-dependent error
435 message.
436 @seealso{fopen, dup2}
437 @end deftypefn */)
438 {
439  if (args.length () != 3)
440  print_usage ();
441 
442  octave::stream_list& streams = interp.get_stream_list ();
443 
444  octave::stream strm = streams.lookup (args(0), "fcntl");
445 
446  int fid = strm.file_number ();
447 
448  // FIXME: Do we want to use xint_value and throw a warning message
449  // if input validation fails?
450  int req = args(1).int_value (true);
451  int arg = args(2).int_value (true);
452 
453  // FIXME: Need better checking here?
454  if (fid < 0)
455  error ("fcntl: invalid file id");
456 
457  std::string msg;
458 
459  int status = octave::sys::fcntl (fid, req, arg, msg);
460 
461  return ovl (status, msg);
462 }
463 
464 DEFMETHODX ("fork", Ffork, interp, args, ,
465  doc: /* -*- texinfo -*-
466 @deftypefn {} {[@var{pid}, @var{msg}] =} fork ()
467 Create a copy of the current process.
468 
469 Fork can return one of the following values:
470 
471 @table @asis
472 @item > 0
473 You are in the parent process. The value returned from @code{fork} is the
474 process id of the child process. You should probably arrange to wait for
475 any child processes to exit.
476 
477 @item 0
478 You are in the child process. You can call @code{exec} to start another
479 process. If that fails, you should probably call @code{exit}.
480 
481 @item < 0
482 The call to @code{fork} failed for some reason. You must take evasive
483 action. A system dependent error message will be waiting in @var{msg}.
484 @end table
485 @end deftypefn */)
486 {
487  if (args.length () != 0)
488  print_usage ();
489 
490  if (interp.at_top_level ())
491  error ("fork: cannot be called from command line");
492 
493  std::string msg;
494 
495  pid_t pid = octave::sys::fork (msg);
496 
497  return ovl (pid, msg);
498 }
499 
500 DEFUNX ("getpgrp", Fgetpgrp, args, ,
501  doc: /* -*- texinfo -*-
502 @deftypefn {} {pgid =} getpgrp ()
503 Return the process group id of the current process.
504 @end deftypefn */)
505 {
506  if (args.length () != 0)
507  print_usage ();
508 
509  std::string msg;
510 
511  pid_t pid = octave::sys::getpgrp (msg);
512 
513  return ovl (pid, msg);
514 }
515 
516 DEFUNX ("getpid", Fgetpid, args, ,
517  doc: /* -*- texinfo -*-
518 @deftypefn {} {pid =} getpid ()
519 Return the process id of the current process.
520 @seealso{getppid}
521 @end deftypefn */)
522 {
523  if (args.length () != 0)
524  print_usage ();
525 
526  return ovl (octave::sys::getpid ());
527 }
528 
529 DEFUNX ("getppid", Fgetppid, args, ,
530  doc: /* -*- texinfo -*-
531 @deftypefn {} {pid =} getppid ()
532 Return the process id of the parent process.
533 @seealso{getpid}
534 @end deftypefn */)
535 {
536  if (args.length () != 0)
537  print_usage ();
538 
539  return ovl (octave::sys::getppid ());
540 }
541 
542 DEFUNX ("getegid", Fgetegid, args, ,
543  doc: /* -*- texinfo -*-
544 @deftypefn {} {egid =} getegid ()
545 Return the effective group id of the current process.
546 @seealso{getgid}
547 @end deftypefn */)
548 {
549  if (args.length () != 0)
550  print_usage ();
551 
552  return ovl (octave::sys::getegid ());
553 }
554 
555 DEFUNX ("getgid", Fgetgid, args, ,
556  doc: /* -*- texinfo -*-
557 @deftypefn {} {gid =} getgid ()
558 Return the real group id of the current process.
559 @seealso{getegid}
560 @end deftypefn */)
561 {
562  if (args.length () != 0)
563  print_usage ();
564 
565  return ovl (octave::sys::getgid ());
566 }
567 
568 DEFUNX ("geteuid", Fgeteuid, args, ,
569  doc: /* -*- texinfo -*-
570 @deftypefn {} {euid =} geteuid ()
571 Return the effective user id of the current process.
572 @seealso{getuid}
573 @end deftypefn */)
574 {
575  if (args.length () != 0)
576  print_usage ();
577 
578  return ovl (octave::sys::geteuid ());
579 }
580 
581 DEFUNX ("getuid", Fgetuid, args, ,
582  doc: /* -*- texinfo -*-
583 @deftypefn {} {uid =} getuid ()
584 Return the real user id of the current process.
585 @seealso{geteuid}
586 @end deftypefn */)
587 {
588  if (args.length () != 0)
589  print_usage ();
590 
591  return ovl (octave::sys::getuid ());
592 }
593 
594 DEFUNX ("kill", Fkill, args, ,
595  doc: /* -*- texinfo -*-
596 @deftypefn {} {[@var{err}, @var{msg}] =} kill (@var{pid}, @var{sig})
597 Send signal @var{sig} to process @var{pid}.
598 
599 If @var{pid} is positive, then signal @var{sig} is sent to @var{pid}.
600 
601 If @var{pid} is 0, then signal @var{sig} is sent to every process
602 in the process group of the current process.
603 
604 If @var{pid} is -1, then signal @var{sig} is sent to every process
605 except process 1.
606 
607 If @var{pid} is less than -1, then signal @var{sig} is sent to every
608 process in the process group @var{-pid}.
609 
610 If @var{sig} is 0, then no signal is sent, but error checking is still
611 performed.
612 
613 Return 0 if successful, otherwise return -1.
614 @end deftypefn */)
615 {
616  if (args.length () != 2)
617  print_usage ();
618 
619  pid_t pid = args(0).int_value (true);
620 
621  int sig = args(1).int_value (true);
622 
623  std::string msg;
624 
625  int status = octave::sys::kill (pid, sig, msg);
626 
627  return ovl (status, msg);
628 }
629 
630 DEFUNX ("lstat", Flstat, args, ,
631  doc: /* -*- texinfo -*-
632 @deftypefn {} {@var{info} =} lstat (@var{symlink})
633 @deftypefnx {} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{symlink})
634 Return a structure @var{info} containing information about the symbolic link
635 @var{symlink}.
636 
637 The function outputs are described in the documentation for @code{stat}.
638 @seealso{stat, symlink}
639 @end deftypefn */)
640 {
641  if (args.length () != 1)
642  print_usage ();
643 
644  std::string fname = args(0).xstring_value ("lstat: NAME must be a string");
645 
646  octave::sys::file_stat fs (fname, false);
647 
648  return mk_stat_result (fs);
649 }
650 
651 // FIXME: This routine also exists verbatim in file-io.cc.
652 // Maybe change to be a general utility routine.
653 static int
654 convert (int x, int ibase, int obase)
655 {
656  int retval = 0;
657 
658  int tmp = x % obase;
659 
660  if (tmp > ibase - 1)
661  error ("mkfifo: invalid digit");
662 
663  retval = tmp;
664  int mult = ibase;
665  while ((x = (x - tmp) / obase))
666  {
667  tmp = x % obase;
668 
669  if (tmp > ibase - 1)
670  error ("mkfifo: invalid digit");
671 
672  retval += mult * tmp;
673  mult *= ibase;
674  }
675 
676  return retval;
677 }
678 
679 DEFUNX ("mkfifo", Fmkfifo, args, ,
680  doc: /* -*- texinfo -*-
681 @deftypefn {} {@var{err} =} mkfifo (@var{name}, @var{mode})
682 @deftypefnx {} {[@var{err}, @var{msg}] =} mkfifo (@var{name}, @var{mode})
683 Create a FIFO special file named @var{name} with file mode @var{mode}.
684 
685 @var{mode} is interpreted as an octal number and is subject to umask
686 processing. The final calculated mode is @code{@var{mode} - @var{umask}}.
687 
688 If successful, @var{err} is 0 and @var{msg} is an empty string.
689 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent
690 error message.
691 @seealso{pipe, umask}
692 @end deftypefn */)
693 {
694  if (args.length () != 2)
695  print_usage ();
696 
697  std::string name = args(0).xstring_value ("mkfifo: FILE must be a string");
698 
699  int octal_mode = args(1).xint_value ("mkfifo: MODE must be an integer");
700 
701  if (octal_mode < 0)
702  error ("mkfifo: MODE must be a positive integer value");
703 
704  int mode = convert (octal_mode, 8, 10);
705 
706  std::string msg;
707 
708  int status = octave::sys::mkfifo (name, mode, msg);
709 
710  return ovl (status, msg);
711 }
712 
713 /*
714 
715 ## Test input validation
716 %!error mkfifo ()
717 %!error mkfifo ("abc")
718 %!error mkfifo ("abc", 777, 123)
719 %!error <FILE must be a string> mkfifo (123, 456)
720 ## FIXME: These tests should work, but lasterr is not being set correctly.
721 #%!error <MODE must be an integer> mkfifo ("abc", {456})
722 #%!error <MODE must be a positive integer value> mkfifo ("abc", -1)
723 
724 */
725 
726 DEFMETHODX ("pipe", Fpipe, interp, args, ,
727  doc: /* -*- texinfo -*-
728 @deftypefn {} {[@var{read_fd}, @var{write_fd}, @var{err}, @var{msg}] =} pipe ()
729 Create a pipe and return the reading and writing ends of the pipe into
730 @var{read_fd} and @var{write_fd} respectively.
731 
732 If successful, @var{err} is 0 and @var{msg} is an empty string.
733 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent
734 error message.
735 @seealso{mkfifo}
736 @end deftypefn */)
737 {
738  if (args.length () != 0)
739  print_usage ();
740 
741  int fid[2];
742  std::string msg;
743 
744  int status = octave::sys::pipe (fid, msg);
745 
746  if (status < 0)
747  return ovl (-1, -1, -1, msg);
748  else
749  {
750  FILE *ifile = fdopen (fid[0], "r");
751  FILE *ofile = fdopen (fid[1], "w");
752 
753  octave::stream is
754  = octave_stdiostream::create ("pipe-in", ifile, std::ios::in);
755 
756  octave::stream os
757  = octave_stdiostream::create ("pipe-out", ofile, std::ios::out);
758 
759  octave::stream_list& streams = interp.get_stream_list ();
760 
761  return ovl (streams.insert (is), streams.insert (os), status, msg);
762  }
763 }
764 
765 DEFMETHODX ("stat", Fstat, interp, args, ,
766  doc: /* -*- texinfo -*-
767 @deftypefn {} {[@var{info}, @var{err}, @var{msg}] =} stat (@var{file})
768 @deftypefnx {} {[@var{info}, @var{err}, @var{msg}] =} stat (@var{fid})
769 @deftypefnx {} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{file})
770 @deftypefnx {} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{fid})
771 Return a structure @var{info} containing the following information about
772 @var{file} or file identifier @var{fid}.
773 
774 @table @code
775 @item dev
776 ID of device containing a directory entry for this file.
777 
778 @item ino
779 File number of the file.
780 
781 @item mode
782 File mode, as an integer. Use the functions @w{@code{S_ISREG}},
783 @w{@code{S_ISDIR}}, @w{@code{S_ISCHR}}, @w{@code{S_ISBLK}},
784 @w{@code{S_ISFIFO}}, @w{@code{S_ISLNK}}, or @w{@code{S_ISSOCK}} to extract
785 information from this value.
786 
787 @item modestr
788 File mode, as a string of ten letters or dashes as would be returned by
789 @kbd{ls -l}.
790 
791 @item nlink
792 Number of links.
793 
794 @item uid
795 User ID of file's owner.
796 
797 @item gid
798 Group ID of file's group.
799 
800 @item rdev
801 ID of device for block or character special files.
802 
803 @item size
804 Size in bytes.
805 
806 @item atime
807 Time of last access in the same form as time values returned from
808 @code{time}. @xref{Timing Utilities}.
809 
810 @item mtime
811 Time of last modification in the same form as time values returned from
812 @code{time}. @xref{Timing Utilities}.
813 
814 @item ctime
815 Time of last file status change in the same form as time values
816 returned from @code{time}. @xref{Timing Utilities}.
817 
818 @item blksize
819 Size of blocks in the file.
820 
821 @item blocks
822 Number of blocks allocated for file.
823 @end table
824 
825 If the call is successful @var{err} is 0 and @var{msg} is an empty string.
826 If the file does not exist, or some other error occurs, @var{info} is an
827 empty matrix, @var{err} is @minus{}1, and @var{msg} contains the
828 corresponding system error message.
829 
830 If @var{file} is a symbolic link, @code{stat} will return information about
831 the actual file that is referenced by the link. Use @code{lstat} if you
832 want information about the symbolic link itself.
833 
834 For example:
835 
836 @example
837 [info, err, msg] = stat ("/vmlinuz")
838  @result{} info =
839  @{
840  atime = 855399756
841  rdev = 0
842  ctime = 847219094
843  uid = 0
844  size = 389218
845  blksize = 4096
846  mtime = 847219094
847  gid = 6
848  nlink = 1
849  blocks = 768
850  mode = -rw-r--r--
851  modestr = -rw-r--r--
852  ino = 9316
853  dev = 2049
854  @}
855  @result{} err = 0
856  @result{} msg =
857 @end example
858 @seealso{lstat, ls, dir, isfile, isfolder}
859 @end deftypefn */)
860 {
861  if (args.length () != 1)
862  print_usage ();
863 
865 
866  if (args(0).is_scalar_type ())
867  {
868  octave::stream_list& streams = interp.get_stream_list ();
869 
870  int fid = streams.get_file_number (args(0));
871 
872  octave::sys::file_fstat fs (fid);
873 
874  retval = mk_stat_result (fs);
875  }
876  else
877  {
878  std::string fname = args(0).xstring_value ("stat: NAME must be a string");
879 
880  octave::sys::file_stat fs (fname);
881 
882  retval = mk_stat_result (fs);
883  }
884 
885  return retval;
886 }
887 
888 DEFUNX ("S_ISREG", FS_ISREG, args, ,
889  doc: /* -*- texinfo -*-
890 @deftypefn {} {} S_ISREG (@var{mode})
891 Return true if @var{mode} corresponds to a regular file.
892 
893 The value of @var{mode} is assumed to be returned from a call to
894 @code{stat}.
895 @seealso{stat, lstat}
896 @end deftypefn */)
897 {
898  if (args.length () != 1)
899  print_usage ();
900 
901  double mode = args(0).xdouble_value ("S_ISREG: invalid MODE value");
902 
903  return ovl (octave::sys::file_stat::is_reg (static_cast<mode_t> (mode)));
904 }
905 
906 DEFUNX ("S_ISDIR", FS_ISDIR, args, ,
907  doc: /* -*- texinfo -*-
908 @deftypefn {} {} S_ISDIR (@var{mode})
909 Return true if @var{mode} corresponds to a directory.
910 
911 The value of @var{mode} is assumed to be returned from a call to
912 @code{stat}.
913 @seealso{stat, lstat}
914 @end deftypefn */)
915 {
916  if (args.length () != 1)
917  print_usage ();
918 
919  double mode = args(0).xdouble_value ("S_ISDIR: invalid MODE value");
920 
921  return ovl (octave::sys::file_stat::is_dir (static_cast<mode_t> (mode)));
922 }
923 
924 DEFUNX ("S_ISCHR", FS_ISCHR, args, ,
925  doc: /* -*- texinfo -*-
926 @deftypefn {} {} S_ISCHR (@var{mode})
927 Return true if @var{mode} corresponds to a character device.
928 
929 The value of @var{mode} is assumed to be returned from a call to
930 @code{stat}.
931 @seealso{stat, lstat}
932 @end deftypefn */)
933 {
934  if (args.length () != 1)
935  print_usage ();
936 
937  double mode = args(0).xdouble_value ("S_ISCHR: invalid MODE value");
938 
939  return ovl (octave::sys::file_stat::is_chr (static_cast<mode_t> (mode)));
940 }
941 
942 DEFUNX ("S_ISBLK", FS_ISBLK, args, ,
943  doc: /* -*- texinfo -*-
944 @deftypefn {} {} S_ISBLK (@var{mode})
945 Return true if @var{mode} corresponds to a block device.
946 
947 The value of @var{mode} is assumed to be returned from a call to
948 @code{stat}.
949 @seealso{stat, lstat}
950 @end deftypefn */)
951 {
952  if (args.length () != 1)
953  print_usage ();
954 
955  double mode = args(0).xdouble_value ("S_ISBLK: invalid MODE value");
956 
957  return ovl (octave::sys::file_stat::is_blk (static_cast<mode_t> (mode)));
958 }
959 
960 DEFUNX ("S_ISFIFO", FS_ISFIFO, args, ,
961  doc: /* -*- texinfo -*-
962 @deftypefn {} {} S_ISFIFO (@var{mode})
963 Return true if @var{mode} corresponds to a fifo.
964 
965 The value of @var{mode} is assumed to be returned from a call to
966 @code{stat}.
967 @seealso{stat, lstat}
968 @end deftypefn */)
969 {
970  if (args.length () != 1)
971  print_usage ();
972 
973  double mode = args(0).xdouble_value ("S_ISFIFO: invalid MODE value");
974 
975  return ovl (octave::sys::file_stat::is_fifo (static_cast<mode_t> (mode)));
976 }
977 
978 DEFUNX ("S_ISLNK", FS_ISLNK, args, ,
979  doc: /* -*- texinfo -*-
980 @deftypefn {} {} S_ISLNK (@var{mode})
981 Return true if @var{mode} corresponds to a symbolic link.
982 
983 The value of @var{mode} is assumed to be returned from a call to
984 @code{stat}.
985 @seealso{stat, lstat}
986 @end deftypefn */)
987 {
988  if (args.length () != 1)
989  print_usage ();
990 
991  double mode = args(0).xdouble_value ("S_ISLNK: invalid MODE value");
992 
993  return ovl (octave::sys::file_stat::is_lnk (static_cast<mode_t> (mode)));
994 }
995 
996 DEFUNX ("S_ISSOCK", FS_ISSOCK, args, ,
997  doc: /* -*- texinfo -*-
998 @deftypefn {} {} S_ISSOCK (@var{mode})
999 Return true if @var{mode} corresponds to a socket.
1000 
1001 The value of @var{mode} is assumed to be returned from a call to
1002 @code{stat}.
1003 @seealso{stat, lstat}
1004 @end deftypefn */)
1005 {
1006  if (args.length () != 1)
1007  print_usage ();
1008 
1009  double mode = args(0).xdouble_value ("S_ISSOCK: invalid MODE value");
1010 
1011  return ovl (octave::sys::file_stat::is_sock (static_cast<mode_t> (mode)));
1012 }
1013 
1014 DEFUN (gethostname, args, ,
1015  doc: /* -*- texinfo -*-
1016 @deftypefn {} {} gethostname ()
1017 Return the hostname of the system where Octave is running.
1018 @end deftypefn */)
1019 {
1020  if (args.length () != 0)
1021  print_usage ();
1022 
1024 }
1025 
1026 DEFUN (uname, args, ,
1027  doc: /* -*- texinfo -*-
1028 @deftypefn {} {[@var{uts}, @var{err}, @var{msg}] =} uname ()
1029 Return system information in the structure.
1030 
1031 For example:
1032 
1033 @example
1034 @group
1035 uname ()
1036  @result{} @{
1037  sysname = x86_64
1038  nodename = segfault
1039  release = 2.6.15-1-amd64-k8-smp
1040  version = Linux
1041  machine = #2 SMP Thu Feb 23 04:57:49 UTC 2006
1042  @}
1043 @end group
1044 @end example
1045 
1046 If successful, @var{err} is 0 and @var{msg} is an empty string.
1047 Otherwise, @var{err} is nonzero and @var{msg} contains a
1048 system-dependent error message.
1049 @end deftypefn */)
1050 {
1051  if (args.length () != 0)
1052  print_usage ();
1053 
1054  octave::sys::uname sysinfo;
1055 
1057 
1058  m.assign ("sysname", sysinfo.sysname ());
1059  m.assign ("nodename", sysinfo.nodename ());
1060  m.assign ("release", sysinfo.release ());
1061  m.assign ("version", sysinfo.version ());
1062  m.assign ("machine", sysinfo.machine ());
1063 
1064  return ovl (m, sysinfo.error (), sysinfo.message ());
1065 }
1066 
1067 /*
1068 %!test <*51869>
1069 %! [info, status, msg] = uname ();
1070 %! if (status == 0)
1071 %! assert (isstruct (info))
1072 %! assert (ischar (msg) && isempty (msg))
1073 %! endif
1074 */
1075 
1076 DEFMETHODX ("unlink", Funlink, interp, args, ,
1077  doc: /* -*- texinfo -*-
1078 @deftypefn {} {[@var{err}, @var{msg}] =} unlink (@var{file})
1079 Delete the file named @var{file}.
1080 
1081 If successful, @var{err} is 0 and @var{msg} is an empty string.
1082 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent
1083 error message.
1084 @seealso{delete, rmdir}
1085 @end deftypefn */)
1086 {
1087  if (args.length () != 1)
1088  print_usage ();
1089 
1090  std::string name = args(0).xstring_value ("unlink: FILE must be a string");
1091 
1092  std::string msg;
1093 
1094  octave::event_manager& evmgr = interp.get_event_manager ();
1095 
1096  evmgr.file_remove (name, "");
1097 
1098  int status = octave::sys::unlink (name, msg);
1099 
1100  evmgr.file_renamed (status == 0);
1101 
1102  return ovl (status, msg);
1103 }
1104 
1105 /*
1106 %!test
1107 %! file = tempname ();
1108 %! fid = fopen (file, "wt");
1109 %! if (fid < 0)
1110 %! error ("Could not open temporary file for unlink BIST test");
1111 %! endif
1112 %! fdisp (fid, pi);
1113 %! fclose (fid);
1114 %! [err, msg] = unlink (file);
1115 %! assert (err, 0);
1116 %! assert (msg, "");
1117 
1118 ## Test input validation
1119 %!error unlink ()
1120 %!error unlink ("a", "b")
1121 %!error <FILE must be a string> unlink (123)
1122 */
1123 
1124 DEFUNX ("waitpid", Fwaitpid, args, ,
1125  doc: /* -*- texinfo -*-
1126 @deftypefn {} {[@var{pid}, @var{status}, @var{msg}] =} waitpid (@var{pid}, @var{options})
1127 Wait for process @var{pid} to terminate.
1128 
1129 The @var{pid} argument can be:
1130 
1131 @table @asis
1132 @item @minus{}1
1133 Wait for any child process.
1134 
1135 @item 0
1136 Wait for any child process whose process group ID is equal to that of the
1137 Octave interpreter process.
1138 
1139 @item > 0
1140 Wait for termination of the child process with ID @var{pid}.
1141 @end table
1142 
1143 The @var{options} argument can be a bitwise OR of zero or more of the
1144 following constants:
1145 
1146 @table @code
1147 @item 0
1148 Wait until signal is received or a child process exits (this is the default
1149 if the @var{options} argument is missing).
1150 
1151 @item WNOHANG
1152 Do not hang if status is not immediately available.
1153 
1154 @item WUNTRACED
1155 Report the status of any child processes that are stopped, and whose status
1156 has not yet been reported since they stopped.
1157 
1158 @item WCONTINUE
1159 Return if a stopped child has been resumed by delivery of @code{SIGCONT}.
1160 This value may not be meaningful on all systems.
1161 @end table
1162 
1163 If the returned value of @var{pid} is greater than 0, it is the process ID
1164 of the child process that exited. If an error occurs, @var{pid} will be
1165 less than zero and @var{msg} will contain a system-dependent error message.
1166 The value of @var{status} contains additional system-dependent information
1167 about the subprocess that exited.
1168 @seealso{WCONTINUE, WCOREDUMP, WEXITSTATUS, WIFCONTINUED, WIFSIGNALED, WIFSTOPPED, WNOHANG, WSTOPSIG, WTERMSIG, WUNTRACED}
1169 @end deftypefn */)
1170 {
1171  int nargin = args.length ();
1172 
1173  if (nargin != 1 && nargin != 2)
1174  print_usage ();
1175 
1176  pid_t pid = args(0).xint_value ("waitpid: OPTIONS must be an integer");
1177 
1178  int options = 0;
1179 
1180  if (nargin == 2)
1181  options = args(1).xint_value ("waitpid: PID must be an integer value");
1182 
1183  std::string msg;
1184  int status;
1185 
1186  pid_t result = octave::sys::waitpid (pid, &status, options, msg);
1187 
1188  return ovl (result, status, msg);
1189 }
1190 
1191 DEFUNX ("WIFEXITED", FWIFEXITED, args, ,
1192  doc: /* -*- texinfo -*-
1193 @deftypefn {} {} WIFEXITED (@var{status})
1194 Given @var{status} from a call to @code{waitpid}, return
1195 true if the child terminated normally.
1196 @seealso{waitpid, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}
1197 @end deftypefn */)
1198 {
1199  if (args.length () != 1)
1200  print_usage ();
1201 
1202  int status = args(0).xint_value ("WIFEXITED: STATUS must be an integer");
1203 
1204  return ovl (octave::sys::wifexited (status));
1205 }
1206 
1207 DEFUNX ("WEXITSTATUS", FWEXITSTATUS, args, ,
1208  doc: /* -*- texinfo -*-
1209 @deftypefn {} {} WEXITSTATUS (@var{status})
1210 Given @var{status} from a call to @code{waitpid}, return
1211 the exit status of the child.
1212 
1213 This function should only be employed if @code{WIFEXITED} returned true.
1214 @seealso{waitpid, WIFEXITED, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}
1215 @end deftypefn */)
1216 {
1217  if (args.length () != 1)
1218  print_usage ();
1219 
1220  int status = args(0).xint_value ("WEXITSTATUS: STATUS must be an integer");
1221 
1222  return ovl (octave::sys::wexitstatus (status));
1223 }
1224 
1225 DEFUNX ("WIFSIGNALED", FWIFSIGNALED, args, ,
1226  doc: /* -*- texinfo -*-
1227 @deftypefn {} {} WIFSIGNALED (@var{status})
1228 Given @var{status} from a call to @code{waitpid}, return
1229 true if the child process was terminated by a signal.
1230 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}
1231 @end deftypefn */)
1232 {
1233  if (args.length () != 1)
1234  print_usage ();
1235 
1236  int status = args(0).xint_value ("WIFSIGNALED: STATUS must be an integer");
1237 
1238  return ovl (octave::sys::wifsignaled (status));
1239 }
1240 
1241 DEFUNX ("WTERMSIG", FWTERMSIG, args, ,
1242  doc: /* -*- texinfo -*-
1243 @deftypefn {} {} WTERMSIG (@var{status})
1244 Given @var{status} from a call to @code{waitpid}, return
1245 the number of the signal that caused the child process to terminate.
1246 
1247 This function should only be employed if @code{WIFSIGNALED} returned true.
1248 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}
1249 @end deftypefn */)
1250 {
1251  if (args.length () != 1)
1252  print_usage ();
1253 
1254  int status = args(0).xint_value ("WTERMSIG: STATUS must be an integer");
1255 
1256  return ovl (octave::sys::wtermsig (status));
1257 }
1258 
1259 DEFUNX ("WCOREDUMP", FWCOREDUMP, args, ,
1260  doc: /* -*- texinfo -*-
1261 @deftypefn {} {} WCOREDUMP (@var{status})
1262 Given @var{status} from a call to @code{waitpid}, return
1263 true if the child produced a core dump.
1264 
1265 This function should only be employed if @code{WIFSIGNALED} returned true.
1266 The macro used to implement this function is not specified in POSIX.1-2001
1267 and is not available on some Unix implementations (e.g., @nospell{AIX, SunOS}).
1268 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}
1269 @end deftypefn */)
1270 {
1271  if (args.length () != 1)
1272  print_usage ();
1273 
1274  int status = args(0).xint_value ("WCOREDUMP: STATUS must be an integer");
1275 
1276  return ovl (octave::sys::wcoredump (status));
1277 }
1278 
1279 DEFUNX ("WIFSTOPPED", FWIFSTOPPED, args, ,
1280  doc: /* -*- texinfo -*-
1281 @deftypefn {} {} WIFSTOPPED (@var{status})
1282 Given @var{status} from a call to @code{waitpid}, return
1283 true if the child process was stopped by delivery of a signal.
1284 
1285 This is only possible if the call was done using @code{WUNTRACED} or when
1286 the child is being traced (see ptrace(2)).
1287 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WSTOPSIG, WIFCONTINUED}
1288 @end deftypefn */)
1289 {
1290  if (args.length () != 1)
1291  print_usage ();
1292 
1293  int status = args(0).xint_value ("WIFSTOPPED: STATUS must be an integer");
1294 
1295  return ovl (octave::sys::wifstopped (status));
1296 }
1297 
1298 DEFUNX ("WSTOPSIG", FWSTOPSIG, args, ,
1299  doc: /* -*- texinfo -*-
1300 @deftypefn {} {} WSTOPSIG (@var{status})
1301 Given @var{status} from a call to @code{waitpid}, return
1302 the number of the signal which caused the child to stop.
1303 
1304 This function should only be employed if @code{WIFSTOPPED} returned true.
1305 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WIFCONTINUED}
1306 @end deftypefn */)
1307 {
1308  if (args.length () != 1)
1309  print_usage ();
1310 
1311  int status = args(0).xint_value ("WSTOPSIG: STATUS must be an integer");
1312 
1313  return ovl (octave::sys::wstopsig (status));
1314 }
1315 
1316 DEFUNX ("WIFCONTINUED", FWIFCONTINUED, args, ,
1317  doc: /* -*- texinfo -*-
1318 @deftypefn {} {} WIFCONTINUED (@var{status})
1319 Given @var{status} from a call to @code{waitpid}, return
1320 true if the child process was resumed by delivery of @code{SIGCONT}.
1321 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG}
1322 @end deftypefn */)
1323 {
1324  if (args.length () != 1)
1325  print_usage ();
1326 
1327  int status = args(0).xint_value ("WIFCONTINUED: STATUS must be an integer");
1328 
1329  return ovl (octave::sys::wifcontinued (status));
1330 }
1331 
1332 DEFUNX ("canonicalize_file_name", Fcanonicalize_file_name, args, ,
1333  doc: /* -*- texinfo -*-
1334 @deftypefn {} {[@var{cname}, @var{status}, @var{msg}] =} canonicalize_file_name (@var{fname})
1335 Return the canonical name of file @var{fname}.
1336 
1337 If the file does not exist the empty string ("") is returned. No tilde
1338 expansion of @var{fname} is performed.
1339 @seealso{make_absolute_filename, is_absolute_filename, is_rooted_relative_filename, is_same_file, tilde_expand}
1340 @end deftypefn */)
1341 {
1342  if (args.length () != 1)
1343  print_usage ();
1344 
1345  std::string name = args(0).xstring_value ("canonicalize_file_name: NAME must be a string");
1346 
1347  std::string msg;
1348 
1349  std::string result = octave::sys::canonicalize_file_name (name, msg);
1350 
1351  return ovl (result, msg.empty () ? 0 : -1, msg);
1352 }
1353 
1354 static inline octave_value
1355 const_value (const octave_value_list& args, int val)
1356 {
1357  if (args.length () != 0)
1358  print_usage ();
1359 
1360  return octave_value (val);
1361 }
1362 
1363 DEFUNX ("F_DUPFD", FF_DUPFD, args, ,
1364  doc: /* -*- texinfo -*-
1365 @deftypefn {} {} F_DUPFD ()
1366 Return the numerical value to pass to @code{fcntl} to return
1367 a duplicate file descriptor.
1368 @seealso{fcntl, F_GETFD, F_GETFL, F_SETFD, F_SETFL}
1369 @end deftypefn */)
1370 {
1371  static int val = octave_f_dupfd_wrapper ();
1372 
1373  if (val < 0)
1374  err_disabled_feature ("F_DUPFD", "F_DUPFD");
1375 
1376  return const_value (args, val);
1377 }
1378 
1379 DEFUNX ("F_GETFD", FF_GETFD, args, ,
1380  doc: /* -*- texinfo -*-
1381 @deftypefn {} {} F_GETFD ()
1382 Return the numerical value to pass to @code{fcntl} to return
1383 the file descriptor flags.
1384 @seealso{fcntl, F_DUPFD, F_GETFL, F_SETFD, F_SETFL}
1385 @end deftypefn */)
1386 {
1387  static int val = octave_f_getfd_wrapper ();
1388 
1389  if (val < 0)
1390  err_disabled_feature ("F_GETFD", "F_GETFD");
1391 
1392  return const_value (args, val);
1393 }
1394 
1395 DEFUNX ("F_GETFL", FF_GETFL, args, ,
1396  doc: /* -*- texinfo -*-
1397 @deftypefn {} {} F_GETFL ()
1398 Return the numerical value to pass to @code{fcntl} to return
1399 the file status flags.
1400 @seealso{fcntl, F_DUPFD, F_GETFD, F_SETFD, F_SETFL}
1401 @end deftypefn */)
1402 {
1403  static int val = octave_f_getfl_wrapper ();
1404 
1405  if (val < 0)
1406  err_disabled_feature ("F_GETFL", "F_GETFL");
1407 
1408  return const_value (args, val);
1409 }
1410 
1411 DEFUNX ("F_SETFD", FF_SETFD, args, ,
1412  doc: /* -*- texinfo -*-
1413 @deftypefn {} {} F_SETFD ()
1414 Return the numerical value to pass to @code{fcntl} to set the file
1415 descriptor flags.
1416 @seealso{fcntl, F_DUPFD, F_GETFD, F_GETFL, F_SETFL}
1417 @end deftypefn */)
1418 {
1419  static int val = octave_f_setfd_wrapper ();
1420 
1421  if (val < 0)
1422  err_disabled_feature ("F_SETFD", "F_SETFD");
1423 
1424  return const_value (args, val);
1425 }
1426 
1427 DEFUNX ("F_SETFL", FF_SETFL, args, ,
1428  doc: /* -*- texinfo -*-
1429 @deftypefn {} {} F_SETFL ()
1430 Return the numerical value to pass to @code{fcntl} to set the file
1431 status flags.
1432 @seealso{fcntl, F_DUPFD, F_GETFD, F_GETFL, F_SETFD}
1433 @end deftypefn */)
1434 {
1435  static int val = octave_f_setfl_wrapper ();
1436 
1437  if (val < 0)
1438  err_disabled_feature ("F_SETFL", "F_SETFL");
1439 
1440  return const_value (args, val);
1441 }
1442 
1443 DEFUNX ("O_APPEND", FO_APPEND, args, ,
1444  doc: /* -*- texinfo -*-
1445 @deftypefn {} {} O_APPEND ()
1446 Return the numerical value of the @code{O_APPEND} macro.
1447 
1448 @code{O_APPEND} is file status flag that may be returned by @code{fcntl}
1449 to indicate each write operation appends, or that may be passed to
1450 @code{fcntl} to set the write mode to append.
1451 @seealso{fcntl, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}
1452 @end deftypefn */)
1453 {
1454  static int val = octave_o_append_wrapper ();
1455 
1456  if (val < 0)
1457  err_disabled_feature ("O_APPEND", "O_APPEND");
1458 
1459  return const_value (args, val);
1460 }
1461 
1462 DEFUNX ("O_ASYNC", FO_ASYNC, args, ,
1463  doc: /* -*- texinfo -*-
1464 @deftypefn {} {} O_ASYNC ()
1465 Return the numerical value of the @code{O_ASYNC} macro.
1466 
1467 @code{O_ASYNC} is the file status flag that may be returned by
1468 @code{fcntl} to indicate asynchronous I/O.
1469 @seealso{fcntl, O_APPEND, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}
1470 @end deftypefn */)
1471 {
1472  static int val = octave_o_async_wrapper ();
1473 
1474  if (val < 0)
1475  err_disabled_feature ("O_ASYNC", "O_ASYNC");
1476 
1477  return const_value (args, val);
1478 }
1479 
1480 DEFUNX ("O_CREAT", FO_CREAT, args, ,
1481  doc: /* -*- texinfo -*-
1482 @deftypefn {} {} O_CREAT ()
1483 Return the numerical value of the @code{O_CREAT}.
1484 
1485 @code{O_CREAT} is the file status flag that may be returned by
1486 @code{fcntl} to indicate that a file should be created if it does not
1487 exist.
1488 @seealso{fcntl, O_APPEND, O_ASYNC, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}
1489 @end deftypefn */)
1490 {
1491  static int val = octave_o_creat_wrapper ();
1492 
1493  if (val < 0)
1494  err_disabled_feature ("O_CREAT", "O_CREAT");
1495 
1496  return const_value (args, val);
1497 }
1498 
1499 DEFUNX ("O_EXCL", FO_EXCL, args, ,
1500  doc: /* -*- texinfo -*-
1501 @deftypefn {} {} O_EXCL ()
1502 Return the numerical value of the @code{O_EXCL}.
1503 
1504 @code{O_EXCL} is the file status flag that may be returned by
1505 @code{fcntl} to indicate that file locking is used.
1506 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}
1507 @end deftypefn */)
1508 {
1509  static int val = octave_o_excl_wrapper ();
1510 
1511  if (val < 0)
1512  err_disabled_feature ("O_EXCL", "O_EXCL");
1513 
1514  return const_value (args, val);
1515 }
1516 
1517 DEFUNX ("O_NONBLOCK", FO_NONBLOCK, args, ,
1518  doc: /* -*- texinfo -*-
1519 @deftypefn {} {} O_NONBLOCK ()
1520 Return the numerical value of the @code{O_NONBLOCK}.
1521 
1522 @code{O_NONBLOCK} is the file status flag that may be returned by
1523 @code{fcntl} to indicate that non-blocking I/O is in use, or that may be
1524 passsed to @code{fcntl} to set non-blocking I/O.
1525 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}
1526 @end deftypefn */)
1527 {
1528  static int val = octave_o_nonblock_wrapper ();
1529 
1530  if (val < 0)
1531  err_disabled_feature ("O_NONBLOCK", "O_NONBLOCK");
1532 
1533  return const_value (args, val);
1534 }
1535 
1536 DEFUNX ("O_RDONLY", FO_RDONLY, args, ,
1537  doc: /* -*- texinfo -*-
1538 @deftypefn {} {} O_RDONLY ()
1539 Return the numerical value of the @code{O_RDONLY}.
1540 
1541 @code{O_RDONLY} is the file status flag that may be returned by
1542 @code{fcntl} to indicate that a file is open for reading only.
1543 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}
1544 @end deftypefn */)
1545 {
1546  static int val = octave_o_rdonly_wrapper ();
1547 
1548  if (val < 0)
1549  err_disabled_feature ("O_RDONLY", "O_RDONLY");
1550 
1551  return const_value (args, val);
1552 }
1553 
1554 DEFUNX ("O_RDWR", FO_RDWR, args, ,
1555  doc: /* -*- texinfo -*-
1556 @deftypefn {} {} O_RDWR ()
1557 Return the numerical value of the @code{O_RDWR}.
1558 
1559 @code{O_RDWR} is the file status flag that may be returned by
1560 @code{fcntl} to indicate that a file is open for both reading and
1561 writing.
1562 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_SYNC, O_TRUNC, O_WRONLY}
1563 @end deftypefn */)
1564 {
1565  static int val = octave_o_rdwr_wrapper ();
1566 
1567  if (val < 0)
1568  err_disabled_feature ("O_RDWR", "O_RDWR");
1569 
1570  return const_value (args, val);
1571 }
1572 
1573 DEFUNX ("O_SYNC", FO_SYNC, args, ,
1574  doc: /* -*- texinfo -*-
1575 @deftypefn {} {} O_SYNC ()
1576 Return the numerical value of the @code{O_SYNC}.
1577 
1578 @code{O_SYNC} is the file status flag that may be returned by
1579 @code{fcntl} to indicate that a file is open for synchronous I/O
1580 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY}
1581 @end deftypefn */)
1582 {
1583  static int val = octave_o_sync_wrapper ();
1584 
1585  if (val < 0)
1586  err_disabled_feature ("O_SYNC", "O_SYNC");
1587 
1588  return const_value (args, val);
1589 }
1590 
1591 DEFUNX ("O_TRUNC", FO_TRUNC, args, ,
1592  doc: /* -*- texinfo -*-
1593 @deftypefn {} {} O_TRUNC ()
1594 Return the numerical value of the @code{O_TRUNC}.
1595 
1596 @code{O_TRUNC} is the file status flag that may be returned by
1597 @code{fcntl} to indicate that if file exists, it should be truncated
1598 when writing.
1599 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_WRONLY}
1600 @end deftypefn */)
1601 {
1602  static int val = octave_o_trunc_wrapper ();
1603 
1604  if (val < 0)
1605  err_disabled_feature ("O_TRUNC", "O_TRUNC");
1606 
1607  return const_value (args, val);
1608 }
1609 
1610 DEFUNX ("O_WRONLY", FO_WRONLY, args, ,
1611  doc: /* -*- texinfo -*-
1612 @deftypefn {} {} O_WRONLY ()
1613 Return the numerical value of the @code{O_WRONLY}.
1614 
1615 @code{O_WRONLY} is the file status flag that may be returned by
1616 @code{fcntl} to indicate that a file is open for writing only
1617 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC}
1618 @end deftypefn */)
1619 {
1620  static int val = octave_o_wronly_wrapper ();
1621 
1622  if (val < 0)
1623  err_disabled_feature ("O_WRONLY", "O_WRONLY");
1624 
1625  return const_value (args, val);
1626 }
1627 
1628 DEFUNX ("WNOHANG", FWNOHANG, args, ,
1629  doc: /* -*- texinfo -*-
1630 @deftypefn {} {} WNOHANG ()
1631 Return the numerical value of the @code{WNOHANG} macro.
1632 
1633 @code{WNOHANG} is the option argument that may be passed to
1634 @code{waitpid} to indicate that it should return its status immediately
1635 instead of waiting for a process to exit.
1636 @seealso{waitpid, WUNTRACED, WCONTINUE}
1637 @end deftypefn */)
1638 {
1639  return const_value (args, octave::sys::wnohang ());
1640 }
1641 
1642 DEFUNX ("WUNTRACED", FWUNTRACED, args, ,
1643  doc: /* -*- texinfo -*-
1644 @deftypefn {} {} WUNTRACED ()
1645 Return the numerical value of the @code{WUNTRACED} macro.
1646 
1647 @code{WUNTRACED} is the option argument that may be passed to
1648 @code{waitpid} to indicate that it should also return if the child
1649 process has stopped but is not traced via the @code{ptrace} system call
1650 @seealso{waitpid, WNOHANG, WCONTINUE}
1651 @end deftypefn */)
1652 {
1653  return const_value (args, octave::sys::wuntraced ());
1654 }
1655 
1656 DEFUNX ("WCONTINUE", FWCONTINUE, args, ,
1657  doc: /* -*- texinfo -*-
1658 @deftypefn {} {} WCONTINUE ()
1659 Return the numerical value of the @code{WCONTINUE} macro.
1660 
1661 @code{WCONTINUE} is the option argument that may be passed to
1662 @code{waitpid} to indicate that it should also return if a stopped child
1663 has been resumed by delivery of a @code{SIGCONT} signal.
1664 @seealso{waitpid, WNOHANG, WUNTRACED}
1665 @end deftypefn */)
1666 {
1667  return const_value (args, octave::sys::wcontinue ());
1668 }
#define NaN
Definition: Faddeeva.cc:248
Definition: dMatrix.h:42
static bool ignoring_entries(void)
Definition: cmd-hist.cc:599
static void clean_up_and_save(const std::string &="", int=-1)
Definition: cmd-hist.cc:757
Provides threadsafe access to octave.
void file_renamed(bool load_new)
void file_remove(const std::string &old_name, const std::string &new_name)
void write_timestamp(void)
Definition: oct-hist.cc:286
int get_file_number(const octave_value &fid) const
Definition: oct-stream.cc:7640
int insert(stream &os)
Definition: oct-stream.cc:7387
stream lookup(int fid, const std::string &who="") const
Definition: oct-stream.cc:7427
int file_number(void)
Definition: oct-stream.h:359
sys::time mtime(void) const
Definition: file-stat.h:131
bool is_lnk(void) const
Definition: file-stat.cc:77
dev_t dev(void) const
Definition: file-stat.h:121
bool is_sock(void) const
Definition: file-stat.cc:89
nlink_t nlink(void) const
Definition: file-stat.h:123
dev_t rdev(void) const
Definition: file-stat.h:134
bool is_blk(void) const
Definition: file-stat.cc:53
bool is_fifo(void) const
Definition: file-stat.cc:71
mode_t mode(void) const
Definition: file-stat.h:139
std::string mode_as_string(void) const
Definition: file-stat.cc:155
off_t size(void) const
Definition: file-stat.h:128
std::string error(void) const
Definition: file-stat.h:149
sys::time atime(void) const
Definition: file-stat.h:130
static bool have_struct_stat_st_rdev(void)
Definition: file-stat.cc:137
bool is_reg(void) const
Definition: file-stat.cc:83
bool is_dir(void) const
Definition: file-stat.cc:65
ino_t ino(void) const
Definition: file-stat.h:120
long blksize(void) const
Definition: file-stat.h:136
uid_t uid(void) const
Definition: file-stat.h:125
static bool have_struct_stat_st_blocks(void)
Definition: file-stat.cc:149
static bool have_struct_stat_st_blksize(void)
Definition: file-stat.cc:143
gid_t gid(void) const
Definition: file-stat.h:126
long blocks(void) const
Definition: file-stat.h:137
sys::time ctime(void) const
Definition: file-stat.h:132
bool is_chr(void) const
Definition: file-stat.cc:59
static std::string get_host_name(void)
Definition: oct-env.cc:196
std::string machine(void) const
Definition: oct-uname.h:79
std::string release(void) const
Definition: oct-uname.h:77
std::string nodename(void) const
Definition: oct-uname.h:76
std::string version(void) const
Definition: oct-uname.h:78
std::string message(void) const
Definition: oct-uname.h:81
int error(void) const
Definition: oct-uname.h:82
std::string sysname(void) const
Definition: oct-uname.h:75
static octave::stream create(const std::string &n, FILE *f=nullptr, std::ios::openmode m=std::ios::in|std::ios::out, octave::mach_info::float_format ff=octave::mach_info::native_float_format(), const std::string &encoding="utf-8", c_file_ptr_buf::close_fcn cf=c_file_ptr_buf::file_close)
Definition: oct-stdstrm.h:139
octave_idx_type length(void) const
Definition: ovl.h:113
void resize(octave_idx_type n, const std::string &rfv="")
Definition: str-vec.h:95
octave_idx_type numel(void) const
Definition: str-vec.h:100
OCTINTERP_API void print_usage(void)
Definition: defun.cc:53
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:56
#define DEFUNX(name, fname, args_name, nargout_name, doc)
Macro to define a builtin function with certain internal name.
Definition: defun.h:85
void error(const char *fmt,...)
Definition: error.cc:968
void err_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
Definition: errwarn.cc:53
int octave_o_trunc_wrapper(void)
int octave_f_dupfd_wrapper(void)
int octave_o_wronly_wrapper(void)
int octave_o_creat_wrapper(void)
int octave_o_append_wrapper(void)
int octave_o_sync_wrapper(void)
int octave_o_nonblock_wrapper(void)
int octave_o_excl_wrapper(void)
int octave_f_getfd_wrapper(void)
int octave_o_rdonly_wrapper(void)
int octave_f_setfd_wrapper(void)
int octave_o_rdwr_wrapper(void)
int octave_f_setfl_wrapper(void)
int octave_o_async_wrapper(void)
int octave_f_getfl_wrapper(void)
QString name
F77_RET_T const F77_DBLE * x
T octave_idx_type m
Definition: mx-inlines.cc:773
pid_t getppid(void)
int wexitstatus(int status)
std::string canonicalize_file_name(const std::string &name)
Definition: file-ops.cc:693
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:75
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:53
int unlink(const std::string &name)
Definition: file-ops.cc:626
int wnohang(void)
bool wifexited(int status)
int mkfifo(const std::string &nm, mode_t md)
Definition: file-ops.cc:422
uid_t geteuid(void)
int wcoredump(int status)
pid_t fork(std::string &msg)
int wuntraced(void)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:211
DEFMETHODX("quad", Fquad, interp, args,, doc:)
Definition: quad.cc:130
static octave_scalar_map mk_stat_map(const octave::sys::base_file_stat &fs)
Definition: syscalls.cc:64
OCTAVE_EXPORT octave_value_list Flstat(const octave_value_list &args, int)
Definition: syscalls.cc:639
OCTAVE_EXPORT octave_value_list Fgetpgrp(const octave_value_list &args, int)
Definition: syscalls.cc:504
OCTAVE_EXPORT octave_value_list Fgetgid(const octave_value_list &args, int)
Definition: syscalls.cc:560
OCTAVE_EXPORT octave_value_list Ffork(octave::interpreter &interp, const octave_value_list &args, int)
Definition: syscalls.cc:485
OCTAVE_EXPORT octave_value_list FO_WRONLY(const octave_value_list &args, int)
Definition: syscalls.cc:1618
OCTAVE_EXPORT octave_value_list Fgetuid(const octave_value_list &args, int)
Definition: syscalls.cc:586
OCTAVE_EXPORT octave_value_list Fgetegid(const octave_value_list &args, int)
Definition: syscalls.cc:547
OCTAVE_EXPORT octave_value_list FS_ISLNK(const octave_value_list &args, int)
Definition: syscalls.cc:986
OCTAVE_EXPORT octave_value_list Fgetppid(const octave_value_list &args, int)
Definition: syscalls.cc:534
OCTAVE_EXPORT octave_value_list Fpopen2(octave::interpreter &interp, const octave_value_list &args, int)
Definition: syscalls.cc:256
OCTAVE_EXPORT octave_value_list FF_DUPFD(const octave_value_list &args, int)
Definition: syscalls.cc:1369
OCTAVE_EXPORT octave_value_list FF_SETFD(const octave_value_list &args, int)
Definition: syscalls.cc:1417
OCTAVE_EXPORT octave_value_list Fmkfifo(const octave_value_list &args, int)
Definition: syscalls.cc:692
OCTAVE_EXPORT octave_value_list FO_RDWR(const octave_value_list &args, int)
Definition: syscalls.cc:1563
OCTAVE_EXPORT octave_value_list FS_ISSOCK(const octave_value_list &args, int)
Definition: syscalls.cc:1004
OCTAVE_EXPORT octave_value_list Fpipe(octave::interpreter &interp, const octave_value_list &args, int)
Definition: syscalls.cc:736
OCTAVE_EXPORT octave_value_list FS_ISCHR(const octave_value_list &args, int)
Definition: syscalls.cc:932
OCTAVE_EXPORT octave_value_list FWUNTRACED(const octave_value_list &args, int)
Definition: syscalls.cc:1651
OCTAVE_EXPORT octave_value_list FWIFEXITED(const octave_value_list &args, int)
Definition: syscalls.cc:1197
OCTAVE_EXPORT octave_value_list FWTERMSIG(const octave_value_list &args, int)
Definition: syscalls.cc:1249
OCTAVE_EXPORT octave_value_list FO_TRUNC(const octave_value_list &args, int)
Definition: syscalls.cc:1600
OCTAVE_EXPORT octave_value_list FO_CREAT(const octave_value_list &args, int)
Definition: syscalls.cc:1489
OCTAVE_EXPORT octave_value_list FWEXITSTATUS(const octave_value_list &args, int)
Definition: syscalls.cc:1215
OCTAVE_EXPORT octave_value_list Funlink(octave::interpreter &interp, const octave_value_list &args, int)
Definition: syscalls.cc:1085
OCTAVE_EXPORT octave_value_list Fdup2(octave::interpreter &interp, const octave_value_list &args, int)
Definition: syscalls.cc:121
static octave_value const_value(const octave_value_list &args, int val)
Definition: syscalls.cc:1355
OCTAVE_EXPORT octave_value_list FO_ASYNC(const octave_value_list &args, int)
Definition: syscalls.cc:1470
OCTAVE_EXPORT octave_value_list Fgeteuid(const octave_value_list &args, int)
Definition: syscalls.cc:573
OCTAVE_EXPORT octave_value_list FO_APPEND(const octave_value_list &args, int)
Definition: syscalls.cc:1452
OCTAVE_EXPORT octave_value_list FWIFSTOPPED(const octave_value_list &args, int)
Definition: syscalls.cc:1288
OCTAVE_EXPORT octave_value_list FO_SYNC(const octave_value_list &args, int)
Definition: syscalls.cc:1581
OCTAVE_EXPORT octave_value_list FS_ISFIFO(const octave_value_list &args, int)
Definition: syscalls.cc:968
OCTAVE_EXPORT octave_value_list FS_ISREG(const octave_value_list &args, int)
Definition: syscalls.cc:896
OCTAVE_EXPORT octave_value_list Fexec(octave::interpreter &interp, const octave_value_list &args, int)
Definition: syscalls.cc:166
OCTAVE_EXPORT octave_value_list FWIFCONTINUED(const octave_value_list &args, int)
Definition: syscalls.cc:1322
OCTAVE_EXPORT octave_value_list FF_GETFD(const octave_value_list &args, int)
Definition: syscalls.cc:1385
OCTAVE_EXPORT octave_value_list Fcanonicalize_file_name(const octave_value_list &args, int)
Definition: syscalls.cc:1340
OCTAVE_EXPORT octave_value_list Fwaitpid(const octave_value_list &args, int)
Definition: syscalls.cc:1169
OCTAVE_EXPORT octave_value_list FO_NONBLOCK(const octave_value_list &args, int)
Definition: syscalls.cc:1526
OCTAVE_EXPORT octave_value_list FWCONTINUE(const octave_value_list &args, int)
Definition: syscalls.cc:1665
OCTAVE_EXPORT octave_value_list Ffcntl(octave::interpreter &interp, const octave_value_list &args, int)
Definition: syscalls.cc:437
static int convert(int x, int ibase, int obase)
Definition: syscalls.cc:654
OCTAVE_EXPORT octave_value_list Fkill(const octave_value_list &args, int)
Definition: syscalls.cc:614
OCTAVE_EXPORT octave_value_list FS_ISBLK(const octave_value_list &args, int)
Definition: syscalls.cc:950
OCTAVE_EXPORT octave_value_list FO_RDONLY(const octave_value_list &args, int)
Definition: syscalls.cc:1544
static octave_value_list mk_stat_result(const octave::sys::base_file_stat &fs)
Definition: syscalls.cc:104
OCTAVE_EXPORT octave_value_list FO_EXCL(const octave_value_list &args, int)
Definition: syscalls.cc:1507
OCTAVE_EXPORT octave_value_list FF_GETFL(const octave_value_list &args, int)
Definition: syscalls.cc:1401
OCTAVE_EXPORT octave_value_list FWIFSIGNALED(const octave_value_list &args, int)
Definition: syscalls.cc:1231
OCTAVE_EXPORT octave_value_list FF_SETFL(const octave_value_list &args, int)
Definition: syscalls.cc:1433
OCTAVE_EXPORT octave_value_list FWCOREDUMP(const octave_value_list &args, int)
Definition: syscalls.cc:1269
OCTAVE_EXPORT octave_value_list FS_ISDIR(const octave_value_list &args, int)
Definition: syscalls.cc:914
OCTAVE_EXPORT octave_value_list FWNOHANG(const octave_value_list &args, int)
Definition: syscalls.cc:1637
OCTAVE_EXPORT octave_value_list FWSTOPSIG(const octave_value_list &args, int)
Definition: syscalls.cc:1306
OCTAVE_EXPORT octave_value_list Fgetpid(const octave_value_list &args, int)
Definition: syscalls.cc:521
OCTAVE_EXPORT octave_value_list Fstat(octave::interpreter &interp, const octave_value_list &args, int)
Definition: syscalls.cc:859
F77_RET_T len
Definition: xerbla.cc:61