00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifdef HAVE_CONFIG_H
00030 #include <config.h>
00031 #endif
00032
00033 #include <cstdio>
00034 #include <cstring>
00035
00036 #include <sys/types.h>
00037 #include <unistd.h>
00038
00039 #include <fcntl.h>
00040
00041 #include "file-ops.h"
00042 #include "file-stat.h"
00043 #include "oct-env.h"
00044 #include "oct-syscalls.h"
00045 #include "oct-uname.h"
00046
00047 #include "defun.h"
00048 #include "error.h"
00049 #include "gripes.h"
00050 #include "lo-utils.h"
00051 #include "oct-map.h"
00052 #include "oct-obj.h"
00053 #include "oct-stdstrm.h"
00054 #include "oct-stream.h"
00055 #include "sysdep.h"
00056 #include "utils.h"
00057 #include "variables.h"
00058 #include "input.h"
00059
00060 static octave_scalar_map
00061 mk_stat_map (const base_file_stat& fs)
00062 {
00063 octave_scalar_map m;
00064
00065 m.assign ("dev", static_cast<double> (fs.dev ()));
00066 m.assign ("ino", fs.ino ());
00067 m.assign ("mode", fs.mode ());
00068 m.assign ("modestr", fs.mode_as_string ());
00069 m.assign ("nlink", fs.nlink ());
00070 m.assign ("uid", fs.uid ());
00071 m.assign ("gid", fs.gid ());
00072 #if defined (HAVE_STRUCT_STAT_ST_RDEV)
00073 m.assign ("rdev", static_cast<double> (fs.rdev ()));
00074 #endif
00075 m.assign ("size", fs.size ());
00076 m.assign ("atime", fs.atime ());
00077 m.assign ("mtime", fs.mtime ());
00078 m.assign ("ctime", fs.ctime ());
00079 #if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
00080 m.assign ("blksize", fs.blksize ());
00081 #endif
00082 #if defined (HAVE_STRUCT_STAT_ST_BLOCKS)
00083 m.assign ("blocks", fs.blocks ());
00084 #endif
00085
00086 return m;
00087 }
00088
00089 static octave_value_list
00090 mk_stat_result (const base_file_stat& fs)
00091 {
00092 octave_value_list retval;
00093
00094 if (fs)
00095 {
00096 retval(2) = std::string ();
00097 retval(1) = 0;
00098 retval(0) = octave_value (mk_stat_map (fs));
00099 }
00100 else
00101 {
00102 retval(2) = fs.error ();
00103 retval(1) = -1;
00104 retval(0) = Matrix ();
00105 }
00106
00107 return retval;
00108 }
00109
00110 DEFUNX ("dup2", Fdup2, args, ,
00111 "-*- texinfo -*-\n\
00112 @deftypefn {Built-in Function} {[@var{fid}, @var{msg}] =} dup2 (@var{old}, @var{new})\n\
00113 Duplicate a file descriptor.\n\
00114 \n\
00115 If successful, @var{fid} is greater than zero and contains the new file\n\
00116 ID@. Otherwise, @var{fid} is negative and @var{msg} contains a\n\
00117 system-dependent error message.\n\
00118 @end deftypefn")
00119 {
00120 octave_value_list retval;
00121
00122 retval(1) = std::string ();
00123 retval(0) = -1;
00124
00125 int nargin = args.length ();
00126
00127 if (nargin == 2)
00128 {
00129 octave_stream old_stream
00130 = octave_stream_list::lookup (args(0), "dup2");
00131
00132 if (! error_state)
00133 {
00134 octave_stream new_stream
00135 = octave_stream_list::lookup (args(1), "dup2");
00136
00137 if (! error_state)
00138 {
00139 int i_old = old_stream.file_number ();
00140 int i_new = new_stream.file_number ();
00141
00142 if (i_old >= 0 && i_new >= 0)
00143 {
00144 std::string msg;
00145
00146 int status = octave_syscalls::dup2 (i_old, i_new, msg);
00147
00148 retval(1) = msg;
00149 retval(0) = status;
00150 }
00151 }
00152 }
00153 else
00154 error ("dup2: invalid stream");
00155 }
00156 else
00157 print_usage ();
00158
00159 return retval;
00160 }
00161
00162 DEFUNX ("exec", Fexec, args, ,
00163 "-*- texinfo -*-\n\
00164 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} exec (@var{file}, @var{args})\n\
00165 Replace current process with a new process. Calling @code{exec} without\n\
00166 first calling @code{fork} will terminate your current Octave process and\n\
00167 replace it with the program named by @var{file}. For example,\n\
00168 \n\
00169 @example\n\
00170 exec (\"ls\" \"-l\")\n\
00171 @end example\n\
00172 \n\
00173 @noindent\n\
00174 will run @code{ls} and return you to your shell prompt.\n\
00175 \n\
00176 If successful, @code{exec} does not return. If @code{exec} does return,\n\
00177 @var{err} will be nonzero, and @var{msg} will contain a system-dependent\n\
00178 error message.\n\
00179 @end deftypefn")
00180 {
00181 octave_value_list retval;
00182
00183 retval(1) = std::string ();
00184 retval(0) = -1;
00185
00186 int nargin = args.length ();
00187
00188 if (nargin == 1 || nargin == 2)
00189 {
00190 std::string exec_file = args(0).string_value ();
00191
00192 if (! error_state)
00193 {
00194 string_vector exec_args;
00195
00196 if (nargin == 2)
00197 {
00198 string_vector tmp = args(1).all_strings ();
00199
00200 if (! error_state)
00201 {
00202 int len = tmp.length ();
00203
00204 exec_args.resize (len + 1);
00205
00206 exec_args[0] = exec_file;
00207
00208 for (int i = 0; i < len; i++)
00209 exec_args[i+1] = tmp[i];
00210 }
00211 else
00212 error ("exec: arguments must be character strings");
00213 }
00214 else
00215 {
00216 exec_args.resize (1);
00217
00218 exec_args[0] = exec_file;
00219 }
00220
00221 if (! error_state)
00222 {
00223 std::string msg;
00224
00225 int status = octave_syscalls::execvp (exec_file, exec_args, msg);
00226
00227 retval(1) = msg;
00228 retval(0) = status;
00229 }
00230 }
00231 else
00232 error ("exec: FILE must be a string");
00233 }
00234 else
00235 print_usage ();
00236
00237 return retval;
00238 }
00239
00240 DEFUNX ("popen2", Fpopen2, args, ,
00241 "-*- texinfo -*-\n\
00242 @deftypefn {Built-in Function} {[@var{in}, @var{out}, @var{pid}] =} popen2 (@var{command}, @var{args})\n\
00243 Start a subprocess with two-way communication. The name of the process\n\
00244 is given by @var{command}, and @var{args} is an array of strings\n\
00245 containing options for the command. The file identifiers for the input\n\
00246 and output streams of the subprocess are returned in @var{in} and\n\
00247 @var{out}. If execution of the command is successful, @var{pid}\n\
00248 contains the process ID of the subprocess. Otherwise, @var{pid} is\n\
00249 @minus{}1.\n\
00250 \n\
00251 For example:\n\
00252 \n\
00253 @example\n\
00254 [in, out, pid] = popen2 (\"sort\", \"-r\");\n\
00255 fputs (in, \"these\\nare\\nsome\\nstrings\\n\");\n\
00256 fclose (in);\n\
00257 EAGAIN = errno (\"EAGAIN\");\n\
00258 done = false;\n\
00259 do\n\
00260 s = fgets (out);\n\
00261 if (ischar (s))\n\
00262 fputs (stdout, s);\n\
00263 elseif (errno () == EAGAIN)\n\
00264 sleep (0.1);\n\
00265 fclear (out);\n\
00266 else\n\
00267 done = true;\n\
00268 endif\n\
00269 until (done)\n\
00270 fclose (out);\n\
00271 waitpid (pid);\n\
00272 @print{} these\n\
00273 @print{} strings\n\
00274 @print{} some\n\
00275 @print{} are\n\
00276 @end example\n\
00277 \n\
00278 Note that @code{popen2}, unlike @code{popen}, will not \"reap\" the\n\
00279 child process. If you don't use @code{waitpid} to check the child's\n\
00280 exit status, it will linger until Octave exits.\n\
00281 @end deftypefn")
00282 {
00283 octave_value_list retval;
00284
00285 retval(2) = -1;
00286 retval(1) = Matrix ();
00287 retval(0) = Matrix ();
00288
00289 int nargin = args.length ();
00290
00291 if (nargin >= 1 && nargin <= 3)
00292 {
00293 std::string exec_file = args(0).string_value();
00294
00295 if (! error_state)
00296 {
00297 string_vector arg_list;
00298
00299 if (nargin >= 2)
00300 {
00301 string_vector tmp = args(1).all_strings ();
00302
00303 if (! error_state)
00304 {
00305 int len = tmp.length ();
00306
00307 arg_list.resize (len + 1);
00308
00309 arg_list[0] = exec_file;
00310
00311 for (int i = 0; i < len; i++)
00312 arg_list[i+1] = tmp[i];
00313 }
00314 else
00315 error ("popen2: arguments must be character strings");
00316 }
00317 else
00318 {
00319 arg_list.resize (1);
00320
00321 arg_list[0] = exec_file;
00322 }
00323
00324 if (! error_state)
00325 {
00326 bool sync_mode = (nargin == 3 ? args(2).bool_value() : false);
00327
00328 if (! error_state)
00329 {
00330 int fildes[2];
00331 std::string msg;
00332 pid_t pid;
00333
00334 pid = octave_syscalls::popen2 (exec_file, arg_list, sync_mode, fildes, msg, interactive);
00335 if (pid >= 0)
00336 {
00337 FILE *ifile = fdopen (fildes[1], "r");
00338 FILE *ofile = fdopen (fildes[0], "w");
00339
00340 std::string nm;
00341
00342 octave_stream is = octave_stdiostream::create (nm, ifile,
00343 std::ios::in);
00344
00345 octave_stream os = octave_stdiostream::create (nm, ofile,
00346 std::ios::out);
00347
00348 Cell file_ids (1, 2);
00349
00350 retval(2) = pid;
00351 retval(1) = octave_stream_list::insert (is);
00352 retval(0) = octave_stream_list::insert (os);
00353 }
00354 else
00355 error (msg.c_str ());
00356 }
00357 }
00358 else
00359 error ("popen2: arguments must be character strings");
00360 }
00361 else
00362 error ("popen2: COMMAND argument must be a string");
00363 }
00364 else
00365 print_usage ();
00366
00367 return retval;
00368 }
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 DEFUNX ("fcntl", Ffcntl, args, ,
00414 "-*- texinfo -*-\n\
00415 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} fcntl (@var{fid}, @var{request}, @var{arg})\n\
00416 Change the properties of the open file @var{fid}. The following values\n\
00417 may be passed as @var{request}:\n\
00418 \n\
00419 @vtable @code\n\
00420 @item F_DUPFD\n\
00421 Return a duplicate file descriptor.\n\
00422 \n\
00423 @item F_GETFD\n\
00424 Return the file descriptor flags for @var{fid}.\n\
00425 \n\
00426 @item F_SETFD\n\
00427 Set the file descriptor flags for @var{fid}.\n\
00428 \n\
00429 @item F_GETFL\n\
00430 Return the file status flags for @var{fid}. The following codes may be\n\
00431 returned (some of the flags may be undefined on some systems).\n\
00432 \n\
00433 @vtable @code\n\
00434 @item O_RDONLY\n\
00435 Open for reading only.\n\
00436 \n\
00437 @item O_WRONLY\n\
00438 Open for writing only.\n\
00439 \n\
00440 @item O_RDWR\n\
00441 Open for reading and writing.\n\
00442 \n\
00443 @item O_APPEND\n\
00444 Append on each write.\n\
00445 \n\
00446 @item O_CREAT\n\
00447 Create the file if it does not exist.\n\
00448 \n\
00449 @item O_NONBLOCK\n\
00450 Non-blocking mode.\n\
00451 \n\
00452 @item O_SYNC\n\
00453 Wait for writes to complete.\n\
00454 \n\
00455 @item O_ASYNC\n\
00456 Asynchronous I/O.\n\
00457 @end vtable\n\
00458 \n\
00459 @item F_SETFL\n\
00460 Set the file status flags for @var{fid} to the value specified by\n\
00461 @var{arg}. The only flags that can be changed are @w{@code{O_APPEND}} and\n\
00462 @w{@code{O_NONBLOCK}}.\n\
00463 @end vtable\n\
00464 \n\
00465 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
00466 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
00467 system-dependent error message.\n\
00468 @end deftypefn")
00469 {
00470 octave_value_list retval;
00471
00472 retval(1) = std::string ();
00473 retval(0) = -1;
00474
00475 int nargin = args.length ();
00476
00477 if (nargin == 3)
00478 {
00479 octave_stream strm = octave_stream_list::lookup (args (0), "fcntl");
00480
00481 if (! error_state)
00482 {
00483 int fid = strm.file_number ();
00484
00485 int req = args(1).int_value (true);
00486 int arg = args(2).int_value (true);
00487
00488 if (! error_state)
00489 {
00490
00491 if (fid < 0)
00492 error ("fcntl: invalid file id");
00493 else
00494 {
00495 std::string msg;
00496
00497 int status = octave_fcntl (fid, req, arg, msg);
00498
00499 retval(1) = msg;
00500 retval(0) = status;
00501 }
00502 }
00503 }
00504 else
00505 error ("fcntl: FID, REQUEST, and ARG must be integers");
00506 }
00507 else
00508 print_usage ();
00509
00510 return retval;
00511 }
00512
00513 DEFUNX ("fork", Ffork, args, ,
00514 "-*- texinfo -*-\n\
00515 @deftypefn {Built-in Function} {[@var{pid}, @var{msg}] =} fork ()\n\
00516 Create a copy of the current process.\n\
00517 \n\
00518 Fork can return one of the following values:\n\
00519 \n\
00520 @table @asis\n\
00521 @item > 0\n\
00522 You are in the parent process. The value returned from @code{fork} is\n\
00523 the process id of the child process. You should probably arrange to\n\
00524 wait for any child processes to exit.\n\
00525 \n\
00526 @item 0\n\
00527 You are in the child process. You can call @code{exec} to start another\n\
00528 process. If that fails, you should probably call @code{exit}.\n\
00529 \n\
00530 @item < 0\n\
00531 The call to @code{fork} failed for some reason. You must take evasive\n\
00532 action. A system dependent error message will be waiting in @var{msg}.\n\
00533 @end table\n\
00534 @end deftypefn")
00535 {
00536 octave_value_list retval;
00537
00538 retval(1) = std::string ();
00539 retval(0) = -1;
00540
00541 int nargin = args.length ();
00542
00543 if (nargin == 0)
00544 {
00545 std::string msg;
00546
00547 pid_t pid = octave_syscalls::fork (msg);
00548
00549 retval(1) = msg;
00550 retval(0) = pid;
00551 }
00552 else
00553 print_usage ();
00554
00555 return retval;
00556 }
00557
00558 DEFUNX ("getpgrp", Fgetpgrp, args, ,
00559 "-*- texinfo -*-\n\
00560 @deftypefn {Built-in Function} {pgid =} getpgrp ()\n\
00561 Return the process group id of the current process.\n\
00562 @end deftypefn")
00563 {
00564 octave_value_list retval;
00565
00566 retval(1) = std::string ();
00567 retval(0) = -1;
00568
00569 int nargin = args.length ();
00570
00571 if (nargin == 0)
00572 {
00573 std::string msg;
00574
00575 retval(1) = msg;
00576 retval(0) = octave_syscalls::getpgrp (msg);
00577 }
00578 else
00579 print_usage ();
00580
00581 return retval;
00582 }
00583
00584 DEFUNX ("getpid", Fgetpid, args, ,
00585 "-*- texinfo -*-\n\
00586 @deftypefn {Built-in Function} {pid =} getpid ()\n\
00587 Return the process id of the current process.\n\
00588 @end deftypefn")
00589 {
00590 octave_value retval = -1;
00591
00592 int nargin = args.length ();
00593
00594 if (nargin == 0)
00595 retval = octave_syscalls::getpid ();
00596 else
00597 print_usage ();
00598
00599 return retval;
00600 }
00601
00602 DEFUNX ("getppid", Fgetppid, args, ,
00603 "-*- texinfo -*-\n\
00604 @deftypefn {Built-in Function} {pid =} getppid ()\n\
00605 Return the process id of the parent process.\n\
00606 @end deftypefn")
00607 {
00608 octave_value retval = -1;
00609
00610 int nargin = args.length ();
00611
00612 if (nargin == 0)
00613 retval = octave_syscalls::getppid ();
00614 else
00615 print_usage ();
00616
00617 return retval;
00618 }
00619
00620 DEFUNX ("getegid", Fgetegid, args, ,
00621 "-*- texinfo -*-\n\
00622 @deftypefn {Built-in Function} {egid =} getegid ()\n\
00623 Return the effective group id of the current process.\n\
00624 @end deftypefn")
00625 {
00626 octave_value retval = -1;
00627
00628 int nargin = args.length ();
00629
00630 if (nargin == 0)
00631 retval = octave_syscalls::getegid ();
00632 else
00633 print_usage ();
00634
00635 return retval;
00636 }
00637
00638 DEFUNX ("getgid", Fgetgid, args, ,
00639 "-*- texinfo -*-\n\
00640 @deftypefn {Built-in Function} {gid =} getgid ()\n\
00641 Return the real group id of the current process.\n\
00642 @end deftypefn")
00643 {
00644 octave_value retval = -1;
00645
00646 int nargin = args.length ();
00647
00648 if (nargin == 0)
00649 retval = octave_syscalls::getgid ();
00650 else
00651 print_usage ();
00652
00653 return retval;
00654 }
00655
00656 DEFUNX ("geteuid", Fgeteuid, args, ,
00657 "-*- texinfo -*-\n\
00658 @deftypefn {Built-in Function} {euid =} geteuid ()\n\
00659 Return the effective user id of the current process.\n\
00660 @end deftypefn")
00661 {
00662 octave_value retval = -1;
00663
00664 int nargin = args.length ();
00665
00666 if (nargin == 0)
00667 retval = octave_syscalls::geteuid ();
00668 else
00669 print_usage ();
00670
00671 return retval;
00672 }
00673
00674 DEFUNX ("getuid", Fgetuid, args, ,
00675 "-*- texinfo -*-\n\
00676 @deftypefn {Built-in Function} {uid =} getuid ()\n\
00677 Return the real user id of the current process.\n\
00678 @end deftypefn")
00679 {
00680 octave_value retval = -1;
00681
00682 int nargin = args.length ();
00683
00684 if (nargin == 0)
00685 retval = octave_syscalls::getuid ();
00686 else
00687 print_usage ();
00688
00689 return retval;
00690 }
00691
00692 DEFUNX ("kill", Fkill, args, ,
00693 "-*- texinfo -*-\n\
00694 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} kill (@var{pid}, @var{sig})\n\
00695 Send signal @var{sig} to process @var{pid}.\n\
00696 \n\
00697 If @var{pid} is positive, then signal @var{sig} is sent to @var{pid}.\n\
00698 \n\
00699 If @var{pid} is 0, then signal @var{sig} is sent to every process\n\
00700 in the process group of the current process.\n\
00701 \n\
00702 If @var{pid} is -1, then signal @var{sig} is sent to every process\n\
00703 except process 1.\n\
00704 \n\
00705 If @var{pid} is less than -1, then signal @var{sig} is sent to every\n\
00706 process in the process group @var{-pid}.\n\
00707 \n\
00708 If @var{sig} is 0, then no signal is sent, but error checking is still\n\
00709 performed.\n\
00710 \n\
00711 Return 0 if successful, otherwise return -1.\n\
00712 @end deftypefn")
00713 {
00714 octave_value_list retval;
00715
00716 retval(1) = std::string ();
00717 retval(0) = -1;
00718
00719 if (args.length () == 2)
00720 {
00721 pid_t pid = args(0).int_value (true);
00722
00723 if (! error_state)
00724 {
00725 int sig = args(1).int_value (true);
00726
00727 if (! error_state)
00728 {
00729 std::string msg;
00730
00731 int status = octave_syscalls::kill (pid, sig, msg);
00732
00733 retval(1) = msg;
00734 retval(0) = status;
00735 }
00736 }
00737 }
00738 else
00739 print_usage ();
00740
00741 return retval;
00742 }
00743
00744 DEFUNX ("lstat", Flstat, args, ,
00745 "-*- texinfo -*-\n\
00746 @deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{symlink})\n\
00747 Return a structure @var{info} containing information about the symbolic link\n\
00748 @var{symlink}. The function outputs are described in the documentation for\n\
00749 @code{stat}.\n\
00750 @seealso{stat}\n\
00751 @end deftypefn")
00752 {
00753 octave_value_list retval;
00754
00755 if (args.length () == 1)
00756 {
00757 std::string fname = args(0).string_value ();
00758
00759 if (! error_state)
00760 {
00761 file_stat fs (fname, false);
00762
00763 retval = mk_stat_result (fs);
00764 }
00765 }
00766 else
00767 print_usage ();
00768
00769 return retval;
00770 }
00771
00772 DEFUNX ("mkfifo", Fmkfifo, args, ,
00773 "-*- texinfo -*-\n\
00774 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} mkfifo (@var{name}, @var{mode})\n\
00775 Create a @var{fifo} special file named @var{name} with file mode @var{mode}\n\
00776 \n\
00777 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
00778 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
00779 system-dependent error message.\n\
00780 @end deftypefn")
00781 {
00782 octave_value_list retval;
00783
00784 retval(1) = std::string ();
00785 retval(0) = -1;
00786
00787 int nargin = args.length ();
00788
00789 if (nargin == 2)
00790 {
00791 if (args(0).is_string ())
00792 {
00793 std::string name = args(0).string_value ();
00794
00795 if (args(1).is_scalar_type ())
00796 {
00797 long mode = args(1).long_value ();
00798
00799 if (! error_state)
00800 {
00801 std::string msg;
00802
00803 int status = octave_mkfifo (name, mode, msg);
00804
00805 retval(0) = status;
00806
00807 if (status < 0)
00808 retval(1) = msg;
00809 }
00810 else
00811 error ("mkfifo: invalid MODE");
00812 }
00813 else
00814 error ("mkfifo: MODE must be an integer");
00815 }
00816 else
00817 error ("mkfifo: FILE must be a string");
00818 }
00819 else
00820 print_usage ();
00821
00822 return retval;
00823 }
00824
00825 DEFUNX ("pipe", Fpipe, args, ,
00826 "-*- texinfo -*-\n\
00827 @deftypefn {Built-in Function} {[@var{read_fd}, @var{write_fd}, @var{err}, @var{msg}] =} pipe ()\n\
00828 Create a pipe and return the reading and writing ends of the pipe\n\
00829 into @var{read_fd} and @var{write_fd} respectively.\n\
00830 \n\
00831 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
00832 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
00833 system-dependent error message.\n\
00834 @end deftypefn")
00835 {
00836 octave_value_list retval;
00837
00838 retval(3) = std::string ();
00839 retval(2) = -1;
00840 retval(1) = -1;
00841 retval(0) = -1;
00842
00843 int nargin = args.length ();
00844
00845 if (nargin == 0)
00846 {
00847 int fid[2];
00848
00849 std::string msg;
00850
00851 int status = octave_syscalls::pipe (fid, msg);
00852
00853 if (status < 0)
00854 retval(3) = msg;
00855 else
00856 {
00857 FILE *ifile = fdopen (fid[0], "r");
00858 FILE *ofile = fdopen (fid[1], "w");
00859
00860 std::string nm;
00861
00862 octave_stream is = octave_stdiostream::create (nm, ifile,
00863 std::ios::in);
00864
00865 octave_stream os = octave_stdiostream::create (nm, ofile,
00866 std::ios::out);
00867
00868 retval(2) = status;
00869 retval(1) = octave_stream_list::insert (os);
00870 retval(0) = octave_stream_list::insert (is);
00871 }
00872 }
00873 else
00874 print_usage ();
00875
00876 return retval;
00877 }
00878
00879 DEFUNX ("stat", Fstat, args, ,
00880 "-*- texinfo -*-\n\
00881 @deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} stat (@var{file})\n\
00882 @deftypefnx {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} stat (@var{fid})\n\
00883 @deftypefnx {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{file})\n\
00884 @deftypefnx {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{fid})\n\
00885 Return a structure @var{info} containing the following information about\n\
00886 @var{file} or file identifier @var{fid}.\n\
00887 \n\
00888 @table @code\n\
00889 @item dev\n\
00890 ID of device containing a directory entry for this file.\n\
00891 \n\
00892 @item ino\n\
00893 File number of the file.\n\
00894 \n\
00895 @item mode\n\
00896 File mode, as an integer. Use the functions @w{@code{S_ISREG}},\n\
00897 @w{@code{S_ISDIR}}, @w{@code{S_ISCHR}}, @w{@code{S_ISBLK}}, @w{@code{S_ISFIFO}},\n\
00898 @w{@code{S_ISLNK}}, or @w{@code{S_ISSOCK}} to extract information from this\n\
00899 value.\n\
00900 \n\
00901 @item modestr\n\
00902 File mode, as a string of ten letters or dashes as would be returned by\n\
00903 @kbd{ls -l}.\n\
00904 \n\
00905 @item nlink\n\
00906 Number of links.\n\
00907 \n\
00908 @item uid\n\
00909 User ID of file's owner.\n\
00910 \n\
00911 @item gid\n\
00912 Group ID of file's group.\n\
00913 \n\
00914 @item rdev\n\
00915 ID of device for block or character special files.\n\
00916 \n\
00917 @item size\n\
00918 Size in bytes.\n\
00919 \n\
00920 @item atime\n\
00921 Time of last access in the same form as time values returned from\n\
00922 @code{time}. @xref{Timing Utilities}.\n\
00923 \n\
00924 @item mtime\n\
00925 Time of last modification in the same form as time values returned from\n\
00926 @code{time}. @xref{Timing Utilities}.\n\
00927 \n\
00928 @item ctime\n\
00929 Time of last file status change in the same form as time values\n\
00930 returned from @code{time}. @xref{Timing Utilities}.\n\
00931 \n\
00932 @item blksize\n\
00933 Size of blocks in the file.\n\
00934 \n\
00935 @item blocks\n\
00936 Number of blocks allocated for file.\n\
00937 @end table\n\
00938 \n\
00939 If the call is successful @var{err} is 0 and @var{msg} is an empty\n\
00940 string. If the file does not exist, or some other error occurs, @var{s}\n\
00941 is an empty matrix, @var{err} is @minus{}1, and @var{msg} contains the\n\
00942 corresponding system error message.\n\
00943 \n\
00944 If @var{file} is a symbolic link, @code{stat} will return information\n\
00945 about the actual file that is referenced by the link. Use @code{lstat}\n\
00946 if you want information about the symbolic link itself.\n\
00947 \n\
00948 For example:\n\
00949 \n\
00950 @example\n\
00951 [s, err, msg] = stat (\"/vmlinuz\")\n\
00952 @result{} s =\n\
00953 @{\n\
00954 atime = 855399756\n\
00955 rdev = 0\n\
00956 ctime = 847219094\n\
00957 uid = 0\n\
00958 size = 389218\n\
00959 blksize = 4096\n\
00960 mtime = 847219094\n\
00961 gid = 6\n\
00962 nlink = 1\n\
00963 blocks = 768\n\
00964 mode = -rw-r--r--\n\
00965 modestr = -rw-r--r--\n\
00966 ino = 9316\n\
00967 dev = 2049\n\
00968 @}\n\
00969 @result{} err = 0\n\
00970 @result{} msg =\n\
00971 @end example\n\
00972 @end deftypefn")
00973 {
00974 octave_value_list retval;
00975
00976 if (args.length () == 1)
00977 {
00978 if (args(0).is_scalar_type ())
00979 {
00980 int fid = octave_stream_list::get_file_number (args(0));
00981
00982 if (! error_state)
00983 {
00984 file_fstat fs (fid);
00985
00986 retval = mk_stat_result (fs);
00987 }
00988 }
00989 else
00990 {
00991 std::string fname = args(0).string_value ();
00992
00993 if (! error_state)
00994 {
00995 file_stat fs (fname);
00996
00997 retval = mk_stat_result (fs);
00998 }
00999 }
01000 }
01001 else
01002 print_usage ();
01003
01004 return retval;
01005 }
01006
01007 DEFUNX ("S_ISREG", FS_ISREG, args, ,
01008 "-*- texinfo -*-\n\
01009 @deftypefn {Built-in Function} {} S_ISREG (@var{mode})\n\
01010 Return true if @var{mode} corresponds to a regular file. The value\n\
01011 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
01012 @seealso{stat, lstat}\n\
01013 @end deftypefn")
01014 {
01015 octave_value retval = false;
01016
01017 if (args.length () == 1)
01018 {
01019 double mode = args(0).double_value ();
01020
01021 if (! error_state)
01022 retval = file_stat::is_reg (static_cast<mode_t> (mode));
01023 else
01024 error ("S_ISREG: invalid MODE value");
01025 }
01026 else
01027 print_usage ();
01028
01029 return retval;
01030 }
01031
01032 DEFUNX ("S_ISDIR", FS_ISDIR, args, ,
01033 "-*- texinfo -*-\n\
01034 @deftypefn {Built-in Function} {} S_ISDIR (@var{mode})\n\
01035 Return true if @var{mode} corresponds to a directory. The value\n\
01036 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
01037 @seealso{stat, lstat}\n\
01038 @end deftypefn")
01039 {
01040 octave_value retval = false;
01041
01042 if (args.length () == 1)
01043 {
01044 double mode = args(0).double_value ();
01045
01046 if (! error_state)
01047 retval = file_stat::is_dir (static_cast<mode_t> (mode));
01048 else
01049 error ("S_ISDIR: invalid MODE value");
01050 }
01051 else
01052 print_usage ();
01053
01054 return retval;
01055 }
01056
01057 DEFUNX ("S_ISCHR", FS_ISCHR, args, ,
01058 "-*- texinfo -*-\n\
01059 @deftypefn {Built-in Function} {} S_ISCHR (@var{mode})\n\
01060 Return true if @var{mode} corresponds to a character device. The value\n\
01061 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
01062 @seealso{stat, lstat}\n\
01063 @end deftypefn")
01064 {
01065 octave_value retval = false;
01066
01067 if (args.length () == 1)
01068 {
01069 double mode = args(0).double_value ();
01070
01071 if (! error_state)
01072 retval = file_stat::is_chr (static_cast<mode_t> (mode));
01073 else
01074 error ("S_ISCHR: invalid MODE value");
01075 }
01076 else
01077 print_usage ();
01078
01079 return retval;
01080 }
01081
01082 DEFUNX ("S_ISBLK", FS_ISBLK, args, ,
01083 "-*- texinfo -*-\n\
01084 @deftypefn {Built-in Function} {} S_ISBLK (@var{mode})\n\
01085 Return true if @var{mode} corresponds to a block device. The value\n\
01086 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
01087 @seealso{stat, lstat}\n\
01088 @end deftypefn")
01089 {
01090 octave_value retval = false;
01091
01092 if (args.length () == 1)
01093 {
01094 double mode = args(0).double_value ();
01095
01096 if (! error_state)
01097 retval = file_stat::is_blk (static_cast<mode_t> (mode));
01098 else
01099 error ("S_ISBLK: invalid MODE value");
01100 }
01101 else
01102 print_usage ();
01103
01104 return retval;
01105 }
01106
01107 DEFUNX ("S_ISFIFO", FS_ISFIFO, args, ,
01108 "-*- texinfo -*-\n\
01109 @deftypefn {Built-in Function} {} S_ISFIFO (@var{mode})\n\
01110 Return true if @var{mode} corresponds to a fifo. The value\n\
01111 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
01112 @seealso{stat, lstat}\n\
01113 @end deftypefn")
01114 {
01115 octave_value retval = false;
01116
01117 if (args.length () == 1)
01118 {
01119 double mode = args(0).double_value ();
01120
01121 if (! error_state)
01122 retval = file_stat::is_fifo (static_cast<mode_t> (mode));
01123 else
01124 error ("S_ISFIFO: invalid MODE value");
01125 }
01126 else
01127 print_usage ();
01128
01129 return retval;
01130 }
01131
01132 DEFUNX ("S_ISLNK", FS_ISLNK, args, ,
01133 "-*- texinfo -*-\n\
01134 @deftypefn {Built-in Function} {} S_ISLNK (@var{mode})\n\
01135 Return true if @var{mode} corresponds to a symbolic link. The value\n\
01136 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
01137 @seealso{stat, lstat}\n\
01138 @end deftypefn")
01139 {
01140 octave_value retval = false;
01141
01142 if (args.length () == 1)
01143 {
01144 double mode = args(0).double_value ();
01145
01146 if (! error_state)
01147 retval = file_stat::is_lnk (static_cast<mode_t> (mode));
01148 else
01149 error ("S_ISLNK: invalid MODE value");
01150 }
01151 else
01152 print_usage ();
01153
01154 return retval;
01155 }
01156
01157 DEFUNX ("S_ISSOCK", FS_ISSOCK, args, ,
01158 "-*- texinfo -*-\n\
01159 @deftypefn {Built-in Function} {} S_ISSOCK (@var{mode})\n\
01160 Return true if @var{mode} corresponds to a socket. The value\n\
01161 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\
01162 @seealso{stat, lstat}\n\
01163 @end deftypefn")
01164 {
01165 octave_value retval = false;
01166
01167 if (args.length () == 1)
01168 {
01169 double mode = args(0).double_value ();
01170
01171 if (! error_state)
01172 retval = file_stat::is_sock (static_cast<mode_t> (mode));
01173 else
01174 error ("S_ISSOCK: invalid MODE value");
01175 }
01176 else
01177 print_usage ();
01178
01179 return retval;
01180 }
01181
01182 DEFUN (gethostname, args, ,
01183 "-*- texinfo -*-\n\
01184 @deftypefn {Built-in Function} {} gethostname ()\n\
01185 Return the hostname of the system where Octave is running.\n\
01186 @end deftypefn")
01187 {
01188 octave_value retval;
01189
01190 if (args.length () == 0)
01191 retval = octave_env::get_host_name ();
01192 else
01193 print_usage ();
01194
01195 return retval;
01196 }
01197
01198 DEFUN (uname, args, ,
01199 "-*- texinfo -*-\n\
01200 @deftypefn {Built-in Function} {[@var{uts}, @var{err}, @var{msg}] =} uname ()\n\
01201 Return system information in the structure. For example:\n\
01202 \n\
01203 @example\n\
01204 @group\n\
01205 uname ()\n\
01206 @result{} @{\n\
01207 sysname = x86_64\n\
01208 nodename = segfault\n\
01209 release = 2.6.15-1-amd64-k8-smp\n\
01210 version = Linux\n\
01211 machine = #2 SMP Thu Feb 23 04:57:49 UTC 2006\n\
01212 @}\n\
01213 @end group\n\
01214 @end example\n\
01215 \n\
01216 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
01217 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
01218 system-dependent error message.\n\
01219 @end deftypefn")
01220 {
01221 octave_value_list retval;
01222
01223 if (args.length () == 0)
01224 {
01225 octave_uname sysinfo;
01226
01227 octave_scalar_map m;
01228
01229 m.assign ("sysname", sysinfo.sysname ());
01230 m.assign ("nodename", sysinfo.nodename ());
01231 m.assign ("release", sysinfo.release ());
01232 m.assign ("version", sysinfo.version ());
01233 m.assign ("machine", sysinfo.machine ());
01234
01235 retval(2) = sysinfo.message ();
01236 retval(1) = sysinfo.error ();
01237 retval(0) = m;
01238 }
01239 else
01240 print_usage ();
01241
01242 return retval;
01243 }
01244
01245 DEFUNX ("unlink", Funlink, args, ,
01246 "-*- texinfo -*-\n\
01247 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} unlink (@var{file})\n\
01248 Delete the file named @var{file}.\n\
01249 \n\
01250 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
01251 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
01252 system-dependent error message.\n\
01253 @end deftypefn")
01254 {
01255 octave_value_list retval;
01256
01257 retval(1) = std::string ();
01258 retval(0) = -1;
01259
01260 int nargin = args.length ();
01261
01262 if (nargin == 1)
01263 {
01264 if (args(0).is_string ())
01265 {
01266 std::string name = args(0).string_value ();
01267
01268 std::string msg;
01269
01270 int status = octave_unlink (name, msg);
01271
01272 retval(1) = msg;
01273 retval(0) = status;
01274 }
01275 else
01276 error ("unlink: FILE must be a string");
01277 }
01278 else
01279 print_usage ();
01280
01281 return retval;
01282 }
01283
01284 DEFUNX ("waitpid", Fwaitpid, args, ,
01285 "-*- texinfo -*-\n\
01286 @deftypefn {Built-in Function} {[@var{pid}, @var{status}, @var{msg}] =} waitpid (@var{pid}, @var{options})\n\
01287 Wait for process @var{pid} to terminate. The @var{pid} argument can be:\n\
01288 \n\
01289 @table @asis\n\
01290 @item @minus{}1\n\
01291 Wait for any child process.\n\
01292 \n\
01293 @item 0\n\
01294 Wait for any child process whose process group ID is equal to that of\n\
01295 the Octave interpreter process.\n\
01296 \n\
01297 @item > 0\n\
01298 Wait for termination of the child process with ID @var{pid}.\n\
01299 @end table\n\
01300 \n\
01301 The @var{options} argument can be a bitwise OR of zero or more of\n\
01302 the following constants:\n\
01303 \n\
01304 @table @code\n\
01305 @item 0\n\
01306 Wait until signal is received or a child process exits (this is the\n\
01307 default if the @var{options} argument is missing).\n\
01308 \n\
01309 @item WNOHANG\n\
01310 Do not hang if status is not immediately available.\n\
01311 \n\
01312 @item WUNTRACED\n\
01313 Report the status of any child processes that are stopped, and whose\n\
01314 status has not yet been reported since they stopped.\n\
01315 \n\
01316 @item WCONTINUE\n\
01317 Return if a stopped child has been resumed by delivery of @code{SIGCONT}.\n\
01318 This value may not be meaningful on all systems.\n\
01319 @end table\n\
01320 \n\
01321 If the returned value of @var{pid} is greater than 0, it is the process\n\
01322 ID of the child process that exited. If an error occurs, @var{pid} will\n\
01323 be less than zero and @var{msg} will contain a system-dependent error\n\
01324 message. The value of @var{status} contains additional system-dependent\n\
01325 information about the subprocess that exited.\n\
01326 @seealso{WCONTINUE, WCOREDUMP, WEXITSTATUS, WIFCONTINUED, WIFSIGNALED, WIFSTOPPED, WNOHANG, WSTOPSIG, WTERMSIG, WUNTRACED}\n\
01327 @end deftypefn")
01328 {
01329 octave_value_list retval;
01330
01331 retval(2) = std::string ();
01332 retval(1) = 0;
01333 retval(0) = -1;
01334
01335 int nargin = args.length ();
01336
01337 if (nargin == 1 || nargin == 2)
01338 {
01339 pid_t pid = args(0).int_value (true);
01340
01341 if (! error_state)
01342 {
01343 int options = 0;
01344
01345 if (args.length () == 2)
01346 options = args(1).int_value (true);
01347
01348 if (! error_state)
01349 {
01350 std::string msg;
01351
01352 int status = 0;
01353
01354 pid_t result = octave_syscalls::waitpid (pid, &status, options, msg);
01355
01356 retval(2) = msg;
01357 retval(1) = status;
01358 retval(0) = result;
01359 }
01360 else
01361 error ("waitpid: OPTIONS must be an integer");
01362 }
01363 else
01364 error ("waitpid: PID must be an integer value");
01365 }
01366 else
01367 print_usage ();
01368
01369 return retval;
01370 }
01371
01372 DEFUNX ("WIFEXITED", FWIFEXITED, args, ,
01373 "-*- texinfo -*-\n\
01374 @deftypefn {Built-in Function} {} WIFEXITED (@var{status})\n\
01375 Given @var{status} from a call to @code{waitpid}, return true if the\n\
01376 child terminated normally.\n\
01377 @seealso{waitpid, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\
01378 @end deftypefn")
01379 {
01380 octave_value retval = 0.0;
01381
01382 #if defined (WIFEXITED)
01383 if (args.length () == 1)
01384 {
01385 int status = args(0).int_value ();
01386
01387 if (! error_state)
01388 retval = WIFEXITED (status);
01389 else
01390 error ("WIFEXITED: STATUS must be an integer");
01391 }
01392 #else
01393 warning ("WIFEXITED always returns false in this version of Octave");
01394 #endif
01395
01396 return retval;
01397 }
01398
01399 DEFUNX ("WEXITSTATUS", FWEXITSTATUS, args, ,
01400 "-*- texinfo -*-\n\
01401 @deftypefn {Built-in Function} {} WEXITSTATUS (@var{status})\n\
01402 Given @var{status} from a call to @code{waitpid}, return the exit\n\
01403 status of the child. This function should only be employed if\n\
01404 @code{WIFEXITED} returned true.\n\
01405 @seealso{waitpid, WIFEXITED, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\
01406 @end deftypefn")
01407 {
01408 octave_value retval = 0.0;
01409
01410 #if defined (WEXITSTATUS)
01411 if (args.length () == 1)
01412 {
01413 int status = args(0).int_value ();
01414
01415 if (! error_state)
01416 retval = WEXITSTATUS (status);
01417 else
01418 error ("WEXITSTATUS: STATUS must be an integer");
01419 }
01420 #else
01421 warning ("WEXITSTATUS always returns false in this version of Octave");
01422 #endif
01423
01424 return retval;
01425 }
01426
01427 DEFUNX ("WIFSIGNALED", FWIFSIGNALED, args, ,
01428 "-*- texinfo -*-\n\
01429 @deftypefn {Built-in Function} {} WIFSIGNALED (@var{status})\n\
01430 Given @var{status} from a call to @code{waitpid}, return true if the\n\
01431 child process was terminated by a signal.\n\
01432 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\
01433 @end deftypefn")
01434 {
01435 octave_value retval = 0.0;
01436
01437 #if defined (WIFSIGNALED)
01438 if (args.length () == 1)
01439 {
01440 int status = args(0).int_value ();
01441
01442 if (! error_state)
01443 retval = WIFSIGNALED (status);
01444 else
01445 error ("WIFSIGNALED: STATUS must be an integer");
01446 }
01447 #else
01448 warning ("WIFSIGNALED always returns false in this version of Octave");
01449 #endif
01450
01451 return retval;
01452 }
01453
01454 DEFUNX ("WTERMSIG", FWTERMSIG, args, ,
01455 "-*- texinfo -*-\n\
01456 @deftypefn {Built-in Function} {} WTERMSIG (@var{status})\n\
01457 Given @var{status} from a call to @code{waitpid}, return the number of\n\
01458 the signal that caused the child process to terminate. This function\n\
01459 should only be employed if @code{WIFSIGNALED} returned true.\n\
01460 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\
01461 @end deftypefn")
01462 {
01463 octave_value retval = 0.0;
01464
01465 #if defined (WTERMSIG)
01466 if (args.length () == 1)
01467 {
01468 int status = args(0).int_value ();
01469
01470 if (! error_state)
01471 retval = WTERMSIG (status);
01472 else
01473 error ("WTERMSIG: STATUS must be an integer");
01474 }
01475 #else
01476 warning ("WTERMSIG always returns false in this version of Octave");
01477 #endif
01478
01479 return retval;
01480 }
01481
01482 DEFUNX ("WCOREDUMP", FWCOREDUMP, args, ,
01483 "-*- texinfo -*-\n\
01484 @deftypefn {Built-in Function} {} WCOREDUMP (@var{status})\n\
01485 Given @var{status} from a call to @code{waitpid}, return true if the\n\
01486 child produced a core dump. This function should only be employed if\n\
01487 @code{WIFSIGNALED} returned true. The macro used to implement this\n\
01488 function is not specified in POSIX.1-2001 and is not available on some\n\
01489 Unix implementations (e.g., AIX, SunOS).\n\
01490 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\
01491 @end deftypefn")
01492 {
01493 octave_value retval = 0.0;
01494
01495 #if defined (WCOREDUMP)
01496 if (args.length () == 1)
01497 {
01498 int status = args(0).int_value ();
01499
01500 if (! error_state)
01501 retval = WCOREDUMP (status);
01502 else
01503 error ("WCOREDUMP: STATUS must be an integer");
01504 }
01505 #else
01506 warning ("WCOREDUMP always returns false in this version of Octave");
01507 #endif
01508
01509 return retval;
01510 }
01511
01512 DEFUNX ("WIFSTOPPED", FWIFSTOPPED, args, ,
01513 "-*- texinfo -*-\n\
01514 @deftypefn {Built-in Function} {} WIFSTOPPED (@var{status})\n\
01515 Given @var{status} from a call to @code{waitpid}, return true if the\n\
01516 child process was stopped by delivery of a signal; this is only\n\
01517 possible if the call was done using @code{WUNTRACED} or when the child\n\
01518 is being traced (see ptrace(2)).\n\
01519 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WSTOPSIG, WIFCONTINUED}\n\
01520 @end deftypefn")
01521 {
01522 octave_value retval = 0.0;
01523
01524 #if defined (WIFSTOPPED)
01525 if (args.length () == 1)
01526 {
01527 int status = args(0).int_value ();
01528
01529 if (! error_state)
01530 retval = WIFSTOPPED (status);
01531 else
01532 error ("WIFSTOPPED: STATUS must be an integer");
01533 }
01534 #else
01535 warning ("WIFSTOPPED always returns false in this version of Octave");
01536 #endif
01537
01538 return retval;
01539 }
01540
01541 DEFUNX ("WSTOPSIG", FWSTOPSIG, args, ,
01542 "-*- texinfo -*-\n\
01543 @deftypefn {Built-in Function} {} WSTOPSIG (@var{status})\n\
01544 Given @var{status} from a call to @code{waitpid}, return the number of\n\
01545 the signal which caused the child to stop. This function should only\n\
01546 be employed if @code{WIFSTOPPED} returned true.\n\
01547 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WIFCONTINUED}\n\
01548 @end deftypefn")
01549 {
01550 octave_value retval = 0.0;
01551
01552 #if defined (WSTOPSIG)
01553 if (args.length () == 1)
01554 {
01555 int status = args(0).int_value ();
01556
01557 if (! error_state)
01558 retval = WSTOPSIG (status);
01559 else
01560 error ("WSTOPSIG: STATUS must be an integer");
01561 }
01562 #else
01563 warning ("WSTOPSIG always returns false in this version of Octave");
01564 #endif
01565
01566 return retval;
01567 }
01568
01569 DEFUNX ("WIFCONTINUED", FWIFCONTINUED, args, ,
01570 "-*- texinfo -*-\n\
01571 @deftypefn {Built-in Function} {} WIFCONTINUED (@var{status})\n\
01572 Given @var{status} from a call to @code{waitpid}, return true if the\n\
01573 child process was resumed by delivery of @code{SIGCONT}.\n\
01574 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG}\n\
01575 @end deftypefn")
01576 {
01577 octave_value retval = 0.0;
01578
01579 #if defined (WIFCONTINUED)
01580 if (args.length () == 1)
01581 {
01582 int status = args(0).int_value ();
01583
01584 if (! error_state)
01585 retval = WIFCONTINUED (status);
01586 else
01587 error ("WIFCONTINUED: STATUS must be an integer");
01588 }
01589 #else
01590 warning ("WIFCONTINUED always returns false in this version of Octave");
01591 #endif
01592
01593 return retval;
01594 }
01595
01596 DEFUNX ("canonicalize_file_name", Fcanonicalize_file_name, args, ,
01597 "-*- texinfo -*-\n\
01598 @deftypefn {Built-in Function} {[@var{cname}, @var{status}, @var{msg}]} canonicalize_file_name (@var{name})\n\
01599 Return the canonical name of file @var{name}.\n\
01600 @end deftypefn")
01601 {
01602 octave_value_list retval;
01603
01604 if (args.length () == 1)
01605 {
01606 std::string name = args(0).string_value ();
01607
01608 if (! error_state)
01609 {
01610 std::string msg;
01611
01612 std::string result = octave_canonicalize_file_name (name, msg);
01613
01614 retval(2) = msg;
01615 retval(1) = msg.empty () ? 0 : -1;
01616 retval(0) = result;
01617 }
01618 else
01619 error ("canonicalize_file_name: NAME must be a character string");
01620 }
01621 else
01622 print_usage ();
01623
01624 return retval;
01625 }
01626
01627 static octave_value
01628 const_value (const octave_value_list& args, int val)
01629 {
01630 octave_value retval;
01631
01632 int nargin = args.length ();
01633
01634 if (nargin == 0)
01635 retval = val;
01636 else
01637 print_usage ();
01638
01639 return retval;
01640 }
01641
01642 #if !defined (O_NONBLOCK) && defined (O_NDELAY)
01643 #define O_NONBLOCK O_NDELAY
01644 #endif
01645
01646 DEFUNX ("F_DUPFD", FF_DUPFD, args, ,
01647 "-*- texinfo -*-\n\
01648 @deftypefn {Built-in Function} {} F_DUPFD ()\n\
01649 Return the numerical value to pass to @code{fcntl} to return a\n\
01650 duplicate file descriptor.\n\
01651 @seealso{fcntl, F_GETFD, F_GETFL, F_SETFD, F_SETFL}\n\
01652 @end deftypefn")
01653 {
01654 #if defined (F_DUPFD)
01655 return const_value (args, F_DUPFD);
01656 #else
01657 error ("F_DUPFD: not available on this system");
01658 return octave_value ();
01659 #endif
01660 }
01661
01662 DEFUNX ("F_GETFD", FF_GETFD, args, ,
01663 "-*- texinfo -*-\n\
01664 @deftypefn {Built-in Function} {} F_GETFD ()\n\
01665 Return the numerical value to pass to @code{fcntl} to return the\n\
01666 file descriptor flags.\n\
01667 @seealso{fcntl, F_DUPFD, F_GETFL, F_SETFD, F_SETFL}\n\
01668 @end deftypefn")
01669 {
01670 #if defined (F_GETFD)
01671 return const_value (args, F_GETFD);
01672 #else
01673 error ("F_GETFD: not available on this system");
01674 return octave_value ();
01675 #endif
01676 }
01677
01678 DEFUNX ("F_GETFL", FF_GETFL, args, ,
01679 "-*- texinfo -*-\n\
01680 @deftypefn {Built-in Function} {} F_GETFL ()\n\
01681 Return the numerical value to pass to @code{fcntl} to return the\n\
01682 file status flags.\n\
01683 @seealso{fcntl, F_DUPFD, F_GETFD, F_SETFD, F_SETFL}\n\
01684 @end deftypefn")
01685 {
01686 #if defined (F_GETFL)
01687 return const_value (args, F_GETFL);
01688 #else
01689 error ("F_GETFL: not available on this system");
01690 return octave_value ();
01691 #endif
01692 }
01693
01694 DEFUNX ("F_SETFD", FF_SETFD, args, ,
01695 "-*- texinfo -*-\n\
01696 @deftypefn {Built-in Function} {} F_SETFD ()\n\
01697 Return the numerical value to pass to @code{fcntl} to set the file\n\
01698 descriptor flags.\n\
01699 @seealso{fcntl, F_DUPFD, F_GETFD, F_GETFL, F_SETFL}\n\
01700 @end deftypefn")
01701 {
01702 #if defined (F_SETFD)
01703 return const_value (args, F_SETFD);
01704 #else
01705 error ("F_SETFD: not available on this system");
01706 return octave_value ();
01707 #endif
01708 }
01709
01710 DEFUNX ("F_SETFL", FF_SETFL, args, ,
01711 "-*- texinfo -*-\n\
01712 @deftypefn {Built-in Function} {} F_SETFL ()\n\
01713 Return the numerical value to pass to @code{fcntl} to set the file\n\
01714 status flags.\n\
01715 @seealso{fcntl, F_DUPFD, F_GETFD, F_GETFL, F_SETFD}\n\
01716 @end deftypefn")
01717 {
01718 #if defined (F_SETFL)
01719 return const_value (args, F_SETFL);
01720 #else
01721 error ("F_SETFL: not available on this system");
01722 return octave_value ();
01723 #endif
01724 }
01725
01726 DEFUNX ("O_APPEND", FO_APPEND, args, ,
01727 "-*- texinfo -*-\n\
01728 @deftypefn {Built-in Function} {} O_APPEND ()\n\
01729 Return the numerical value of the file status flag that may be\n\
01730 returned by @code{fcntl} to indicate each write operation appends,\n\
01731 or that may be passed to @code{fcntl} to set the write mode to append.\n\
01732 @seealso{fcntl, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\
01733 @end deftypefn")
01734 {
01735 #if defined (O_APPEND)
01736 return const_value (args, O_APPEND);
01737 #else
01738 error ("O_APPEND: not available on this system");
01739 return octave_value ();
01740 #endif
01741 }
01742
01743 DEFUNX ("O_ASYNC", FO_ASYNC, args, ,
01744 "-*- texinfo -*-\n\
01745 @deftypefn {Built-in Function} {} O_ASYNC ()\n\
01746 Return the numerical value of the file status flag that may be\n\
01747 returned by @code{fcntl} to indicate asynchronous I/O.\n\
01748 @seealso{fcntl, O_APPEND, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\
01749 @end deftypefn")
01750 {
01751 #if defined (O_ASYNC)
01752 return const_value (args, O_ASYNC);
01753 #else
01754 error ("O_ASYNC: not available on this system");
01755 return octave_value ();
01756 #endif
01757 }
01758
01759 DEFUNX ("O_CREAT", FO_CREAT, args, ,
01760 "-*- texinfo -*-\n\
01761 @deftypefn {Built-in Function} {} O_CREAT ()\n\
01762 Return the numerical value of the file status flag that may be\n\
01763 returned by @code{fcntl} to indicate that a file should be\n\
01764 created if it does not exist.\n\
01765 @seealso{fcntl, O_APPEND, O_ASYNC, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\
01766 @end deftypefn")
01767 {
01768 #if defined (O_CREAT)
01769 return const_value (args, O_CREAT);
01770 #else
01771 error ("O_CREAT: not available on this system");
01772 return octave_value ();
01773 #endif
01774 }
01775
01776 DEFUNX ("O_EXCL", FO_EXCL, args, ,
01777 "-*- texinfo -*-\n\
01778 @deftypefn {Built-in Function} {} O_EXCL ()\n\
01779 Return the numerical value of the file status flag that may be\n\
01780 returned by @code{fcntl} to indicate that file locking is used.\n\
01781 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\
01782 @end deftypefn")
01783 {
01784 #if defined (O_EXCL)
01785 return const_value (args, O_EXCL);
01786 #else
01787 error ("O_EXCL: not available on this system");
01788 return octave_value ();
01789 #endif
01790 }
01791
01792 DEFUNX ("O_NONBLOCK", FO_NONBLOCK, args, ,
01793 "-*- texinfo -*-\n\
01794 @deftypefn {Built-in Function} {} O_NONBLOCK ()\n\
01795 Return the numerical value of the file status flag that may be\n\
01796 returned by @code{fcntl} to indicate that non-blocking I/O is in use,\n\
01797 or that may be passsed to @code{fcntl} to set non-blocking I/O.\n\
01798 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\
01799 @end deftypefn")
01800 {
01801 #if defined (O_NONBLOCK)
01802 return const_value (args, O_NONBLOCK);
01803 #else
01804 error ("O_NONBLOCK: not available on this system");
01805 return octave_value ();
01806 #endif
01807 }
01808
01809 DEFUNX ("O_RDONLY", FO_RDONLY, args, ,
01810 "-*- texinfo -*-\n\
01811 @deftypefn {Built-in Function} {} O_RDONLY ()\n\
01812 Return the numerical value of the file status flag that may be\n\
01813 returned by @code{fcntl} to indicate that a file is open for\n\
01814 reading only.\n\
01815 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\
01816 @end deftypefn")
01817 {
01818 #if defined (O_RDONLY)
01819 return const_value (args, O_RDONLY);
01820 #else
01821 error ("O_RDONLY: not available on this system");
01822 return octave_value ();
01823 #endif
01824 }
01825
01826 DEFUNX ("O_RDWR", FO_RDWR, args, ,
01827 "-*- texinfo -*-\n\
01828 @deftypefn {Built-in Function} {} O_RDWR ()\n\
01829 Return the numerical value of the file status flag that may be\n\
01830 returned by @code{fcntl} to indicate that a file is open for both\n\
01831 reading and writing.\n\
01832 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_SYNC, O_TRUNC, O_WRONLY}\n\
01833 @end deftypefn")
01834 {
01835 #if defined (O_RDWR)
01836 return const_value (args, O_RDWR);
01837 #else
01838 error ("O_RDWR: not available on this system");
01839 return octave_value ();
01840 #endif
01841 }
01842
01843 DEFUNX ("O_SYNC", FO_SYNC, args, ,
01844 "-*- texinfo -*-\n\
01845 @deftypefn {Built-in Function} {} O_SYNC ()\n\
01846 Return the numerical value of the file status flag that may be\n\
01847 returned by @code{fcntl} to indicate that a file is open for\n\
01848 synchronous I/O.\n\
01849 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY}\n\
01850 @end deftypefn")
01851 {
01852 #if defined (O_SYNC)
01853 return const_value (args, O_SYNC);
01854 #else
01855 error ("O_SYNC: not available on this system");
01856 return octave_value ();
01857 #endif
01858 }
01859
01860 DEFUNX ("O_TRUNC", FO_TRUNC, args, ,
01861 "-*- texinfo -*-\n\
01862 @deftypefn {Built-in Function} O_TRUNC ()\n\
01863 Return the numerical value of the file status flag that may be\n\
01864 returned by @code{fcntl} to indicate that if file exists, it should\n\
01865 be truncated when writing.\n\
01866 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_WRONLY}\n\
01867 @end deftypefn")
01868 {
01869 #if defined (O_TRUNC)
01870 return const_value (args, O_TRUNC);
01871 #else
01872 error ("O_TRUNC: not available on this system");
01873 return octave_value ();
01874 #endif
01875 }
01876
01877 DEFUNX ("O_WRONLY", FO_WRONLY, args, ,
01878 "-*- texinfo -*-\n\
01879 @deftypefn {Built-in Function} {} O_WRONLY ()\n\
01880 Return the numerical value of the file status flag that may be\n\
01881 returned by @code{fcntl} to indicate that a file is open for\n\
01882 writing only.\n\
01883 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC}\n\
01884 @end deftypefn")
01885 {
01886 #if defined (O_WRONLY)
01887 return const_value (args, O_WRONLY);
01888 #else
01889 error ("O_WRONLY: not available on this system");
01890 return octave_value ();
01891 #endif
01892 }
01893
01894 #if !defined (WNOHANG)
01895 #define WNOHANG 0
01896 #endif
01897
01898 DEFUNX ("WNOHANG", FWNOHANG, args, ,
01899 "-*- texinfo -*-\n\
01900 @deftypefn {Built-in Function} {} WNOHANG ()\n\
01901 Return the numerical value of the option argument that may be\n\
01902 passed to @code{waitpid} to indicate that it should return its\n\
01903 status immediately instead of waiting for a process to exit.\n\
01904 @seealso{waitpid, WUNTRACED, WCONTINUE}\n\
01905 @end deftypefn")
01906 {
01907 return const_value (args, WNOHANG);
01908 }
01909
01910 #if !defined (WUNTRACED)
01911 #define WUNTRACED 0
01912 #endif
01913
01914 DEFUNX ("WUNTRACED", FWUNTRACED, args, ,
01915 "-*- texinfo -*-\n\
01916 @deftypefn {Built-in Function} {} WUNTRACED ()\n\
01917 Return the numerical value of the option argument that may be\n\
01918 passed to @code{waitpid} to indicate that it should also return\n\
01919 if the child process has stopped but is not traced via the\n\
01920 @code{ptrace} system call\n\
01921 @seealso{waitpid, WNOHANG, WCONTINUE}\n\
01922 @end deftypefn")
01923 {
01924 return const_value (args, WUNTRACED);
01925 }
01926
01927 #if !defined (WCONTINUE)
01928 #define WCONTINUE 0
01929 #endif
01930
01931 DEFUNX ("WCONTINUE", FWCONTINUE, args, ,
01932 "-*- texinfo -*-\n\
01933 @deftypefn {Built-in Function} {} WCONTINUE ()\n\
01934 Return the numerical value of the option argument that may be\n\
01935 passed to @code{waitpid} to indicate that it should also return\n\
01936 if a stopped child has been resumed by delivery of a @code{SIGCONT}\n\
01937 signal.\n\
01938 @seealso{waitpid, WNOHANG, WUNTRACED}\n\
01939 @end deftypefn")
01940 {
01941 return const_value (args, WCONTINUE);
01942 }