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