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