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
37#ifdef HAVE_SYS_TYPES_H
49#include "oct-syscalls.h"
58#include "oct-stdstrm.h"
59#include "oct-stream.h"
66mk_stat_map (const base_file_stat& fs)
70 m.assign ("dev", static_cast<double> (fs.dev ()));
71 m.assign ("ino", fs.ino ());
72 m.assign ("mode", fs.mode ());
73 m.assign ("modestr", fs.mode_as_string ());
74 m.assign ("nlink", fs.nlink ());
75 m.assign ("uid", fs.uid ());
76 m.assign ("gid", fs.gid ());
77#if defined (HAVE_STRUCT_STAT_ST_RDEV)
78 m.assign ("rdev", static_cast<double> (fs.rdev ()));
80 m.assign ("size", fs.size ());
81 m.assign ("atime", fs.atime ());
82 m.assign ("mtime", fs.mtime ());
83 m.assign ("ctime", fs.ctime ());
84#if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
85 m.assign ("blksize", fs.blksize ());
87#if defined (HAVE_STRUCT_STAT_ST_BLOCKS)
88 m.assign ("blocks", fs.blocks ());
96@deftypefn {Built-in Function} {[@var{fid}, @var{msg}] =} dup2 (@var{old}, @var{new})\n\
97Duplicate a file descriptor.\n\
99If successful, @var{fid} is greater than zero and contains the new file\n\
100ID. Otherwise, @var{fid} is negative and @var{msg} contains a\n\
101system-dependent error message.\n\
104 octave_value_list retval;
106 retval(1) = std::string ();
109 int nargin = args.length ();
113 octave_stream old_stream
114 = octave_stream_list::lookup (args(0), "dup2");
118 octave_stream new_stream
119 = octave_stream_list::lookup (args(1), "dup2");
123 int i_old = old_stream.file_number ();
124 int i_new = new_stream.file_number ();
126 if (i_old >= 0 && i_new >= 0)
130 int status = octave_syscalls::dup2 (i_old, i_new, msg);
138 error ("dup2: invalid stream");
148@deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} exec (@var{file}, @var{args})\n\
149Replace current process with a new process. Calling @code{exec} without\n\
150first calling @code{fork} will terminate your current Octave process and\n\
151replace it with the program named by @var{file}. For example,\n\
154exec (\"ls\" \"-l\")\n\
158will run @code{ls} and return you to your shell prompt.\n\
160If successful, @code{exec} does not return. If @code{exec} does return,\n\
161@var{err} will be nonzero, and @var{msg} will contain a system-dependent\n\
165 octave_value_list retval;
167 retval(1) = std::string ();
170 int nargin = args.length ();
172 if (nargin == 1 || nargin == 2)
174 std::string exec_file = args(0).string_value ();
178 string_vector exec_args;
182 string_vector tmp = args(1).all_strings ();
186 int len = tmp.length ();
188 exec_args.resize (len + 1);
190 exec_args[0] = exec_file;
192 for (int i = 0; i < len; i++)
193 exec_args[i+1] = tmp[i];
196 error ("exec: arguments must be character strings");
200 exec_args.resize (1);
202 exec_args[0] = exec_file;
209 int status = octave_syscalls::execvp (exec_file, exec_args, msg);
216 error ("exec: first argument must be a string");
224DEFUN (popen2, args, ,
226@deftypefn {Built-in Function} {[@var{in}, @var{out}, @var{pid}] =} popen2 (@var{command}, @var{args})\n\
227Start a subprocess with two-way communication. The name of the process\n\
228is given by @var{command}, and @var{args} is an array of strings\n\
229containing options for the command. The file identifiers for the input\n\
230and output streams of the subprocess are returned in @var{in} and\n\
231@var{out}. If execution of the command is successful, @var{pid}\n\
232contains the process ID of the subprocess. Otherwise, @var{pid} is\n\
238[in, out, pid] = popen2 (\"sort\", \"-r\");\n\
239fputs (in, \"these\\nare\\nsome\\nstrings\\n\");\n\
241EAGAIN = errno (\"EAGAIN\");\n\
246 fputs (stdout, s);\n\
247 elseif (errno () == EAGAIN)\n\
262Note that @code{popen2}, unlike @code{popen}, will not \"reap\" the\n\
263child process. If you don't use @code{waitpid} to check the child's\n\
264exit status, it will linger until Octave exits.\n\
267 octave_value_list retval;
270 retval(1) = Matrix ();
271 retval(0) = Matrix ();
273 int nargin = args.length ();
275 if (nargin >= 1 && nargin <= 3)
277 std::string exec_file = args(0).string_value();
281 string_vector arg_list;
285 string_vector tmp = args(1).all_strings ();
289 int len = tmp.length ();
291 arg_list.resize (len + 1);
293 arg_list[0] = exec_file;
295 for (int i = 0; i < len; i++)
296 arg_list[i+1] = tmp[i];
299 error ("popen2: arguments must be character strings");
305 arg_list[0] = exec_file;
310 bool sync_mode = (nargin == 3 ? args(2).bool_value() : false);
318 pid = octave_syscalls::popen2 (exec_file, arg_list, sync_mode, fildes, msg, interactive);
321 FILE *ifile = fdopen (fildes[1], "r");
322 FILE *ofile = fdopen (fildes[0], "w");
326 octave_stream is = octave_stdiostream::create (nm, ifile,
329 octave_stream os = octave_stdiostream::create (nm, ofile,
332 Cell file_ids (1, 2);
334 retval(0) = octave_stream_list::insert (os);
335 retval(1) = octave_stream_list::insert (is);
339 error (msg.c_str ());
343 error ("popen2: arguments must be character strings");
346 error ("popen2: first argument must be a string");
358%! [in, out, pid] = popen2 ("sort", "-r");
359%! EAGAIN = errno ("EAGAIN");
361%! [in, out, pid] = popen2 ("sort", "/R");
362%! EAGAIN = errno ("EINVAL");
364%! fputs (in, "these\nare\nsome\nstrings\n");
378%! elseif (errno () == EAGAIN)
390%! assert(str,{"these\n","strings\n","some\n","are\n"})
392%! assert(str,{"these\r\n","strings\r\n","some\r\n","are\r\n"})
399@deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} fcntl (@var{fid}, @var{request}, @var{arg})\n\
400Change the properties of the open file @var{fid}. The following values\n\
401may be passed as @var{request}:\n\
405Return a duplicate file descriptor.\n\
408Return the file descriptor flags for @var{fid}.\n\
411Set the file descriptor flags for @var{fid}.\n\
414Return the file status flags for @var{fid}. The following codes may be\n\
415returned (some of the flags may be undefined on some systems).\n\
419Open for reading only.\n\
422Open for writing only.\n\
425Open for reading and writing.\n\
428Append on each write.\n\
431Create the file if it does not exist.\n\
437Wait for writes to complete.\n\
444Set the file status flags for @var{fid} to the value specified by\n\
445@var{arg}. The only flags that can be changed are @w{@code{O_APPEND}} and\n\
446@w{@code{O_NONBLOCK}}.\n\
449If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
450Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
451system-dependent error message.\n\
454 octave_value_list retval;
456 retval(1) = std::string ();
459 int nargin = args.length ();
463 octave_stream strm = octave_stream_list::lookup (args (0), "fcntl");
467 int fid = strm.file_number ();
469 int req = args(1).int_value (true);
470 int arg = args(2).int_value (true);
474 // FIXME -- Need better checking here?
476 error ("fcntl: invalid file id");
481 int status = octave_syscalls::fcntl (fid, req, arg, msg);
489 error ("fcntl: file id, request, and argument must be integers");
499@deftypefn {Built-in Function} {[@var{pid}, @var{msg}] =} fork ()\n\
500Create a copy of the current process.\n\
502Fork can return one of the following values:\n\
506You are in the parent process. The value returned from @code{fork} is\n\
507the process id of the child process. You should probably arrange to\n\
508wait for any child processes to exit.\n\
511You are in the child process. You can call @code{exec} to start another\n\
512process. If that fails, you should probably call @code{exit}.\n\
515The call to @code{fork} failed for some reason. You must take evasive\n\
516action. A system dependent error message will be waiting in @var{msg}.\n\
520 octave_value_list retval;
522 retval(1) = std::string ();
525 int nargin = args.length ();
531 pid_t pid = octave_syscalls::fork (msg);
542DEFUN (getpgrp, args, ,
544@deftypefn {Built-in Function} {pgid =} getpgrp ()\n\
545Return the process group id of the current process.\n\
548 octave_value_list retval;
550 retval(1) = std::string ();
553 int nargin = args.length ();
559 retval(0) = octave_syscalls::getpgrp (msg);
568DEFUN (getpid, args, ,
570@deftypefn {Built-in Function} {pid =} getpid ()\n\
571Return the process id of the current process.\n\
574 octave_value retval = -1;
576 int nargin = args.length ();
579 retval = octave_syscalls::getpid ();
586DEFUN (getppid, args, ,
588@deftypefn {Built-in Function} {pid =} getppid ()\n\
589Return the process id of the parent process.\n\
592 octave_value retval = -1;
594 int nargin = args.length ();
597 retval = octave_syscalls::getppid ();
604DEFUN (getegid, args, ,
606@deftypefn {Built-in Function} {egid =} getegid ()\n\
607Return the effective group id of the current process.\n\
610 octave_value retval = -1;
612 int nargin = args.length ();
615 retval = octave_syscalls::getegid ();
622DEFUN (getgid, args, ,
624@deftypefn {Built-in Function} {gid =} getgid ()\n\
625Return the real group id of the current process.\n\
628 octave_value retval = -1;
630 int nargin = args.length ();
633 retval = octave_syscalls::getgid ();
640DEFUN (geteuid, args, ,
642@deftypefn {Built-in Function} {euid =} geteuid ()\n\
643Return the effective user id of the current process.\n\
646 octave_value retval = -1;
648 int nargin = args.length ();
651 retval = octave_syscalls::geteuid ();
658DEFUN (getuid, args, ,
660@deftypefn {Built-in Function} {uid =} getuid ()\n\
661Return the real user id of the current process.\n\
664 octave_value retval = -1;
666 int nargin = args.length ();
669 retval = octave_syscalls::getuid ();
678@deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} kill (@var{pid}, @var{sig})\n\
679Send signal @var{sig} to process @var{pid}.\n\
681If @var{pid} is positive, then signal @var{sig} is sent to @var{pid}.\n\
683If @var{pid} is 0, then signal @var{sig} is sent to every process\n\
684in the process group of the current process.\n\
686If @var{pid} is -1, then signal @var{sig} is sent to every process\n\
689If @var{pid} is less than -1, then signal @var{sig} is sent to every\n\
690process in the process group @var{-pid}.\n\
692If @var{sig} is 0, then no signal is sent, but error checking is still\n\
695Return 0 if successful, otherwise return -1.\n\
698 octave_value_list retval;
700 retval(1) = std::string ();
703 if (args.length () == 2)
705 pid_t pid = args(0).int_value (true);
709 int sig = args(1).int_value (true);
715 int status = octave_syscalls::kill (pid, sig, msg);
730@deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} fstat (@var{fid})\n\
731Return information about the open file @var{fid}. See @code{stat}\n\
732for a description of the contents of @var{info}.\n\
735 octave_value_list retval;
737 if (args.length () == 1)
739 int fid = octave_stream_list::get_file_number (args(0));
747 retval(2) = std::string ();
749 retval(0) = octave_value (mk_stat_map (fs));
753 retval(2) = fs.error ();
755 retval(0) = Matrix ();
767@deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{file})\n\
771 octave_value_list retval;
773 if (args.length () == 1)
775 std::string fname = args(0).string_value ();
779 file_stat fs (fname, false);
783 retval(2) = std::string ();
785 retval(0) = mk_stat_map (fs);
789 retval(2) = fs.error ();
791 retval(0) = Matrix ();
803DEFUN (mkfifo, args, ,
805@deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} mkfifo (@var{name}, @var{mode})\n\
806Create a @var{fifo} special file named @var{name} with file mode @var{mode}\n\
808If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
809Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
810system-dependent error message.\n\
813 octave_value_list retval;
815 retval(1) = std::string ();
818 int nargin = args.length ();
822 if (args(0).is_string ())
824 std::string name = args(0).string_value ();
826 if (args(1).is_scalar_type ())
828 long mode = args(1).long_value ();
834 int status = file_ops::mkfifo (name, mode, msg);
842 error ("mkfifo: invalid MODE");
845 error ("mkfifo: MODE must be an integer");
848 error ("mkfifo: file name must be a string");
858@deftypefn {Built-in Function} {[@var{read_fd}, @var{write_fd}, @var{err}, @var{msg}] =} pipe ()\n\
859Create a pipe and return the reading and writing ends of the pipe\n\
860into @var{read_fd} and @var{write_fd} respectively.\n\
862If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
863Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
864system-dependent error message.\n\
867 octave_value_list retval;
869 retval(3) = std::string ();
874 int nargin = args.length ();
882 int status = octave_syscalls::pipe (fid, msg);
888 FILE *ifile = fdopen (fid[0], "r");
889 FILE *ofile = fdopen (fid[1], "w");
893 octave_stream is = octave_stdiostream::create (nm, ifile,
896 octave_stream os = octave_stdiostream::create (nm, ofile,
899 retval(1) = octave_stream_list::insert (os);
900 retval(0) = octave_stream_list::insert (is);
913@deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} stat (@var{file})\n\
914@deftypefnx {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{file})\n\
915Return a structure @var{s} containing the following information about\n\
920ID of device containing a directory entry for this file.\n\
923File number of the file.\n\
926File mode, as an integer. Use the functions @w{@code{S_ISREG}},\n\
927@w{@code{S_ISDIR}}, @w{@code{S_ISCHR}}, @w{@code{S_ISBLK}}, @w{@code{S_ISFIFO}},\n\
928@w{@code{S_ISLNK}}, or @w{@code{S_ISSOCK}} to extract information from this\n\
932File mode, as a string of ten letters or dashes as would be returned by\n\
939User ID of file's owner.\n\
942Group ID of file's group.\n\
945ID of device for block or character special files.\n\
951Time of last access in the same form as time values returned from\n\
952@code{time}. @xref{Timing Utilities}.\n\
955Time of last modification in the same form as time values returned from\n\
956@code{time}. @xref{Timing Utilities}.\n\
959Time of last file status change in the same form as time values\n\
960returned from @code{time}. @xref{Timing Utilities}.\n\
963Size of blocks in the file.\n\
966Number of blocks allocated for file.\n\
969If the call is successful @var{err} is 0 and @var{msg} is an empty\n\
970string. If the file does not exist, or some other error occurs, @var{s}\n\
971is an empty matrix, @var{err} is @minus{}1, and @var{msg} contains the\n\
972corresponding system error message.\n\
974If @var{file} is a symbolic link, @code{stat} will return information\n\
975about the actual file that is referenced by the link. Use @code{lstat}\n\
976if you want information about the symbolic link itself.\n\
981[s, err, msg] = stat (\"/vmlinuz\")\n\
995 modestr = -rw-r--r--\n\
1004 octave_value_list retval;
1006 if (args.length () == 1)
1008 std::string fname = args(0).string_value ();
1012 file_stat fs (fname);
1016 retval(2) = std::string ();
1018 retval(0) = octave_value (mk_stat_map (fs));
1022 retval(2) = fs.error ();
1024 retval(0) = Matrix ();
1034DEFUNX ("S_ISREG", FS_ISREG, args, ,
1036@deftypefn {Built-in Function} {} S_ISREG (@var{mode})\n\
1037Return true if @var{mode} corresponds to a regular file. The value\n\
1038of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
1039@seealso{stat, lstat}\n\
1042 octave_value retval = false;
1044 if (args.length () == 1)
1046 double mode = args(0).double_value ();
1049 retval = file_stat::is_reg (static_cast<mode_t> (mode));
1051 error ("S_ISREG: invalid mode value");
1059DEFUNX ("S_ISDIR", FS_ISDIR, args, ,
1061@deftypefn {Built-in Function} {} S_ISDIR (@var{mode})\n\
1062Return true if @var{mode} corresponds to a directory. The value\n\
1063of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
1064@seealso{stat, lstat}\n\
1067 octave_value retval = false;
1069 if (args.length () == 1)
1071 double mode = args(0).double_value ();
1074 retval = file_stat::is_dir (static_cast<mode_t> (mode));
1076 error ("S_ISDIR: invalid mode value");
1084DEFUNX ("S_ISCHR", FS_ISCHR, args, ,
1086@deftypefn {Built-in Function} {} S_ISCHR (@var{mode})\n\
1087Return true if @var{mode} corresponds to a character devicey. The value\n\
1088of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
1089@seealso{stat, lstat}\n\
1092 octave_value retval = false;
1094 if (args.length () == 1)
1096 double mode = args(0).double_value ();
1099 retval = file_stat::is_chr (static_cast<mode_t> (mode));
1101 error ("S_ISCHR: invalid mode value");
1109DEFUNX ("S_ISBLK", FS_ISBLK, args, ,
1111@deftypefn {Built-in Function} {} S_ISBLK (@var{mode})\n\
1112Return true if @var{mode} corresponds to a block device. The value\n\
1113of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
1114@seealso{stat, lstat}\n\
1117 octave_value retval = false;
1119 if (args.length () == 1)
1121 double mode = args(0).double_value ();
1124 retval = file_stat::is_blk (static_cast<mode_t> (mode));
1126 error ("S_ISBLK: invalid mode value");
1134DEFUNX ("S_ISFIFO", FS_ISFIFO, args, ,
1136@deftypefn {Built-in Function} {} S_ISFIFO (@var{mode})\n\
1137Return true if @var{mode} corresponds to a fifo. The value\n\
1138of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
1139@seealso{stat, lstat}\n\
1142 octave_value retval = false;
1144 if (args.length () == 1)
1146 double mode = args(0).double_value ();
1149 retval = file_stat::is_fifo (static_cast<mode_t> (mode));
1151 error ("S_ISFIFO: invalid mode value");
1159DEFUNX ("S_ISLNK", FS_ISLNK, args, ,
1161@deftypefn {Built-in Function} {} S_ISLNK (@var{mode})\n\
1162Return true if @var{mode} corresponds to a symbolic link. The value\n\
1163of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
1164@seealso{stat, lstat}\n\
1167 octave_value retval = false;
1169 if (args.length () == 1)
1171 double mode = args(0).double_value ();
1174 retval = file_stat::is_lnk (static_cast<mode_t> (mode));
1176 error ("S_ISLNK: invalid mode value");
1184DEFUNX ("S_ISSOCK", FS_ISSOCK, args, ,
1186@deftypefn {Built-in Function} {} S_ISSOCK (@var{mode})\n\
1187@seealso{stat, lstat}\n\
1190 octave_value retval = false;
1192 if (args.length () == 1)
1194 double mode = args(0).double_value ();
1197 retval = file_stat::is_sock (static_cast<mode_t> (mode));
1199 error ("S_ISSOCK: invalid mode value");
1207DEFUN (uname, args, ,
1209@deftypefn {Built-in Function} {[@var{uts}, @var{err}, @var{msg}] =} uname ()\n\
1210Return system information in the structure. For example,\n\
1217 nodename = segfault\n\
1218 release = 2.6.15-1-amd64-k8-smp\n\
1220 machine = #2 SMP Thu Feb 23 04:57:49 UTC 2006\n\
1225If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
1226Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
1227system-dependent error message.\n\
1230 octave_value_list retval;
1232 if (args.length () == 0)
1234 octave_uname sysinfo;
1238 m.assign ("sysname", sysinfo.sysname ());
1239 m.assign ("nodename", sysinfo.nodename ());
1240 m.assign ("release", sysinfo.release ());
1241 m.assign ("version", sysinfo.version ());
1242 m.assign ("machine", sysinfo.machine ());
1244 retval(2) = sysinfo.message ();
1245 retval(1) = sysinfo.error ();
1254DEFUN (unlink, args, ,
1256@deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} unlink (@var{file})\n\
1257Delete the file named @var{file}.\n\
1259If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
1260Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
1261system-dependent error message.\n\
1264 octave_value_list retval;
1266 retval(1) = std::string ();
1269 int nargin = args.length ();
1273 if (args(0).is_string ())
1275 std::string name = args(0).string_value ();
1279 int status = file_ops::unlink (name, msg);
1285 error ("unlink: file name must be a string");
1293DEFUN (waitpid, args, ,
1295@deftypefn {Built-in Function} {[@var{pid}, @var{status}, @var{msg}] =} waitpid (@var{pid}, @var{options})\n\
1296Wait for process @var{pid} to terminate. The @var{pid} argument can be:\n\
1300Wait for any child process.\n\
1303Wait for any child process whose process group ID is equal to that of\n\
1304the Octave interpreter process.\n\
1307Wait for termination of the child process with ID @var{pid}.\n\
1310The @var{options} argument can be a bitwise OR of zero or more of\n\
1311the following constants:\n\
1315Wait until signal is received or a child process exits (this is the\n\
1316default if the @var{options} argument is missing).\n\
1319Do not hang if status is not immediately available.\n\
1322Report the status of any child processes that are stopped, and whose\n\
1323status has not yet been reported since they stopped.\n\
1326Return if a stopped child has been resumed by delivery of @code{SIGCONT}.\n\
1327This value may not be meaningful on all systems.\n\
1330If the returned value of @var{pid} is greater than 0, it is the process\n\
1331ID of the child process that exited. If an error occurs, @var{pid} will\n\
1332be less than zero and @var{msg} will contain a system-dependent error\n\
1333message. The value of @var{status} contains additional system-dependent\n\
1334information about the subprocess that exited.\n\
1335@seealso{WCONTINUE, WCOREDUMP, WEXITSTATUS, WIFCONTINUED, WIFSIGNALED, WIFSTOPPED, WNOHANG, WSTOPSIG, WTERMSIG, WUNTRACED}\n\
1338 octave_value_list retval;
1340 retval(2) = std::string ();
1344 int nargin = args.length ();
1346 if (nargin == 1 || nargin == 2)
1348 pid_t pid = args(0).int_value (true);
1354 if (args.length () == 2)
1355 options = args(1).int_value (true);
1363 pid_t result = octave_syscalls::waitpid (pid, &status, options, msg);
1370 error ("waitpid: OPTIONS must be an integer");
1373 error ("waitpid: PID must be an integer value");
1381DEFUNX ("WIFEXITED", FWIFEXITED, args, ,
1383@deftypefn {Built-in Function} {} WIFEXITED (@var{status})\n\
1384Given @var{status} from a call to @code{waitpid}, return true if the\n\
1385child terminated normally.\n\
1386@seealso{waitpid, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\
1389 octave_value retval = 0.0;
1391#if defined (WIFEXITED)
1392 if (args.length () == 1)
1394 int status = args(0).int_value ();
1397 retval = WIFEXITED (status);
1399 error ("WIFEXITED: expecting integer argument");
1402 warning ("WIFEXITED always returns false in this version of Octave")
1408DEFUNX ("WEXITSTATUS", FWEXITSTATUS, args, ,
1410@deftypefn {Built-in Function} {} WEXITSTATUS (@var{status})\n\
1411Given @var{status} from a call to @code{waitpid}, return the exit\n\
1412status of the child. This function should only be employed if\n\
1413@code{WIFEXITED} returned true.\n\
1414@seealso{waitpid, WIFEXITED, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\
1417 octave_value retval = 0.0;
1419#if defined (WEXITSTATUS)
1420 if (args.length () == 1)
1422 int status = args(0).int_value ();
1425 retval = WEXITSTATUS (status);
1427 error ("WEXITSTATUS: expecting integer argument");
1430 warning ("WEXITSTATUS always returns false in this version of Octave")
1436DEFUNX ("WIFSIGNALED", FWIFSIGNALED, args, ,
1438@deftypefn {Built-in Function} {} WIFSIGNALED (@var{status})\n\
1439Given @var{status} from a call to @code{waitpid}, return true if the\n\
1440child process was terminated by a signal.\n\
1441@seealso{waitpid, WIFEXITED, WEXITSTATUS, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\
1444 octave_value retval = 0.0;
1446#if defined (WIFSIGNALED)
1447 if (args.length () == 1)
1449 int status = args(0).int_value ();
1452 retval = WIFSIGNALED (status);
1454 error ("WIFSIGNALED: expecting integer argument");
1457 warning ("WIFSIGNALED always returns false in this version of Octave");
1463DEFUNX ("WTERMSIG", FWTERMSIG, args, ,
1465@deftypefn {Built-in Function} {} WTERMSIG (@var{status})\n\
1466Given @var{status} from a call to @code{waitpid}, return the number of\n\
1467the signal that caused the child process to terminate. This function\n\
1468should only be employed if @code{WIFSIGNALED} returned true.\n\
1469@seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\
1472 octave_value retval = 0.0;
1474#if defined (WTERMSIG)
1475 if (args.length () == 1)
1477 int status = args(0).int_value ();
1480 retval = WTERMSIG (status);
1482 error ("WTERMSIG: expecting integer argument");
1485 warning ("WTERMSIG always returns false in this version of Octave");
1491DEFUNX ("WCOREDUMP", FWCOREDUMP, args, ,
1493@deftypefn {Built-in Function} {} WCOREDUMP (@var{status})\n\
1494Given @var{status} from a call to @code{waitpid}, return true if the\n\
1495child produced a core dump. This function should only be employed if\n\
1496@code{WIFSIGNALED} returned true. The macro used to implement this\n\
1497function is not specified in POSIX.1-2001 and is not available on some\n\
1498Unix implementations (e.g., AIX, SunOS).\n\
1499@seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\
1502 octave_value retval = 0.0;
1504#if defined (WCOREDUMP)
1505 if (args.length () == 1)
1507 int status = args(0).int_value ();
1510 retval = WCOREDUMP (status);
1512 error ("WCOREDUMP: expecting integer argument");
1515 warning ("WCOREDUMP always returns false in this version of Octave");
1521DEFUNX ("WIFSTOPPED", FWIFSTOPPED, args, ,
1523@deftypefn {Built-in Function} {} WIFSTOPPED (@var{status})\n\
1524Given @var{status} from a call to @code{waitpid}, return true if the\n\
1525child process was stopped by delivery of a signal; this is only\n\
1526possible if the call was done using @code{WUNTRACED} or when the child\n\
1527is being traced (see ptrace(2)).\n\
1528@seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WSTOPSIG, WIFCONTINUED}\n\
1531 octave_value retval = 0.0;
1533#if defined (WIFSTOPPED)
1534 if (args.length () == 1)
1536 int status = args(0).int_value ();
1539 retval = WIFSTOPPED (status);
1541 error ("WIFSTOPPED: expecting integer argument");
1544 warning ("WIFSTOPPED always returns false in this version of Octave");
1550DEFUNX ("WSTOPSIG", FWSTOPSIG, args, ,
1552@deftypefn {Built-in Function} {} WSTOPSIG (@var{status})\n\
1553Given @var{status} from a call to @code{waitpid}, return the number of\n\
1554the signal which caused the child to stop. This function should only\n\
1555be employed if @code{WIFSTOPPED} returned true.\n\
1556@seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WIFCONTINUED}\n\
1559 octave_value retval = 0.0;
1561#if defined (WSTOPSIG)
1562 if (args.length () == 1)
1564 int status = args(0).int_value ();
1567 retval = WSTOPSIG (status);
1569 error ("WSTOPSIG: expecting integer argument");
1572 warning ("WSTOPSIG always returns false in this version of Octave");
1578DEFUNX ("WIFCONTINUED", FWIFCONTINUED, args, ,
1580@deftypefn {Built-in Function} {} WIFCONTINUED (@var{status})\n\
1581Given @var{status} from a call to @code{waitpid}, return true if the\n\
1582child process was resumed by delivery of @code{SIGCONT}.\n\
1583@seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG}\n\
1586 octave_value retval = 0.0;
1588#if defined (WIFCONTINUED)
1589 if (args.length () == 1)
1591 int status = args(0).int_value ();
1594 retval = WIFCONTINUED (status);
1596 error ("WIFCONTINUED: expecting integer argument");
1599 warning ("WIFCONTINUED always returns false in this version of Octave");
1605DEFUN (canonicalize_file_name, args, ,
1607@deftypefn {Built-in Function} {[@var{cname}, @var{status}, @var{msg}]} canonicalize_file_name (@var{name})\n\
1608Return the canonical name of file @var{name}.\n\
1611 octave_value_list retval;
1613 if (args.length () == 1)
1615 std::string name = args(0).string_value ();
1621 std::string result = file_ops::canonicalize_file_name (name, msg);
1624 retval(1) = msg.empty () ? 0 : -1;
1628 error ("canonicalize_file_name: argument must be a character string");
1637const_value (const octave_value_list& args, int val)
1639 octave_value retval;
1641 int nargin = args.length ();
1651#if !defined (O_NONBLOCK) && defined (O_NDELAY)
1652#define O_NONBLOCK O_NDELAY
1655#if defined (F_DUPFD)
1656DEFUNX ("F_DUPFD", FF_DUPFD, args, ,
1658@deftypefn {Built-in Function} {} F_DUPFD ()\n\
1659Return the value required to request that @code{fcntl} return a\n\
1660duplicate file descriptor.\n\
1661@seealso{fcntl, F_GETFD, F_GETFL, F_SETFD, F_SETFL}\n\
1664 return const_value (args, F_DUPFD);
1668#if defined (F_GETFD)
1669DEFUNX ("F_GETFD", FF_GETFD, args, ,
1671@deftypefn {Built-in Function} {} F_GETFD ()\n\
1672Return the value required to request that @code{fcntl} to return the\n\
1673file descriptor flags.\n\
1674@seealso{fcntl, F_DUPFD, F_GETFL, F_SETFD, F_SETFL}\n\
1677 return const_value (args, F_GETFD);
1681#if defined (F_GETFL)
1682DEFUNX ("F_GETFL", FF_GETFL, args, ,
1684@deftypefn {Built-in Function} {} F_GETFL ()\n\
1685Return the value required to request that @code{fcntl} to return the\n\
1686file status flags.\n\
1687@seealso{fcntl, F_DUPFD, F_GETFD, F_SETFD, F_SETFL}\n\
1690 return const_value (args, F_GETFL);
1694#if defined (F_SETFD)
1695DEFUNX ("F_SETFD", FF_SETFD, args, ,
1697@deftypefn {Built-in Function} {} F_SETFD ()\n\
1698Return the value required to request that @code{fcntl} to set the file\n\
1700@seealso{fcntl, F_DUPFD, F_GETFD, F_GETFL, F_SETFL}\n\
1703 return const_value (args, F_SETFD);
1707#if defined (F_SETFL)
1708DEFUNX ("F_SETFL", FF_SETFL, args, ,
1710@deftypefn {Built-in Function} {} F_SETFL ()\n\
1711Return the value required to request that @code{fcntl} to set the file\n\
1713@seealso{fcntl, F_DUPFD, F_GETFD, F_GETFL, F_SETFD}\n\
1716 return const_value (args, F_SETFL);
1720#if defined (O_APPEND)
1721DEFUNX ("O_APPEND", FO_APPEND, args, ,
1723@deftypefn {Built-in Function} {} O_APPEND ()\n\
1724Return the numerical value of the file status flag that may be\n\
1725returned by @code{fcntl} to indicate each write operation appends,\n\
1726or that may be passed to @code{fcntl} to set the write mode to append.\\n\
1727@seealso{fcntl, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\
1730 return const_value (args, O_APPEND);
1734#if defined (O_ASYNC)
1735DEFUNX ("O_ASYNC", FO_ASYNC, args, ,
1737@deftypefn {Built-in Function} {} O_ASYNC ()\n\
1738Return the numerical value of the file status flag that may be\n\
1739returned by @code{fcntl} to indicate asynchronous I/O.\n\
1740@seealso{fcntl, O_APPEND, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\
1743 return const_value (args, O_ASYNC);
1747#if defined (O_CREAT)
1748DEFUNX ("O_CREAT", FO_CREAT, args, ,
1750@deftypefn {Built-in Function} {} O_CREAT ()\n\
1751Return the numerical value of the file status flag that may be\n\
1752returned by @code{fcntl} to indicate that a file should be\n\
1753created if it does not exist.\n\
1754@seealso{fcntl, O_APPEND, O_ASYNC, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\
1757 return const_value (args, O_CREAT);
1762DEFUNX ("O_EXCL", FO_EXCL, args, ,
1764@deftypefn {Built-in Function} {} O_EXCL ()\n\
1765Return the numerical value of the file status flag that may be\n\
1766returned by @code{fcntl} to indicate that file locking is used.\n\
1767@seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\
1770 return const_value (args, O_EXCL);
1774#if defined (O_NONBLOCK)
1775DEFUNX ("O_NONBLOCK", FO_NONBLOCK, args, ,
1777@deftypefn {Built-in Function} {} O_NONBLOCK ()\n\
1778Return the numerical value of the file status flag that may be\n\
1779returned by @code{fcntl} to indicate that non-blocking I/O is in use,\n\
1780or that may be passsed to @code{fcntl} to set non-blocking I/O.\n\
1781@seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\
1784 return const_value (args, O_NONBLOCK);
1788#if defined (O_RDONLY)
1789DEFUNX ("O_RDONLY", FO_RDONLY, args, ,
1791@deftypefn {Built-in Function} {} O_RDONLY ()\n\
1792Return the numerical value of the file status flag that may be\n\
1793returned by @code{fcntl} to indicate that a file is open for\n\
1795@seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\
1798 return const_value (args, O_RDONLY);
1803DEFUNX ("O_RDWR", FO_RDWR, args, ,
1805@deftypefn {Built-in Function} {} O_RDWR ()\n\
1806Return the numerical value of the file status flag that may be\n\
1807returned by @code{fcntl} to indicate that a file is open for both\n\
1808reading and writing.\n\
1809@seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_SYNC, O_TRUNC, O_WRONLY}\n\
1812 return const_value (args, O_RDWR);
1817DEFUNX ("O_SYNC", FO_SYNC, args, ,
1819@deftypefn {Built-in Function} {} O_SYNC ()\n\
1820Return the numerical value of the file status flag that may be\n\
1821returned by @code{fcntl} to indicate that a file is open for\n\
1823@seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY}\n\
1826 return const_value (args, O_SYNC);
1830#if defined (O_TRUNC)
1831DEFUNX ("O_TRUNC", FO_TRUNC, args, ,
1833@deftypefn {Built-in Variable} O_TRUNC ()\n\
1834Return the numerical value of the file status flag that may be\n\
1835returned by @code{fcntl} to indicate that if file exists, it should\n\
1836be truncated when writing.\n\
1837@seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_WRONLY}\n\
1840 return const_value (args, O_TRUNC);
1844#if defined (O_WRONLY)
1845DEFUNX ("O_WRONLY", FO_WRONLY, args, ,
1847@deftypefn {Built-in Function} {} O_WRONLY ()\n\
1848Return the numerical value of the file status flag that may be\n\
1849returned by @code{fcntl} to indicate that a file is open for\n\
1851@seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC}\n\
1854 return const_value (args, O_WRONLY);
1858#if !defined (WNOHANG)
1862DEFUNX ("WNOHANG", FWNOHANG, args, ,
1864@deftypefn {Built-in Function} {} WNOHANG ()\n\
1865Return the numerical value of the option argument that may be\n\
1866passed to @code{waitpid} to indicate that it should return its\n\
1867status immediately instead of waiting for a process to exit.\n\
1868@seealso{waitpid, WUNTRACED, WCONTINUE}\n\
1871 return const_value (args, WNOHANG);
1874#if !defined (WUNTRACED)
1878DEFUNX ("WUNTRACED", FWUNTRACED, args, ,
1880@deftypefn {Built-in Function} {} WUNTRACED ()\n\
1881Return the numerical value of the option argument that may be\n\
1882passed to @code{waitpid} to indicate that it should also return\n\
1883if the child process has stopped but is not traced via the\n\
1884@code{ptrace} system call\n\
1885@seealso{waitpid, WNOHANG, WCONTINUE}\n\
1888 return const_value (args, WUNTRACED);
1891#if !defined (WCONTINUE)
1895DEFUNX ("WCONTINUE", FWCONTINUE, args, ,
1897@deftypefn {Built-in Function} {} WCONTINUE ()\n\
1898Return the numerical value of the option argument that may be\n\
1899passed to @code{waitpid} to indicate that it should also return\n\
1900if a stopped child has been resumed by delivery of a @code{SIGCONT}\n\
1902@seealso{waitpid, WNOHANG, WUNTRACED}\n\
1905 return const_value (args, WCONTINUE);
1909;;; Local Variables: ***