3Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005,
4 2006, 2007, 2008, 2009 John W. Eaton
6This file is part of Octave.
8Octave is free software; you can redistribute it and/or modify it
9under the terms of the GNU General Public License as published by the
10Free Software Foundation; either version 3 of the License, or (at your
11option) any later version.
13Octave is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18You should have received a copy of the GNU General Public License
19along with Octave; see the file COPYING. If not, see
20<http://www.gnu.org/licenses/>.
24// Thomas Baier <baier@ci.tuwien.ac.at> added the original versions of
25// the following functions:
27// mkfifo unlink waitpid
43#include "oct-syscalls.h"
52#include "oct-stdstrm.h"
53#include "oct-stream.h"
60mk_stat_map (const base_file_stat& fs)
64 m.assign ("dev", static_cast<double> (fs.dev ()));
65 m.assign ("ino", fs.ino ());
66 m.assign ("mode", fs.mode ());
67 m.assign ("modestr", fs.mode_as_string ());
68 m.assign ("nlink", fs.nlink ());
69 m.assign ("uid", fs.uid ());
70 m.assign ("gid", fs.gid ());
71#if defined (HAVE_STRUCT_STAT_ST_RDEV)
72 m.assign ("rdev", static_cast<double> (fs.rdev ()));
74 m.assign ("size", fs.size ());
75 m.assign ("atime", fs.atime ());
76 m.assign ("mtime", fs.mtime ());
77 m.assign ("ctime", fs.ctime ());
78#if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
79 m.assign ("blksize", fs.blksize ());
81#if defined (HAVE_STRUCT_STAT_ST_BLOCKS)
82 m.assign ("blocks", fs.blocks ());
90@deftypefn {Built-in Function} {[@var{fid}, @var{msg}] =} dup2 (@var{old}, @var{new})\n\
91Duplicate a file descriptor.\n\
93If successful, @var{fid} is greater than zero and contains the new file\n\
94ID. Otherwise, @var{fid} is negative and @var{msg} contains a\n\
95system-dependent error message.\n\
98 octave_value_list retval;
100 retval(1) = std::string ();
103 int nargin = args.length ();
107 octave_stream old_stream
108 = octave_stream_list::lookup (args(0), "dup2");
112 octave_stream new_stream
113 = octave_stream_list::lookup (args(1), "dup2");
117 int i_old = old_stream.file_number ();
118 int i_new = new_stream.file_number ();
120 if (i_old >= 0 && i_new >= 0)
124 int status = octave_syscalls::dup2 (i_old, i_new, msg);
132 error ("dup2: invalid stream");
142@deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} exec (@var{file}, @var{args})\n\
143Replace current process with a new process. Calling @code{exec} without\n\
144first calling @code{fork} will terminate your current Octave process and\n\
145replace it with the program named by @var{file}. For example,\n\
148exec (\"ls\" \"-l\")\n\
152will run @code{ls} and return you to your shell prompt.\n\
154If successful, @code{exec} does not return. If @code{exec} does return,\n\
155@var{err} will be nonzero, and @var{msg} will contain a system-dependent\n\
159 octave_value_list retval;
161 retval(1) = std::string ();
164 int nargin = args.length ();
166 if (nargin == 1 || nargin == 2)
168 std::string exec_file = args(0).string_value ();
172 string_vector exec_args;
176 string_vector tmp = args(1).all_strings ();
180 int len = tmp.length ();
182 exec_args.resize (len + 1);
184 exec_args[0] = exec_file;
186 for (int i = 0; i < len; i++)
187 exec_args[i+1] = tmp[i];
190 error ("exec: arguments must be character strings");
194 exec_args.resize (1);
196 exec_args[0] = exec_file;
203 int status = octave_syscalls::execvp (exec_file, exec_args, msg);
210 error ("exec: first argument must be a string");
218DEFUN (popen2, args, ,
220@deftypefn {Built-in Function} {[@var{in}, @var{out}, @var{pid}] =} popen2 (@var{command}, @var{args})\n\
221Start a subprocess with two-way communication. The name of the process\n\
222is given by @var{command}, and @var{args} is an array of strings\n\
223containing options for the command. The file identifiers for the input\n\
224and output streams of the subprocess are returned in @var{in} and\n\
225@var{out}. If execution of the command is successful, @var{pid}\n\
226contains the process ID of the subprocess. Otherwise, @var{pid} is\n\
232[in, out, pid] = popen2 (\"sort\", \"-r\");\n\
233fputs (in, \"these\\nare\\nsome\\nstrings\\n\");\n\
235EAGAIN = errno (\"EAGAIN\");\n\
240 fputs (stdout, s);\n\
241 elseif (errno () == EAGAIN)\n\
256Note that @code{popen2}, unlike @code{popen}, will not \"reap\" the\n\
257child process. If you don't use @code{waitpid} to check the child's\n\
258exit status, it will linger until Octave exits.\n\
261 octave_value_list retval;
264 retval(1) = Matrix ();
265 retval(0) = Matrix ();
267 int nargin = args.length ();
269 if (nargin >= 1 && nargin <= 3)
271 std::string exec_file = args(0).string_value();
275 string_vector arg_list;
279 string_vector tmp = args(1).all_strings ();
283 int len = tmp.length ();
285 arg_list.resize (len + 1);
287 arg_list[0] = exec_file;
289 for (int i = 0; i < len; i++)
290 arg_list[i+1] = tmp[i];
293 error ("popen2: arguments must be character strings");
299 arg_list[0] = exec_file;
304 bool sync_mode = (nargin == 3 ? args(2).bool_value() : false);
312 pid = octave_syscalls::popen2 (exec_file, arg_list, sync_mode, fildes, msg, interactive);
315 FILE *ifile = fdopen (fildes[1], "r");
316 FILE *ofile = fdopen (fildes[0], "w");
320 octave_stream is = octave_stdiostream::create (nm, ifile,
323 octave_stream os = octave_stdiostream::create (nm, ofile,
326 Cell file_ids (1, 2);
328 retval(0) = octave_stream_list::insert (os);
329 retval(1) = octave_stream_list::insert (is);
333 error (msg.c_str ());
337 error ("popen2: arguments must be character strings");
340 error ("popen2: first argument must be a string");
352%! [in, out, pid] = popen2 ("sort", "-r");
353%! EAGAIN = errno ("EAGAIN");
355%! [in, out, pid] = popen2 ("sort", "/R");
356%! EAGAIN = errno ("EINVAL");
358%! fputs (in, "these\nare\nsome\nstrings\n");
372%! elseif (errno () == EAGAIN)
384%! assert(str,{"these\n","strings\n","some\n","are\n"})
386%! assert(str,{"these\r\n","strings\r\n","some\r\n","are\r\n"})
391DEFUNX ("fcntl", Ffcntl, args, ,
393@deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} fcntl (@var{fid}, @var{request}, @var{arg})\n\
394Change the properties of the open file @var{fid}. The following values\n\
395may be passed as @var{request}:\n\
399Return a duplicate file descriptor.\n\
402Return the file descriptor flags for @var{fid}.\n\
405Set the file descriptor flags for @var{fid}.\n\
408Return the file status flags for @var{fid}. The following codes may be\n\
409returned (some of the flags may be undefined on some systems).\n\
413Open for reading only.\n\
416Open for writing only.\n\
419Open for reading and writing.\n\
422Append on each write.\n\
425Create the file if it does not exist.\n\
431Wait for writes to complete.\n\
438Set the file status flags for @var{fid} to the value specified by\n\
439@var{arg}. The only flags that can be changed are @w{@code{O_APPEND}} and\n\
440@w{@code{O_NONBLOCK}}.\n\
443If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
444Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
445system-dependent error message.\n\
448 octave_value_list retval;
450 retval(1) = std::string ();
453 int nargin = args.length ();
457 octave_stream strm = octave_stream_list::lookup (args (0), "fcntl");
461 int fid = strm.file_number ();
463 int req = args(1).int_value (true);
464 int arg = args(2).int_value (true);
468 // FIXME -- Need better checking here?
470 error ("fcntl: invalid file id");
475 int status = octave_fcntl (fid, req, arg, msg);
483 error ("fcntl: file id, request, and argument must be integers");
493@deftypefn {Built-in Function} {[@var{pid}, @var{msg}] =} fork ()\n\
494Create a copy of the current process.\n\
496Fork can return one of the following values:\n\
500You are in the parent process. The value returned from @code{fork} is\n\
501the process id of the child process. You should probably arrange to\n\
502wait for any child processes to exit.\n\
505You are in the child process. You can call @code{exec} to start another\n\
506process. If that fails, you should probably call @code{exit}.\n\
509The call to @code{fork} failed for some reason. You must take evasive\n\
510action. A system dependent error message will be waiting in @var{msg}.\n\
514 octave_value_list retval;
516 retval(1) = std::string ();
519 int nargin = args.length ();
525 pid_t pid = octave_syscalls::fork (msg);
536DEFUN (getpgrp, args, ,
538@deftypefn {Built-in Function} {pgid =} getpgrp ()\n\
539Return the process group id of the current process.\n\
542 octave_value_list retval;
544 retval(1) = std::string ();
547 int nargin = args.length ();
553 retval(0) = octave_syscalls::getpgrp (msg);
562DEFUN (getpid, args, ,
564@deftypefn {Built-in Function} {pid =} getpid ()\n\
565Return the process id of the current process.\n\
568 octave_value retval = -1;
570 int nargin = args.length ();
573 retval = octave_syscalls::getpid ();
580DEFUN (getppid, args, ,
582@deftypefn {Built-in Function} {pid =} getppid ()\n\
583Return the process id of the parent process.\n\
586 octave_value retval = -1;
588 int nargin = args.length ();
591 retval = octave_syscalls::getppid ();
598DEFUN (getegid, args, ,
600@deftypefn {Built-in Function} {egid =} getegid ()\n\
601Return the effective group id of the current process.\n\
604 octave_value retval = -1;
606 int nargin = args.length ();
609 retval = octave_syscalls::getegid ();
616DEFUN (getgid, args, ,
618@deftypefn {Built-in Function} {gid =} getgid ()\n\
619Return the real group id of the current process.\n\
622 octave_value retval = -1;
624 int nargin = args.length ();
627 retval = octave_syscalls::getgid ();
634DEFUN (geteuid, args, ,
636@deftypefn {Built-in Function} {euid =} geteuid ()\n\
637Return the effective user id of the current process.\n\
640 octave_value retval = -1;
642 int nargin = args.length ();
645 retval = octave_syscalls::geteuid ();
652DEFUN (getuid, args, ,
654@deftypefn {Built-in Function} {uid =} getuid ()\n\
655Return the real user id of the current process.\n\
658 octave_value retval = -1;
660 int nargin = args.length ();
663 retval = octave_syscalls::getuid ();
672@deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} kill (@var{pid}, @var{sig})\n\
673Send signal @var{sig} to process @var{pid}.\n\
675If @var{pid} is positive, then signal @var{sig} is sent to @var{pid}.\n\
677If @var{pid} is 0, then signal @var{sig} is sent to every process\n\
678in the process group of the current process.\n\
680If @var{pid} is -1, then signal @var{sig} is sent to every process\n\
683If @var{pid} is less than -1, then signal @var{sig} is sent to every\n\
684process in the process group @var{-pid}.\n\
686If @var{sig} is 0, then no signal is sent, but error checking is still\n\
689Return 0 if successful, otherwise return -1.\n\
692 octave_value_list retval;
694 retval(1) = std::string ();
697 if (args.length () == 2)
699 pid_t pid = args(0).int_value (true);
703 int sig = args(1).int_value (true);
709 int status = octave_syscalls::kill (pid, sig, msg);
724@deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} fstat (@var{fid})\n\
725Return information about the open file @var{fid}. See @code{stat}\n\
726for a description of the contents of @var{info}.\n\
729 octave_value_list retval;
731 if (args.length () == 1)
733 int fid = octave_stream_list::get_file_number (args(0));
741 retval(2) = std::string ();
743 retval(0) = octave_value (mk_stat_map (fs));
747 retval(2) = fs.error ();
749 retval(0) = Matrix ();
761@deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{file})\n\
765 octave_value_list retval;
767 if (args.length () == 1)
769 std::string fname = args(0).string_value ();
773 file_stat fs (fname, false);
777 retval(2) = std::string ();
779 retval(0) = mk_stat_map (fs);
783 retval(2) = fs.error ();
785 retval(0) = Matrix ();
797DEFUNX ("mkfifo", Fmkfifo, args, ,
799@deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} mkfifo (@var{name}, @var{mode})\n\
800Create a @var{fifo} special file named @var{name} with file mode @var{mode}\n\
802If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
803Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
804system-dependent error message.\n\
807 octave_value_list retval;
809 retval(1) = std::string ();
812 int nargin = args.length ();
816 if (args(0).is_string ())
818 std::string name = args(0).string_value ();
820 if (args(1).is_scalar_type ())
822 long mode = args(1).long_value ();
828 int status = octave_mkfifo (name, mode, msg);
836 error ("mkfifo: invalid MODE");
839 error ("mkfifo: MODE must be an integer");
842 error ("mkfifo: file name must be a string");
852@deftypefn {Built-in Function} {[@var{read_fd}, @var{write_fd}, @var{err}, @var{msg}] =} pipe ()\n\
853Create a pipe and return the reading and writing ends of the pipe\n\
854into @var{read_fd} and @var{write_fd} respectively.\n\
856If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
857Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
858system-dependent error message.\n\
861 octave_value_list retval;
863 retval(3) = std::string ();
868 int nargin = args.length ();
876 int status = octave_syscalls::pipe (fid, msg);
882 FILE *ifile = fdopen (fid[0], "r");
883 FILE *ofile = fdopen (fid[1], "w");
887 octave_stream is = octave_stdiostream::create (nm, ifile,
890 octave_stream os = octave_stdiostream::create (nm, ofile,
893 retval(1) = octave_stream_list::insert (os);
894 retval(0) = octave_stream_list::insert (is);
907@deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} stat (@var{file})\n\
908@deftypefnx {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{file})\n\
909Return a structure @var{s} containing the following information about\n\
914ID of device containing a directory entry for this file.\n\
917File number of the file.\n\
920File mode, as an integer. Use the functions @w{@code{S_ISREG}},\n\
921@w{@code{S_ISDIR}}, @w{@code{S_ISCHR}}, @w{@code{S_ISBLK}}, @w{@code{S_ISFIFO}},\n\
922@w{@code{S_ISLNK}}, or @w{@code{S_ISSOCK}} to extract information from this\n\
926File mode, as a string of ten letters or dashes as would be returned by\n\
933User ID of file's owner.\n\
936Group ID of file's group.\n\
939ID of device for block or character special files.\n\
945Time of last access in the same form as time values returned from\n\
946@code{time}. @xref{Timing Utilities}.\n\
949Time of last modification in the same form as time values returned from\n\
950@code{time}. @xref{Timing Utilities}.\n\
953Time of last file status change in the same form as time values\n\
954returned from @code{time}. @xref{Timing Utilities}.\n\
957Size of blocks in the file.\n\
960Number of blocks allocated for file.\n\
963If the call is successful @var{err} is 0 and @var{msg} is an empty\n\
964string. If the file does not exist, or some other error occurs, @var{s}\n\
965is an empty matrix, @var{err} is @minus{}1, and @var{msg} contains the\n\
966corresponding system error message.\n\
968If @var{file} is a symbolic link, @code{stat} will return information\n\
969about the actual file that is referenced by the link. Use @code{lstat}\n\
970if you want information about the symbolic link itself.\n\
975[s, err, msg] = stat (\"/vmlinuz\")\n\
989 modestr = -rw-r--r--\n\
998 octave_value_list retval;
1000 if (args.length () == 1)
1002 std::string fname = args(0).string_value ();
1006 file_stat fs (fname);
1010 retval(2) = std::string ();
1012 retval(0) = octave_value (mk_stat_map (fs));
1016 retval(2) = fs.error ();
1018 retval(0) = Matrix ();
1028DEFUNX ("S_ISREG", FS_ISREG, args, ,
1030@deftypefn {Built-in Function} {} S_ISREG (@var{mode})\n\
1031Return true if @var{mode} corresponds to a regular file. The value\n\
1032of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
1033@seealso{stat, lstat}\n\
1036 octave_value retval = false;
1038 if (args.length () == 1)
1040 double mode = args(0).double_value ();
1043 retval = file_stat::is_reg (static_cast<mode_t> (mode));
1045 error ("S_ISREG: invalid mode value");
1053DEFUNX ("S_ISDIR", FS_ISDIR, args, ,
1055@deftypefn {Built-in Function} {} S_ISDIR (@var{mode})\n\
1056Return true if @var{mode} corresponds to a directory. The value\n\
1057of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
1058@seealso{stat, lstat}\n\
1061 octave_value retval = false;
1063 if (args.length () == 1)
1065 double mode = args(0).double_value ();
1068 retval = file_stat::is_dir (static_cast<mode_t> (mode));
1070 error ("S_ISDIR: invalid mode value");
1078DEFUNX ("S_ISCHR", FS_ISCHR, args, ,
1080@deftypefn {Built-in Function} {} S_ISCHR (@var{mode})\n\
1081Return true if @var{mode} corresponds to a character devicey. The value\n\
1082of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
1083@seealso{stat, lstat}\n\
1086 octave_value retval = false;
1088 if (args.length () == 1)
1090 double mode = args(0).double_value ();
1093 retval = file_stat::is_chr (static_cast<mode_t> (mode));
1095 error ("S_ISCHR: invalid mode value");
1103DEFUNX ("S_ISBLK", FS_ISBLK, args, ,
1105@deftypefn {Built-in Function} {} S_ISBLK (@var{mode})\n\
1106Return true if @var{mode} corresponds to a block device. The value\n\
1107of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
1108@seealso{stat, lstat}\n\
1111 octave_value retval = false;
1113 if (args.length () == 1)
1115 double mode = args(0).double_value ();
1118 retval = file_stat::is_blk (static_cast<mode_t> (mode));
1120 error ("S_ISBLK: invalid mode value");
1128DEFUNX ("S_ISFIFO", FS_ISFIFO, args, ,
1130@deftypefn {Built-in Function} {} S_ISFIFO (@var{mode})\n\
1131Return true if @var{mode} corresponds to a fifo. The value\n\
1132of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
1133@seealso{stat, lstat}\n\
1136 octave_value retval = false;
1138 if (args.length () == 1)
1140 double mode = args(0).double_value ();
1143 retval = file_stat::is_fifo (static_cast<mode_t> (mode));
1145 error ("S_ISFIFO: invalid mode value");
1153DEFUNX ("S_ISLNK", FS_ISLNK, args, ,
1155@deftypefn {Built-in Function} {} S_ISLNK (@var{mode})\n\
1156Return true if @var{mode} corresponds to a symbolic link. The value\n\
1157of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
1158@seealso{stat, lstat}\n\
1161 octave_value retval = false;
1163 if (args.length () == 1)
1165 double mode = args(0).double_value ();
1168 retval = file_stat::is_lnk (static_cast<mode_t> (mode));
1170 error ("S_ISLNK: invalid mode value");
1178DEFUNX ("S_ISSOCK", FS_ISSOCK, args, ,
1180@deftypefn {Built-in Function} {} S_ISSOCK (@var{mode})\n\
1181@seealso{stat, lstat}\n\
1184 octave_value retval = false;
1186 if (args.length () == 1)
1188 double mode = args(0).double_value ();
1191 retval = file_stat::is_sock (static_cast<mode_t> (mode));
1193 error ("S_ISSOCK: invalid mode value");
1201DEFUN (uname, args, ,
1203@deftypefn {Built-in Function} {[@var{uts}, @var{err}, @var{msg}] =} uname ()\n\
1204Return system information in the structure. For example,\n\
1211 nodename = segfault\n\
1212 release = 2.6.15-1-amd64-k8-smp\n\
1214 machine = #2 SMP Thu Feb 23 04:57:49 UTC 2006\n\
1219If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
1220Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
1221system-dependent error message.\n\
1224 octave_value_list retval;
1226 if (args.length () == 0)
1228 octave_uname sysinfo;
1232 m.assign ("sysname", sysinfo.sysname ());
1233 m.assign ("nodename", sysinfo.nodename ());
1234 m.assign ("release", sysinfo.release ());
1235 m.assign ("version", sysinfo.version ());
1236 m.assign ("machine", sysinfo.machine ());
1238 retval(2) = sysinfo.message ();
1239 retval(1) = sysinfo.error ();
1248DEFUNX ("unlink", Funlink, args, ,
1250@deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} unlink (@var{file})\n\
1251Delete the file named @var{file}.\n\
1253If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
1254Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
1255system-dependent error message.\n\
1258 octave_value_list retval;
1260 retval(1) = std::string ();
1263 int nargin = args.length ();
1267 if (args(0).is_string ())
1269 std::string name = args(0).string_value ();
1273 int status = octave_unlink (name, msg);
1279 error ("unlink: file name must be a string");
1287DEFUN (waitpid, args, ,
1289@deftypefn {Built-in Function} {[@var{pid}, @var{status}, @var{msg}] =} waitpid (@var{pid}, @var{options})\n\
1290Wait for process @var{pid} to terminate. The @var{pid} argument can be:\n\
1294Wait for any child process.\n\
1297Wait for any child process whose process group ID is equal to that of\n\
1298the Octave interpreter process.\n\
1301Wait for termination of the child process with ID @var{pid}.\n\
1304The @var{options} argument can be a bitwise OR of zero or more of\n\
1305the following constants:\n\
1309Wait until signal is received or a child process exits (this is the\n\
1310default if the @var{options} argument is missing).\n\
1313Do not hang if status is not immediately available.\n\
1316Report the status of any child processes that are stopped, and whose\n\
1317status has not yet been reported since they stopped.\n\
1320Return if a stopped child has been resumed by delivery of @code{SIGCONT}.\n\
1321This value may not be meaningful on all systems.\n\
1324If the returned value of @var{pid} is greater than 0, it is the process\n\
1325ID of the child process that exited. If an error occurs, @var{pid} will\n\
1326be less than zero and @var{msg} will contain a system-dependent error\n\
1327message. The value of @var{status} contains additional system-dependent\n\
1328information about the subprocess that exited.\n\
1329@seealso{WCONTINUE, WCOREDUMP, WEXITSTATUS, WIFCONTINUED, WIFSIGNALED, WIFSTOPPED, WNOHANG, WSTOPSIG, WTERMSIG, WUNTRACED}\n\
1332 octave_value_list retval;
1334 retval(2) = std::string ();
1338 int nargin = args.length ();
1340 if (nargin == 1 || nargin == 2)
1342 pid_t pid = args(0).int_value (true);
1348 if (args.length () == 2)
1349 options = args(1).int_value (true);
1357 pid_t result = octave_syscalls::waitpid (pid, &status, options, msg);
1364 error ("waitpid: OPTIONS must be an integer");
1367 error ("waitpid: PID must be an integer value");
1375DEFUNX ("WIFEXITED", FWIFEXITED, args, ,
1377@deftypefn {Built-in Function} {} WIFEXITED (@var{status})\n\
1378Given @var{status} from a call to @code{waitpid}, return true if the\n\
1379child terminated normally.\n\
1380@seealso{waitpid, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\
1383 octave_value retval = 0.0;
1385#if defined (WIFEXITED)
1386 if (args.length () == 1)
1388 int status = args(0).int_value ();
1391 retval = WIFEXITED (status);
1393 error ("WIFEXITED: expecting integer argument");
1396 warning ("WIFEXITED always returns false in this version of Octave")
1402DEFUNX ("WEXITSTATUS", FWEXITSTATUS, args, ,
1404@deftypefn {Built-in Function} {} WEXITSTATUS (@var{status})\n\
1405Given @var{status} from a call to @code{waitpid}, return the exit\n\
1406status of the child. This function should only be employed if\n\
1407@code{WIFEXITED} returned true.\n\
1408@seealso{waitpid, WIFEXITED, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\
1411 octave_value retval = 0.0;
1413#if defined (WEXITSTATUS)
1414 if (args.length () == 1)
1416 int status = args(0).int_value ();
1419 retval = WEXITSTATUS (status);
1421 error ("WEXITSTATUS: expecting integer argument");
1424 warning ("WEXITSTATUS always returns false in this version of Octave")
1430DEFUNX ("WIFSIGNALED", FWIFSIGNALED, args, ,
1432@deftypefn {Built-in Function} {} WIFSIGNALED (@var{status})\n\
1433Given @var{status} from a call to @code{waitpid}, return true if the\n\
1434child process was terminated by a signal.\n\
1435@seealso{waitpid, WIFEXITED, WEXITSTATUS, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\
1438 octave_value retval = 0.0;
1440#if defined (WIFSIGNALED)
1441 if (args.length () == 1)
1443 int status = args(0).int_value ();
1446 retval = WIFSIGNALED (status);
1448 error ("WIFSIGNALED: expecting integer argument");
1451 warning ("WIFSIGNALED always returns false in this version of Octave");
1457DEFUNX ("WTERMSIG", FWTERMSIG, args, ,
1459@deftypefn {Built-in Function} {} WTERMSIG (@var{status})\n\
1460Given @var{status} from a call to @code{waitpid}, return the number of\n\
1461the signal that caused the child process to terminate. This function\n\
1462should only be employed if @code{WIFSIGNALED} returned true.\n\
1463@seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\
1466 octave_value retval = 0.0;
1468#if defined (WTERMSIG)
1469 if (args.length () == 1)
1471 int status = args(0).int_value ();
1474 retval = WTERMSIG (status);
1476 error ("WTERMSIG: expecting integer argument");
1479 warning ("WTERMSIG always returns false in this version of Octave");
1485DEFUNX ("WCOREDUMP", FWCOREDUMP, args, ,
1487@deftypefn {Built-in Function} {} WCOREDUMP (@var{status})\n\
1488Given @var{status} from a call to @code{waitpid}, return true if the\n\
1489child produced a core dump. This function should only be employed if\n\
1490@code{WIFSIGNALED} returned true. The macro used to implement this\n\
1491function is not specified in POSIX.1-2001 and is not available on some\n\
1492Unix implementations (e.g., AIX, SunOS).\n\
1493@seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\
1496 octave_value retval = 0.0;
1498#if defined (WCOREDUMP)
1499 if (args.length () == 1)
1501 int status = args(0).int_value ();
1504 retval = WCOREDUMP (status);
1506 error ("WCOREDUMP: expecting integer argument");
1509 warning ("WCOREDUMP always returns false in this version of Octave");
1515DEFUNX ("WIFSTOPPED", FWIFSTOPPED, args, ,
1517@deftypefn {Built-in Function} {} WIFSTOPPED (@var{status})\n\
1518Given @var{status} from a call to @code{waitpid}, return true if the\n\
1519child process was stopped by delivery of a signal; this is only\n\
1520possible if the call was done using @code{WUNTRACED} or when the child\n\
1521is being traced (see ptrace(2)).\n\
1522@seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WSTOPSIG, WIFCONTINUED}\n\
1525 octave_value retval = 0.0;
1527#if defined (WIFSTOPPED)
1528 if (args.length () == 1)
1530 int status = args(0).int_value ();
1533 retval = WIFSTOPPED (status);
1535 error ("WIFSTOPPED: expecting integer argument");
1538 warning ("WIFSTOPPED always returns false in this version of Octave");
1544DEFUNX ("WSTOPSIG", FWSTOPSIG, args, ,
1546@deftypefn {Built-in Function} {} WSTOPSIG (@var{status})\n\
1547Given @var{status} from a call to @code{waitpid}, return the number of\n\
1548the signal which caused the child to stop. This function should only\n\
1549be employed if @code{WIFSTOPPED} returned true.\n\
1550@seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WIFCONTINUED}\n\
1553 octave_value retval = 0.0;
1555#if defined (WSTOPSIG)
1556 if (args.length () == 1)
1558 int status = args(0).int_value ();
1561 retval = WSTOPSIG (status);
1563 error ("WSTOPSIG: expecting integer argument");
1566 warning ("WSTOPSIG always returns false in this version of Octave");
1572DEFUNX ("WIFCONTINUED", FWIFCONTINUED, args, ,
1574@deftypefn {Built-in Function} {} WIFCONTINUED (@var{status})\n\
1575Given @var{status} from a call to @code{waitpid}, return true if the\n\
1576child process was resumed by delivery of @code{SIGCONT}.\n\
1577@seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG}\n\
1580 octave_value retval = 0.0;
1582#if defined (WIFCONTINUED)
1583 if (args.length () == 1)
1585 int status = args(0).int_value ();
1588 retval = WIFCONTINUED (status);
1590 error ("WIFCONTINUED: expecting integer argument");
1593 warning ("WIFCONTINUED always returns false in this version of Octave");
1599DEFUNX ("canonicalize_file_name", Fcanonicalize_file_name, args, ,
1601@deftypefn {Built-in Function} {[@var{cname}, @var{status}, @var{msg}]} canonicalize_file_name (@var{name})\n\
1602Return the canonical name of file @var{name}.\n\
1605 octave_value_list retval;
1607 if (args.length () == 1)
1609 std::string name = args(0).string_value ();
1615 std::string result = octave_canonicalize_file_name (name, msg);
1618 retval(1) = msg.empty () ? 0 : -1;
1622 error ("canonicalize_file_name: argument must be a character string");
1631const_value (const octave_value_list& args, int val)
1633 octave_value retval;
1635 int nargin = args.length ();
1645#if !defined (O_NONBLOCK) && defined (O_NDELAY)
1646#define O_NONBLOCK O_NDELAY
1649#if defined (F_DUPFD)
1650DEFUNX ("F_DUPFD", FF_DUPFD, args, ,
1652@deftypefn {Built-in Function} {} F_DUPFD ()\n\
1653Return the value required to request that @code{fcntl} return a\n\
1654duplicate file descriptor.\n\
1655@seealso{fcntl, F_GETFD, F_GETFL, F_SETFD, F_SETFL}\n\
1658 return const_value (args, F_DUPFD);
1662#if defined (F_GETFD)
1663DEFUNX ("F_GETFD", FF_GETFD, args, ,
1665@deftypefn {Built-in Function} {} F_GETFD ()\n\
1666Return the value required to request that @code{fcntl} to return the\n\
1667file descriptor flags.\n\
1668@seealso{fcntl, F_DUPFD, F_GETFL, F_SETFD, F_SETFL}\n\
1671 return const_value (args, F_GETFD);
1675#if defined (F_GETFL)
1676DEFUNX ("F_GETFL", FF_GETFL, args, ,
1678@deftypefn {Built-in Function} {} F_GETFL ()\n\
1679Return the value required to request that @code{fcntl} to return the\n\
1680file status flags.\n\
1681@seealso{fcntl, F_DUPFD, F_GETFD, F_SETFD, F_SETFL}\n\
1684 return const_value (args, F_GETFL);
1688#if defined (F_SETFD)
1689DEFUNX ("F_SETFD", FF_SETFD, args, ,
1691@deftypefn {Built-in Function} {} F_SETFD ()\n\
1692Return the value required to request that @code{fcntl} to set the file\n\
1694@seealso{fcntl, F_DUPFD, F_GETFD, F_GETFL, F_SETFL}\n\
1697 return const_value (args, F_SETFD);
1701#if defined (F_SETFL)
1702DEFUNX ("F_SETFL", FF_SETFL, args, ,
1704@deftypefn {Built-in Function} {} F_SETFL ()\n\
1705Return the value required to request that @code{fcntl} to set the file\n\
1707@seealso{fcntl, F_DUPFD, F_GETFD, F_GETFL, F_SETFD}\n\
1710 return const_value (args, F_SETFL);
1714#if defined (O_APPEND)
1715DEFUNX ("O_APPEND", FO_APPEND, args, ,
1717@deftypefn {Built-in Function} {} O_APPEND ()\n\
1718Return the numerical value of the file status flag that may be\n\
1719returned by @code{fcntl} to indicate each write operation appends,\n\
1720or that may be passed to @code{fcntl} to set the write mode to append.\\n\
1721@seealso{fcntl, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\
1724 return const_value (args, O_APPEND);
1728#if defined (O_ASYNC)
1729DEFUNX ("O_ASYNC", FO_ASYNC, args, ,
1731@deftypefn {Built-in Function} {} O_ASYNC ()\n\
1732Return the numerical value of the file status flag that may be\n\
1733returned by @code{fcntl} to indicate asynchronous I/O.\n\
1734@seealso{fcntl, O_APPEND, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\
1737 return const_value (args, O_ASYNC);
1741#if defined (O_CREAT)
1742DEFUNX ("O_CREAT", FO_CREAT, args, ,
1744@deftypefn {Built-in Function} {} O_CREAT ()\n\
1745Return the numerical value of the file status flag that may be\n\
1746returned by @code{fcntl} to indicate that a file should be\n\
1747created if it does not exist.\n\
1748@seealso{fcntl, O_APPEND, O_ASYNC, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\
1751 return const_value (args, O_CREAT);
1756DEFUNX ("O_EXCL", FO_EXCL, args, ,
1758@deftypefn {Built-in Function} {} O_EXCL ()\n\
1759Return the numerical value of the file status flag that may be\n\
1760returned by @code{fcntl} to indicate that file locking is used.\n\
1761@seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\
1764 return const_value (args, O_EXCL);
1768#if defined (O_NONBLOCK)
1769DEFUNX ("O_NONBLOCK", FO_NONBLOCK, args, ,
1771@deftypefn {Built-in Function} {} O_NONBLOCK ()\n\
1772Return the numerical value of the file status flag that may be\n\
1773returned by @code{fcntl} to indicate that non-blocking I/O is in use,\n\
1774or that may be passsed to @code{fcntl} to set non-blocking I/O.\n\
1775@seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\
1778 return const_value (args, O_NONBLOCK);
1782#if defined (O_RDONLY)
1783DEFUNX ("O_RDONLY", FO_RDONLY, args, ,
1785@deftypefn {Built-in Function} {} O_RDONLY ()\n\
1786Return the numerical value of the file status flag that may be\n\
1787returned by @code{fcntl} to indicate that a file is open for\n\
1789@seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\
1792 return const_value (args, O_RDONLY);
1797DEFUNX ("O_RDWR", FO_RDWR, args, ,
1799@deftypefn {Built-in Function} {} O_RDWR ()\n\
1800Return the numerical value of the file status flag that may be\n\
1801returned by @code{fcntl} to indicate that a file is open for both\n\
1802reading and writing.\n\
1803@seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_SYNC, O_TRUNC, O_WRONLY}\n\
1806 return const_value (args, O_RDWR);
1811DEFUNX ("O_SYNC", FO_SYNC, args, ,
1813@deftypefn {Built-in Function} {} O_SYNC ()\n\
1814Return the numerical value of the file status flag that may be\n\
1815returned by @code{fcntl} to indicate that a file is open for\n\
1817@seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY}\n\
1820 return const_value (args, O_SYNC);
1824#if defined (O_TRUNC)
1825DEFUNX ("O_TRUNC", FO_TRUNC, args, ,
1827@deftypefn {Built-in Variable} O_TRUNC ()\n\
1828Return the numerical value of the file status flag that may be\n\
1829returned by @code{fcntl} to indicate that if file exists, it should\n\
1830be truncated when writing.\n\
1831@seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_WRONLY}\n\
1834 return const_value (args, O_TRUNC);
1838#if defined (O_WRONLY)
1839DEFUNX ("O_WRONLY", FO_WRONLY, args, ,
1841@deftypefn {Built-in Function} {} O_WRONLY ()\n\
1842Return the numerical value of the file status flag that may be\n\
1843returned by @code{fcntl} to indicate that a file is open for\n\
1845@seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC}\n\
1848 return const_value (args, O_WRONLY);
1852#if !defined (WNOHANG)
1856DEFUNX ("WNOHANG", FWNOHANG, args, ,
1858@deftypefn {Built-in Function} {} WNOHANG ()\n\
1859Return the numerical value of the option argument that may be\n\
1860passed to @code{waitpid} to indicate that it should return its\n\
1861status immediately instead of waiting for a process to exit.\n\
1862@seealso{waitpid, WUNTRACED, WCONTINUE}\n\
1865 return const_value (args, WNOHANG);
1868#if !defined (WUNTRACED)
1872DEFUNX ("WUNTRACED", FWUNTRACED, args, ,
1874@deftypefn {Built-in Function} {} WUNTRACED ()\n\
1875Return the numerical value of the option argument that may be\n\
1876passed to @code{waitpid} to indicate that it should also return\n\
1877if the child process has stopped but is not traced via the\n\
1878@code{ptrace} system call\n\
1879@seealso{waitpid, WNOHANG, WCONTINUE}\n\
1882 return const_value (args, WUNTRACED);
1885#if !defined (WCONTINUE)
1889DEFUNX ("WCONTINUE", FWCONTINUE, args, ,
1891@deftypefn {Built-in Function} {} WCONTINUE ()\n\
1892Return the numerical value of the option argument that may be\n\
1893passed to @code{waitpid} to indicate that it should also return\n\
1894if a stopped child has been resumed by delivery of a @code{SIGCONT}\n\
1896@seealso{waitpid, WNOHANG, WUNTRACED}\n\
1899 return const_value (args, WCONTINUE);