Mercurial > hg > octave-lyh
annotate src/syscalls.cc @ 8946:e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
author | Benjamin Lindner <lindnerb@users.sourceforge.net> |
---|---|
date | Tue, 10 Mar 2009 01:01:50 -0400 |
parents | eb63fbe60fab |
children | 7c02ec148a3c |
rev | line source |
---|---|
2075 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, |
8920 | 4 2006, 2007, 2008, 2009 John W. Eaton |
2075 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2075 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2075 | 21 |
22 */ | |
23 | |
24 // Thomas Baier <baier@ci.tuwien.ac.at> added the original versions of | |
25 // the following functions: | |
26 // | |
27 // mkfifo unlink waitpid | |
28 | |
29 #ifdef HAVE_CONFIG_H | |
30 #include <config.h> | |
31 #endif | |
32 | |
33 #include <cstdio> | |
2669 | 34 #include <cstring> |
2075 | 35 |
36 #ifdef HAVE_UNISTD_H | |
2442 | 37 #ifdef HAVE_SYS_TYPES_H |
2075 | 38 #include <sys/types.h> |
2442 | 39 #endif |
2075 | 40 #include <unistd.h> |
41 #endif | |
42 | |
43 #ifdef HAVE_FCNTL_H | |
44 #include <fcntl.h> | |
45 #endif | |
46 | |
2926 | 47 #include "file-ops.h" |
48 #include "file-stat.h" | |
2937 | 49 #include "oct-syscalls.h" |
5547 | 50 #include "oct-uname.h" |
2926 | 51 |
2075 | 52 #include "defun.h" |
53 #include "error.h" | |
2078 | 54 #include "gripes.h" |
2075 | 55 #include "lo-utils.h" |
56 #include "oct-map.h" | |
57 #include "oct-obj.h" | |
58 #include "oct-stdstrm.h" | |
59 #include "oct-stream.h" | |
60 #include "sysdep.h" | |
61 #include "utils.h" | |
2366 | 62 #include "variables.h" |
6321 | 63 #include "input.h" |
2075 | 64 |
65 static Octave_map | |
8549 | 66 mk_stat_map (const base_file_stat& fs) |
2075 | 67 { |
68 Octave_map m; | |
69 | |
4675 | 70 m.assign ("dev", static_cast<double> (fs.dev ())); |
71 m.assign ("ino", fs.ino ()); | |
5476 | 72 m.assign ("mode", fs.mode ()); |
4675 | 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 ()); | |
3887 | 77 #if defined (HAVE_STRUCT_STAT_ST_RDEV) |
4675 | 78 m.assign ("rdev", static_cast<double> (fs.rdev ())); |
2075 | 79 #endif |
4675 | 80 m.assign ("size", fs.size ()); |
81 m.assign ("atime", fs.atime ()); | |
82 m.assign ("mtime", fs.mtime ()); | |
83 m.assign ("ctime", fs.ctime ()); | |
3887 | 84 #if defined (HAVE_STRUCT_STAT_ST_BLKSIZE) |
4675 | 85 m.assign ("blksize", fs.blksize ()); |
2075 | 86 #endif |
3887 | 87 #if defined (HAVE_STRUCT_STAT_ST_BLOCKS) |
4675 | 88 m.assign ("blocks", fs.blocks ()); |
2075 | 89 #endif |
90 | |
91 return m; | |
92 } | |
93 | |
2457 | 94 DEFUN (dup2, args, , |
3301 | 95 "-*- texinfo -*-\n\ |
96 @deftypefn {Built-in Function} {[@var{fid}, @var{msg}] =} dup2 (@var{old}, @var{new})\n\ | |
2669 | 97 Duplicate a file descriptor.\n\ |
98 \n\ | |
3301 | 99 If successful, @var{fid} is greater than zero and contains the new file\n\ |
100 ID. Otherwise, @var{fid} is negative and @var{msg} contains a\n\ | |
101 system-dependent error message.\n\ | |
102 @end deftypefn") | |
2075 | 103 { |
2669 | 104 octave_value_list retval; |
105 | |
3523 | 106 retval(1) = std::string (); |
4294 | 107 retval(0) = -1; |
2075 | 108 |
109 int nargin = args.length (); | |
110 | |
111 if (nargin == 2) | |
112 { | |
3341 | 113 octave_stream old_stream |
114 = octave_stream_list::lookup (args(0), "dup2"); | |
2075 | 115 |
3341 | 116 if (! error_state) |
2075 | 117 { |
3341 | 118 octave_stream new_stream |
119 = octave_stream_list::lookup (args(1), "dup2"); | |
2075 | 120 |
3341 | 121 if (! error_state) |
3145 | 122 { |
3341 | 123 int i_old = old_stream.file_number (); |
124 int i_new = new_stream.file_number (); | |
2937 | 125 |
3341 | 126 if (i_old >= 0 && i_new >= 0) |
127 { | |
3523 | 128 std::string msg; |
2669 | 129 |
3341 | 130 int status = octave_syscalls::dup2 (i_old, i_new, msg); |
131 | |
4233 | 132 retval(0) = status; |
3341 | 133 retval(1) = msg; |
134 } | |
2075 | 135 } |
136 } | |
3145 | 137 else |
138 error ("dup2: invalid stream"); | |
2075 | 139 } |
140 else | |
5823 | 141 print_usage (); |
2075 | 142 |
143 return retval; | |
144 } | |
145 | |
2457 | 146 DEFUN (exec, args, , |
3301 | 147 "-*- texinfo -*-\n\ |
148 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} exec (@var{file}, @var{args})\n\ | |
149 Replace current process with a new process. Calling @code{exec} without\n\ | |
150 first calling @code{fork} will terminate your current Octave process and\n\ | |
151 replace it with the program named by @var{file}. For example,\n\ | |
2669 | 152 \n\ |
3301 | 153 @example\n\ |
154 exec (\"ls\" \"-l\")\n\ | |
155 @end example\n\ | |
2669 | 156 \n\ |
3301 | 157 @noindent\n\ |
158 will run @code{ls} and return you to your shell prompt.\n\ | |
159 \n\ | |
160 If 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\ | |
162 error message.\n\ | |
163 @end deftypefn") | |
2075 | 164 { |
2669 | 165 octave_value_list retval; |
166 | |
3523 | 167 retval(1) = std::string (); |
4294 | 168 retval(0) = -1; |
2075 | 169 |
170 int nargin = args.length (); | |
171 | |
172 if (nargin == 1 || nargin == 2) | |
173 { | |
3523 | 174 std::string exec_file = args(0).string_value (); |
2075 | 175 |
176 if (! error_state) | |
177 { | |
2937 | 178 string_vector exec_args; |
2075 | 179 |
180 if (nargin == 2) | |
181 { | |
2937 | 182 string_vector tmp = args(1).all_strings (); |
2075 | 183 |
184 if (! error_state) | |
185 { | |
2937 | 186 int len = tmp.length (); |
2075 | 187 |
2937 | 188 exec_args.resize (len + 1); |
2075 | 189 |
2937 | 190 exec_args[0] = exec_file; |
2075 | 191 |
2937 | 192 for (int i = 0; i < len; i++) |
193 exec_args[i+1] = tmp[i]; | |
2075 | 194 } |
195 else | |
5138 | 196 error ("exec: arguments must be character strings"); |
2075 | 197 } |
198 else | |
199 { | |
2937 | 200 exec_args.resize (1); |
2075 | 201 |
2937 | 202 exec_args[0] = exec_file; |
2075 | 203 } |
204 | |
205 if (! error_state) | |
2669 | 206 { |
3523 | 207 std::string msg; |
2937 | 208 |
209 int status = octave_syscalls::execvp (exec_file, exec_args, msg); | |
2669 | 210 |
4233 | 211 retval(0) = status; |
2937 | 212 retval(1) = msg; |
2669 | 213 } |
2075 | 214 } |
215 else | |
216 error ("exec: first argument must be a string"); | |
217 } | |
218 else | |
5823 | 219 print_usage (); |
2075 | 220 |
221 return retval; | |
222 } | |
223 | |
6321 | 224 DEFUN (popen2, args, , |
225 "-*- texinfo -*-\n\ | |
6678 | 226 @deftypefn {Built-in Function} {[@var{in}, @var{out}, @var{pid}] =} popen2 (@var{command}, @var{args})\n\ |
6321 | 227 Start a subprocess with two-way communication. The name of the process\n\ |
228 is given by @var{command}, and @var{args} is an array of strings\n\ | |
229 containing options for the command. The file identifiers for the input\n\ | |
230 and 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\ | |
232 contains the process ID of the subprocess. Otherwise, @var{pid} is\n\ | |
233 @minus{}1.\n\ | |
234 \n\ | |
235 For example,\n\ | |
236 \n\ | |
237 @example\n\ | |
238 @group\n\ | |
6923 | 239 [in, out, pid] = popen2 (\"sort\", \"-r\");\n\ |
6321 | 240 fputs (in, \"these\\nare\\nsome\\nstrings\\n\");\n\ |
241 fclose (in);\n\ | |
242 EAGAIN = errno (\"EAGAIN\");\n\ | |
243 done = false;\n\ | |
244 do\n\ | |
245 s = fgets (out);\n\ | |
246 if (ischar (s))\n\ | |
247 fputs (stdout, s);\n\ | |
248 elseif (errno () == EAGAIN)\n\ | |
249 sleep (0.1);\n\ | |
250 fclear (out);\n\ | |
251 else\n\ | |
252 done = true;\n\ | |
253 endif\n\ | |
254 until (done)\n\ | |
255 fclose (out);\n\ | |
256 @print{} are\n\ | |
257 @print{} some\n\ | |
258 @print{} strings\n\ | |
259 @print{} these\n\ | |
260 @end group\n\ | |
261 @end example\n\ | |
262 @end deftypefn") | |
263 { | |
264 octave_value_list retval; | |
265 | |
266 retval(2) = -1; | |
267 retval(1) = Matrix (); | |
268 retval(0) = Matrix (); | |
269 | |
270 int nargin = args.length (); | |
271 | |
272 if (nargin >= 1 && nargin <= 3) | |
273 { | |
274 std::string exec_file = args(0).string_value(); | |
275 | |
276 if (! error_state) | |
277 { | |
278 string_vector arg_list; | |
279 | |
280 if (nargin >= 2) | |
281 { | |
282 string_vector tmp = args(1).all_strings (); | |
283 | |
284 if (! error_state) | |
285 { | |
286 int len = tmp.length (); | |
287 | |
288 arg_list.resize (len + 1); | |
289 | |
290 arg_list[0] = exec_file; | |
291 | |
292 for (int i = 0; i < len; i++) | |
293 arg_list[i+1] = tmp[i]; | |
294 } | |
295 else | |
296 error ("popen2: arguments must be character strings"); | |
297 } | |
298 else | |
299 { | |
300 arg_list.resize (1); | |
301 | |
302 arg_list[0] = exec_file; | |
303 } | |
304 | |
305 if (! error_state) | |
306 { | |
307 bool sync_mode = (nargin == 3 ? args(2).bool_value() : false); | |
308 | |
309 if (! error_state) | |
310 { | |
311 int fildes[2]; | |
312 std::string msg; | |
313 pid_t pid; | |
314 | |
315 pid = octave_syscalls::popen2 (exec_file, arg_list, sync_mode, fildes, msg, interactive); | |
316 if (pid >= 0) | |
317 { | |
318 FILE *ifile = fdopen (fildes[1], "r"); | |
319 FILE *ofile = fdopen (fildes[0], "w"); | |
320 | |
321 std::string nm; | |
322 | |
323 octave_stream is = octave_stdiostream::create (nm, ifile, | |
324 std::ios::in); | |
325 | |
326 octave_stream os = octave_stdiostream::create (nm, ofile, | |
327 std::ios::out); | |
328 | |
329 Cell file_ids (1, 2); | |
330 | |
331 retval(0) = octave_stream_list::insert (os); | |
332 retval(1) = octave_stream_list::insert (is); | |
333 retval(2) = pid; | |
334 } | |
335 else | |
336 error (msg.c_str ()); | |
337 } | |
338 } | |
339 else | |
340 error ("popen2: arguments must be character strings"); | |
341 } | |
342 else | |
343 error ("popen2: first argument must be a string"); | |
344 } | |
345 else | |
346 print_usage (); | |
347 | |
348 return retval; | |
349 } | |
350 | |
351 /* | |
352 | |
353 %!test | |
354 %! if (isunix()) | |
6923 | 355 %! [in, out, pid] = popen2 ("sort", "-r"); |
6321 | 356 %! EAGAIN = errno ("EAGAIN"); |
357 %! else | |
6322 | 358 %! [in, out, pid] = popen2 ("sort", "/R"); |
6321 | 359 %! EAGAIN = errno ("EINVAL"); |
360 %! endif | |
361 %! fputs (in, "these\nare\nsome\nstrings\n"); | |
362 %! fclose (in); | |
363 %! done = false; | |
364 %! str = {}; | |
365 %! idx = 0; | |
6545 | 366 %! errs = 0; |
6321 | 367 %! do |
368 %! if (!isunix()) | |
369 %! errno (0); | |
370 %! endif | |
371 %! s = fgets (out); | |
372 %! if (ischar (s)) | |
373 %! idx++; | |
374 %! str{idx} = s; | |
375 %! elseif (errno () == EAGAIN) | |
6543 | 376 %! fclear (out); |
6321 | 377 %! sleep (0.1); |
6545 | 378 %! if (++errs == 100) |
379 %! done = true; | |
380 %! endif | |
6321 | 381 %! else |
382 %! done = true; | |
383 %! endif | |
6545 | 384 %! until (done) |
6321 | 385 %! fclose (out); |
6324 | 386 %! if (isunix()) |
6322 | 387 %! assert(str,{"these\n","strings\n","some\n","are\n"}) |
388 %! else | |
389 %! assert(str,{"these\r\n","strings\r\n","some\r\n","are\r\n"}) | |
390 %! end | |
6321 | 391 |
392 */ | |
393 | |
2457 | 394 DEFUN (fcntl, args, , |
3301 | 395 "-*- texinfo -*-\n\ |
396 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} fcntl (@var{fid}, @var{request}, @var{arg})\n\ | |
397 Change the properties of the open file @var{fid}. The following values\n\ | |
398 may be passed as @var{request}:\n\ | |
399 \n\ | |
400 @vtable @code\n\ | |
401 @item F_DUPFD\n\ | |
402 Return a duplicate file descriptor.\n\ | |
403 \n\ | |
404 @item F_GETFD\n\ | |
405 Return the file descriptor flags for @var{fid}.\n\ | |
406 \n\ | |
407 @item F_SETFD\n\ | |
408 Set the file descriptor flags for @var{fid}.\n\ | |
409 \n\ | |
410 @item F_GETFL\n\ | |
411 Return the file status flags for @var{fid}. The following codes may be\n\ | |
412 returned (some of the flags may be undefined on some systems).\n\ | |
413 \n\ | |
414 @vtable @code\n\ | |
415 @item O_RDONLY\n\ | |
416 Open for reading only.\n\ | |
417 \n\ | |
418 @item O_WRONLY\n\ | |
419 Open for writing only.\n\ | |
2669 | 420 \n\ |
3301 | 421 @item O_RDWR\n\ |
422 Open for reading and writing.\n\ | |
423 \n\ | |
424 @item O_APPEND\n\ | |
425 Append on each write.\n\ | |
426 \n\ | |
5040 | 427 @item O_CREAT\n\ |
428 Create the file if it does not exist.\n\ | |
429 \n\ | |
3301 | 430 @item O_NONBLOCK\n\ |
431 Nonblocking mode.\n\ | |
432 \n\ | |
433 @item O_SYNC\n\ | |
434 Wait for writes to complete.\n\ | |
2669 | 435 \n\ |
3301 | 436 @item O_ASYNC\n\ |
437 Asynchronous I/O.\n\ | |
438 @end vtable\n\ | |
439 \n\ | |
440 @item F_SETFL\n\ | |
441 Set the file status flags for @var{fid} to the value specified by\n\ | |
442 @var{arg}. The only flags that can be changed are @code{O_APPEND} and\n\ | |
443 @code{O_NONBLOCK}.\n\ | |
444 @end vtable\n\ | |
445 \n\ | |
446 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ | |
447 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
448 system-dependent error message.\n\ | |
449 @end deftypefn") | |
2075 | 450 { |
2669 | 451 octave_value_list retval; |
452 | |
3523 | 453 retval(1) = std::string (); |
4294 | 454 retval(0) = -1; |
2075 | 455 |
456 int nargin = args.length (); | |
457 | |
458 if (nargin == 3) | |
459 { | |
3715 | 460 octave_stream strm = octave_stream_list::lookup (args (0), "fcntl"); |
2075 | 461 |
3202 | 462 if (! error_state) |
2075 | 463 { |
3715 | 464 int fid = strm.file_number (); |
465 | |
466 int req = args(1).int_value (true); | |
467 int arg = args(2).int_value (true); | |
468 | |
469 if (! error_state) | |
2669 | 470 { |
5775 | 471 // FIXME -- Need better checking here? |
3715 | 472 if (fid < 0) |
473 error ("fcntl: invalid file id"); | |
474 else | |
475 { | |
476 std::string msg; | |
2937 | 477 |
3715 | 478 int status = octave_syscalls::fcntl (fid, req, arg, msg); |
2669 | 479 |
4233 | 480 retval(0) = status; |
3715 | 481 retval(1) = msg; |
482 } | |
2669 | 483 } |
2075 | 484 } |
485 else | |
3202 | 486 error ("fcntl: file id, request, and argument must be integers"); |
2075 | 487 } |
488 else | |
5823 | 489 print_usage (); |
2075 | 490 |
491 return retval; | |
492 } | |
493 | |
2457 | 494 DEFUN (fork, args, , |
3301 | 495 "-*- texinfo -*-\n\ |
496 @deftypefn {Built-in Function} {[@var{pid}, @var{msg}] =} fork ()\n\ | |
2669 | 497 Create a copy of the current process.\n\ |
498 \n\ | |
3301 | 499 Fork can return one of the following values:\n\ |
500 \n\ | |
501 @table @asis\n\ | |
502 @item > 0\n\ | |
503 You are in the parent process. The value returned from @code{fork} is\n\ | |
504 the process id of the child process. You should probably arrange to\n\ | |
505 wait for any child processes to exit.\n\ | |
506 \n\ | |
507 @item 0\n\ | |
508 You are in the child process. You can call @code{exec} to start another\n\ | |
509 process. If that fails, you should probably call @code{exit}.\n\ | |
510 \n\ | |
511 @item < 0\n\ | |
512 The call to @code{fork} failed for some reason. You must take evasive\n\ | |
513 action. A system dependent error message will be waiting in @var{msg}.\n\ | |
514 @end table\n\ | |
515 @end deftypefn") | |
2075 | 516 { |
2669 | 517 octave_value_list retval; |
518 | |
3523 | 519 retval(1) = std::string (); |
4294 | 520 retval(0) = -1; |
2075 | 521 |
522 int nargin = args.length (); | |
523 | |
524 if (nargin == 0) | |
2475 | 525 { |
3523 | 526 std::string msg; |
2937 | 527 |
528 pid_t pid = octave_syscalls::fork (msg); | |
2669 | 529 |
4233 | 530 retval(0) = pid; |
2937 | 531 retval(1) = msg; |
2475 | 532 } |
2075 | 533 else |
5823 | 534 print_usage (); |
2075 | 535 |
536 return retval; | |
537 } | |
538 | |
2457 | 539 DEFUN (getpgrp, args, , |
3301 | 540 "-*- texinfo -*-\n\ |
541 @deftypefn {Built-in Function} {pgid =} getpgrp ()\n\ | |
542 Return the process group id of the current process.\n\ | |
543 @end deftypefn") | |
2075 | 544 { |
2937 | 545 octave_value_list retval; |
546 | |
3523 | 547 retval(1) = std::string (); |
4294 | 548 retval(0) = -1; |
2075 | 549 |
550 int nargin = args.length (); | |
551 | |
552 if (nargin == 0) | |
2475 | 553 { |
3523 | 554 std::string msg; |
2937 | 555 |
4233 | 556 retval(0) = octave_syscalls::getpgrp (msg); |
2937 | 557 retval(1) = msg; |
2475 | 558 } |
2075 | 559 else |
5823 | 560 print_usage (); |
2075 | 561 |
562 return retval; | |
563 } | |
564 | |
2457 | 565 DEFUN (getpid, args, , |
3301 | 566 "-*- texinfo -*-\n\ |
567 @deftypefn {Built-in Function} {pid =} getpid ()\n\ | |
568 Return the process id of the current process.\n\ | |
569 @end deftypefn") | |
2075 | 570 { |
4233 | 571 octave_value retval = -1; |
2075 | 572 |
573 int nargin = args.length (); | |
574 | |
575 if (nargin == 0) | |
2937 | 576 retval = octave_syscalls::getpid (); |
2075 | 577 else |
5823 | 578 print_usage (); |
2075 | 579 |
580 return retval; | |
581 } | |
582 | |
2457 | 583 DEFUN (getppid, args, , |
3301 | 584 "-*- texinfo -*-\n\ |
585 @deftypefn {Built-in Function} {pid =} getppid ()\n\ | |
586 Return the process id of the parent process.\n\ | |
587 @end deftypefn") | |
2075 | 588 { |
4233 | 589 octave_value retval = -1; |
2075 | 590 |
2475 | 591 int nargin = args.length (); |
592 | |
593 if (nargin == 0) | |
2937 | 594 retval = octave_syscalls::getppid (); |
2475 | 595 else |
5823 | 596 print_usage (); |
2475 | 597 |
598 return retval; | |
599 } | |
600 | |
601 DEFUN (getegid, args, , | |
3301 | 602 "-*- texinfo -*-\n\ |
603 @deftypefn {Built-in Function} {egid =} getegid ()\n\ | |
604 Return the effective group id of the current process.\n\ | |
605 @end deftypefn") | |
2475 | 606 { |
4233 | 607 octave_value retval = -1; |
2475 | 608 |
2075 | 609 int nargin = args.length (); |
610 | |
611 if (nargin == 0) | |
4254 | 612 retval = octave_syscalls::getegid (); |
2075 | 613 else |
5823 | 614 print_usage (); |
2475 | 615 |
616 return retval; | |
617 } | |
618 | |
619 DEFUN (getgid, args, , | |
3301 | 620 "-*- texinfo -*-\n\ |
621 @deftypefn {Built-in Function} {gid =} getgid ()\n\ | |
622 Return the real group id of the current process.\n\ | |
623 @end deftypefn") | |
2475 | 624 { |
4233 | 625 octave_value retval = -1; |
2475 | 626 |
627 int nargin = args.length (); | |
628 | |
629 if (nargin == 0) | |
4254 | 630 retval = octave_syscalls::getgid (); |
2475 | 631 else |
5823 | 632 print_usage (); |
2075 | 633 |
634 return retval; | |
635 } | |
636 | |
2473 | 637 DEFUN (geteuid, args, , |
3301 | 638 "-*- texinfo -*-\n\ |
639 @deftypefn {Built-in Function} {euid =} geteuid ()\n\ | |
640 Return the effective user id of the current process.\n\ | |
641 @end deftypefn") | |
2472 | 642 { |
4233 | 643 octave_value retval = -1; |
2472 | 644 |
645 int nargin = args.length (); | |
646 | |
647 if (nargin == 0) | |
4254 | 648 retval = octave_syscalls::geteuid (); |
2472 | 649 else |
5823 | 650 print_usage (); |
2473 | 651 |
652 return retval; | |
2472 | 653 } |
654 | |
2473 | 655 DEFUN (getuid, args, , |
3301 | 656 "-*- texinfo -*-\n\ |
657 @deftypefn {Built-in Function} {uid =} getuid ()\n\ | |
658 Return the real user id of the current process.\n\ | |
659 @end deftypefn") | |
2472 | 660 { |
4233 | 661 octave_value retval = -1; |
2472 | 662 |
663 int nargin = args.length (); | |
664 | |
665 if (nargin == 0) | |
4254 | 666 retval = octave_syscalls::getuid (); |
2472 | 667 else |
5823 | 668 print_usage (); |
2473 | 669 |
670 return retval; | |
2472 | 671 } |
672 | |
4294 | 673 DEFUN (kill, args, , |
4371 | 674 "-*- texinfo -*-\n\ |
4294 | 675 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} kill (@var{pid}, @var{sig})\n\ |
676 Send signal @var{sig} to process @var{pid}.\n\ | |
677 \n\ | |
678 If @var{pid} is positive, then signal @var{sig} is sent to @var{pid}.\n\ | |
679 \n\ | |
680 If @var{pid} is 0, then signal @var{sig} is sent to every process\n\ | |
681 in the process group of the current process.\n\ | |
682 \n\ | |
683 If @var{pid} is -1, then signal @var{sig} is sent to every process\n\ | |
684 except process 1.\n\ | |
685 \n\ | |
686 If @var{pid} is less than -1, then signal @var{sig} is sent to every\n\ | |
687 process in the process group @var{-pid}.\n\ | |
688 \n\ | |
4371 | 689 If @var{sig} is 0, then no signal is sent, but error checking is still\n\ |
4294 | 690 performed.\n\ |
691 \n\ | |
7001 | 692 Return 0 if successful, otherwise return -1.\n\ |
4294 | 693 @end deftypefn") |
694 { | |
695 octave_value_list retval; | |
696 | |
697 retval(1) = std::string (); | |
698 retval(0) = -1; | |
699 | |
700 if (args.length () == 2) | |
701 { | |
702 pid_t pid = args(0).int_value (true); | |
703 | |
704 if (! error_state) | |
705 { | |
706 int sig = args(1).int_value (true); | |
707 | |
708 if (! error_state) | |
709 { | |
710 std::string msg; | |
711 | |
712 int status = octave_syscalls::kill (pid, sig, msg); | |
713 | |
714 retval(1) = msg; | |
715 retval(0) = status; | |
716 } | |
717 } | |
718 } | |
719 else | |
5823 | 720 print_usage (); |
4294 | 721 |
722 return retval; | |
723 } | |
724 | |
8549 | 725 DEFUN (fstat, args, , |
726 "-*- texinfo -*-\n\ | |
727 @deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} fstat (@var{fid})\n\ | |
728 Return information about about the open file @var{fid}. See @code{stat}\n\ | |
729 for a description of the contents of @var{info}.\n\ | |
730 @end deftypefn") | |
731 { | |
732 octave_value_list retval; | |
733 | |
734 if (args.length () == 1) | |
735 { | |
736 int fid = octave_stream_list::get_file_number (args(0)); | |
737 | |
738 if (! error_state) | |
739 { | |
740 file_fstat fs (fid); | |
741 | |
742 if (fs) | |
743 { | |
744 retval(2) = std::string (); | |
745 retval(1) = 0; | |
746 retval(0) = octave_value (mk_stat_map (fs)); | |
747 } | |
748 else | |
749 { | |
750 retval(2) = fs.error (); | |
751 retval(1) = -1; | |
752 retval(0) = Matrix (); | |
753 } | |
754 } | |
755 } | |
756 else | |
757 print_usage (); | |
758 | |
759 return retval; | |
760 } | |
761 | |
2075 | 762 DEFUN (lstat, args, , |
3458 | 763 "-*- texinfo -*-\n\ |
764 @deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{file})\n\ | |
765 See stat.\n\ | |
766 @end deftypefn") | |
2075 | 767 { |
2263 | 768 octave_value_list retval; |
2075 | 769 |
770 if (args.length () == 1) | |
771 { | |
5872 | 772 std::string fname = args(0).string_value (); |
2075 | 773 |
774 if (! error_state) | |
775 { | |
776 file_stat fs (fname, false); | |
777 | |
2263 | 778 if (fs) |
2262 | 779 { |
3523 | 780 retval(2) = std::string (); |
4294 | 781 retval(1) = 0; |
4233 | 782 retval(0) = mk_stat_map (fs); |
2262 | 783 } |
784 else | |
785 { | |
786 retval(2) = fs.error (); | |
4294 | 787 retval(1) = -1; |
2262 | 788 retval(0) = Matrix (); |
789 } | |
2075 | 790 } |
791 } | |
792 else | |
5823 | 793 print_usage (); |
2075 | 794 |
795 return retval; | |
796 } | |
797 | |
3301 | 798 |
799 | |
2075 | 800 DEFUN (mkfifo, args, , |
3345 | 801 "-*- texinfo -*-\n\ |
4825 | 802 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} mkfifo (@var{name}, @var{mode})\n\ |
4928 | 803 Create a @var{fifo} special file named @var{name} with file mode @var{mode}\n\ |
2075 | 804 \n\ |
3301 | 805 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
806 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
807 system-dependent error message.\n\ | |
808 @end deftypefn") | |
2075 | 809 { |
2669 | 810 octave_value_list retval; |
811 | |
3523 | 812 retval(1) = std::string (); |
4294 | 813 retval(0) = -1; |
2075 | 814 |
815 int nargin = args.length (); | |
816 | |
817 if (nargin == 2) | |
818 { | |
819 if (args(0).is_string ()) | |
820 { | |
3523 | 821 std::string name = args(0).string_value (); |
2075 | 822 |
823 if (args(1).is_scalar_type ()) | |
824 { | |
4254 | 825 long mode = args(1).long_value (); |
2075 | 826 |
4254 | 827 if (! error_state) |
828 { | |
829 std::string msg; | |
830 | |
831 int status = file_ops::mkfifo (name, mode, msg); | |
2669 | 832 |
4254 | 833 retval(0) = status; |
2669 | 834 |
4254 | 835 if (status < 0) |
836 retval(1) = msg; | |
837 } | |
838 else | |
839 error ("mkfifo: invalid MODE"); | |
2075 | 840 } |
841 else | |
842 error ("mkfifo: MODE must be an integer"); | |
843 } | |
844 else | |
845 error ("mkfifo: file name must be a string"); | |
846 } | |
847 else | |
5823 | 848 print_usage (); |
2075 | 849 |
850 return retval; | |
851 } | |
852 | |
853 DEFUN (pipe, args, , | |
3301 | 854 "-*- texinfo -*-\n\ |
6321 | 855 @deftypefn {Built-in Function} {[@var{read_fd}, @var{write_fd}, @var{err}, @var{msg}] =} pipe ()\n\ |
856 Create a pipe and return the reading and writing ends of the pipe\n\ | |
857 into @var{read_fd} and @var{write_fd} respectively.\n\ | |
2669 | 858 \n\ |
3301 | 859 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
860 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
861 system-dependent error message.\n\ | |
862 @end deftypefn") | |
2075 | 863 { |
2669 | 864 octave_value_list retval; |
865 | |
6321 | 866 retval(3) = std::string (); |
867 retval(2) = -1; | |
4294 | 868 retval(1) = -1; |
6321 | 869 retval(0) = -1; |
2075 | 870 |
871 int nargin = args.length (); | |
872 | |
873 if (nargin == 0) | |
874 { | |
875 int fid[2]; | |
876 | |
3523 | 877 std::string msg; |
2937 | 878 |
879 int status = octave_syscalls::pipe (fid, msg); | |
2669 | 880 |
881 if (status < 0) | |
6321 | 882 retval(3) = msg; |
2669 | 883 else |
2075 | 884 { |
3340 | 885 FILE *ifile = fdopen (fid[0], "r"); |
886 FILE *ofile = fdopen (fid[1], "w"); | |
2075 | 887 |
4327 | 888 std::string nm; |
889 | |
890 octave_stream is = octave_stdiostream::create (nm, ifile, | |
891 std::ios::in); | |
892 | |
893 octave_stream os = octave_stdiostream::create (nm, ofile, | |
894 std::ios::out); | |
2075 | 895 |
6321 | 896 retval(1) = octave_stream_list::insert (os); |
897 retval(0) = octave_stream_list::insert (is); | |
2075 | 898 |
6321 | 899 retval(2) = status; |
2669 | 900 } |
2075 | 901 } |
902 else | |
5823 | 903 print_usage (); |
2075 | 904 |
905 return retval; | |
906 } | |
907 | |
908 DEFUN (stat, args, , | |
3301 | 909 "-*- texinfo -*-\n\ |
910 @deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} stat (@var{file})\n\ | |
911 @deftypefnx {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{file})\n\ | |
912 Return a structure @var{s} containing the following information about\n\ | |
913 @var{file}.\n\ | |
914 \n\ | |
915 @table @code\n\ | |
916 @item dev\n\ | |
917 ID of device containing a directory entry for this file.\n\ | |
918 \n\ | |
919 @item ino\n\ | |
920 File number of the file.\n\ | |
921 \n\ | |
5476 | 922 @item mode\n\ |
923 File mode, as an integer. Use the functions @code{S_ISREG},\n\ | |
924 @code{S_ISDIR}, @code{S_ISCHR}, @code{S_ISBLK}, @code{S_ISFIFO},\n\ | |
925 @code{S_ISLNK}, or @code{S_ISSOCK} to extract information from this\n\ | |
926 value.\n\ | |
927 \n\ | |
3301 | 928 @item modestr\n\ |
929 File mode, as a string of ten letters or dashes as would be returned by\n\ | |
930 @kbd{ls -l}.\n\ | |
931 \n\ | |
932 @item nlink\n\ | |
933 Number of links.\n\ | |
2075 | 934 \n\ |
3301 | 935 @item uid\n\ |
936 User ID of file's owner.\n\ | |
937 \n\ | |
938 @item gid\n\ | |
939 Group ID of file's group.\n\ | |
940 \n\ | |
941 @item rdev\n\ | |
942 ID of device for block or character special files.\n\ | |
943 \n\ | |
944 @item size\n\ | |
945 Size in bytes.\n\ | |
946 \n\ | |
947 @item atime\n\ | |
948 Time of last access in the same form as time values returned from\n\ | |
949 @code{time}. @xref{Timing Utilities}.\n\ | |
950 \n\ | |
951 @item mtime\n\ | |
952 Time of last modification in the same form as time values returned from\n\ | |
953 @code{time}. @xref{Timing Utilities}.\n\ | |
2075 | 954 \n\ |
3301 | 955 @item ctime\n\ |
956 Time of last file status change in the same form as time values\n\ | |
957 returned from @code{time}. @xref{Timing Utilities}.\n\ | |
958 \n\ | |
959 @item blksize\n\ | |
960 Size of blocks in the file.\n\ | |
961 \n\ | |
962 @item blocks\n\ | |
963 Number of blocks allocated for file.\n\ | |
964 @end table\n\ | |
965 \n\ | |
966 If the call is successful @var{err} is 0 and @var{msg} is an empty\n\ | |
967 string. If the file does not exist, or some other error occurs, @var{s}\n\ | |
968 is an empty matrix, @var{err} is @minus{}1, and @var{msg} contains the\n\ | |
969 corresponding system error message.\n\ | |
970 \n\ | |
971 If @var{file} is a symbolic link, @code{stat} will return information\n\ | |
7001 | 972 about the actual file that is referenced by the link. Use @code{lstat}\n\ |
3301 | 973 if you want information about the symbolic link itself.\n\ |
974 \n\ | |
975 For example,\n\ | |
2075 | 976 \n\ |
3301 | 977 @example\n\ |
978 @group\n\ | |
979 [s, err, msg] = stat (\"/vmlinuz\")\n\ | |
980 @result{} s =\n\ | |
981 @{\n\ | |
982 atime = 855399756\n\ | |
983 rdev = 0\n\ | |
984 ctime = 847219094\n\ | |
985 uid = 0\n\ | |
986 size = 389218\n\ | |
987 blksize = 4096\n\ | |
988 mtime = 847219094\n\ | |
989 gid = 6\n\ | |
990 nlink = 1\n\ | |
991 blocks = 768\n\ | |
5476 | 992 mode = -rw-r--r--\n\ |
3301 | 993 modestr = -rw-r--r--\n\ |
994 ino = 9316\n\ | |
995 dev = 2049\n\ | |
996 @}\n\ | |
997 @result{} err = 0\n\ | |
998 @result{} msg = \n\ | |
999 @end group\n\ | |
1000 @end example\n\ | |
1001 @end deftypefn") | |
2075 | 1002 { |
2262 | 1003 octave_value_list retval; |
2075 | 1004 |
1005 if (args.length () == 1) | |
1006 { | |
5872 | 1007 std::string fname = args(0).string_value (); |
2075 | 1008 |
1009 if (! error_state) | |
1010 { | |
1011 file_stat fs (fname); | |
1012 | |
1013 if (fs) | |
2262 | 1014 { |
3523 | 1015 retval(2) = std::string (); |
4294 | 1016 retval(1) = 0; |
2262 | 1017 retval(0) = octave_value (mk_stat_map (fs)); |
1018 } | |
1019 else | |
1020 { | |
1021 retval(2) = fs.error (); | |
4294 | 1022 retval(1) = -1; |
2262 | 1023 retval(0) = Matrix (); |
1024 } | |
2075 | 1025 } |
1026 } | |
1027 else | |
5823 | 1028 print_usage (); |
2075 | 1029 |
1030 return retval; | |
1031 } | |
1032 | |
5476 | 1033 DEFUNX ("S_ISREG", FS_ISREG, args, , |
1034 "-*- texinfo -*-\n\ | |
1035 @deftypefn {Built-in Function} {} S_ISREG (@var{mode})\n\ | |
1036 Return true if @var{mode} corresponds to a regular file. The value\n\ | |
1037 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ | |
1038 @seealso{stat, lstat}\n\ | |
1039 @end deftypefn") | |
1040 { | |
1041 octave_value retval = false; | |
1042 | |
1043 if (args.length () == 1) | |
1044 { | |
1045 double mode = args(0).double_value (); | |
1046 | |
1047 if (! error_state) | |
1048 retval = file_stat::is_reg (static_cast<mode_t> (mode)); | |
1049 else | |
1050 error ("S_ISREG: invalid mode value"); | |
1051 } | |
1052 else | |
5823 | 1053 print_usage (); |
5476 | 1054 |
1055 return retval; | |
1056 } | |
1057 | |
1058 DEFUNX ("S_ISDIR", FS_ISDIR, args, , | |
1059 "-*- texinfo -*-\n\ | |
1060 @deftypefn {Built-in Function} {} S_ISDIR (@var{mode})\n\ | |
1061 Return true if @var{mode} corresponds to a directory. The value\n\ | |
1062 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ | |
1063 @seealso{stat, lstat}\n\ | |
1064 @end deftypefn") | |
1065 { | |
1066 octave_value retval = false; | |
1067 | |
1068 if (args.length () == 1) | |
1069 { | |
1070 double mode = args(0).double_value (); | |
1071 | |
1072 if (! error_state) | |
1073 retval = file_stat::is_dir (static_cast<mode_t> (mode)); | |
1074 else | |
1075 error ("S_ISDIR: invalid mode value"); | |
1076 } | |
1077 else | |
5823 | 1078 print_usage (); |
5476 | 1079 |
1080 return retval; | |
1081 } | |
1082 | |
1083 DEFUNX ("S_ISCHR", FS_ISCHR, args, , | |
1084 "-*- texinfo -*-\n\ | |
1085 @deftypefn {Built-in Function} {} S_ISCHR (@var{mode})\n\ | |
1086 Return true if @var{mode} corresponds to a character devicey. The value\n\ | |
1087 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ | |
1088 @seealso{stat, lstat}\n\ | |
1089 @end deftypefn") | |
1090 { | |
1091 octave_value retval = false; | |
1092 | |
1093 if (args.length () == 1) | |
1094 { | |
1095 double mode = args(0).double_value (); | |
1096 | |
1097 if (! error_state) | |
1098 retval = file_stat::is_chr (static_cast<mode_t> (mode)); | |
1099 else | |
1100 error ("S_ISCHR: invalid mode value"); | |
1101 } | |
1102 else | |
5823 | 1103 print_usage (); |
5476 | 1104 |
1105 return retval; | |
1106 } | |
1107 | |
1108 DEFUNX ("S_ISBLK", FS_ISBLK, args, , | |
1109 "-*- texinfo -*-\n\ | |
1110 @deftypefn {Built-in Function} {} S_ISBLK (@var{mode})\n\ | |
1111 Return true if @var{mode} corresponds to a block device. The value\n\ | |
1112 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ | |
1113 @seealso{stat, lstat}\n\ | |
1114 @end deftypefn") | |
1115 { | |
1116 octave_value retval = false; | |
1117 | |
1118 if (args.length () == 1) | |
1119 { | |
1120 double mode = args(0).double_value (); | |
1121 | |
1122 if (! error_state) | |
1123 retval = file_stat::is_blk (static_cast<mode_t> (mode)); | |
1124 else | |
1125 error ("S_ISBLK: invalid mode value"); | |
1126 } | |
1127 else | |
5823 | 1128 print_usage (); |
5476 | 1129 |
1130 return retval; | |
1131 } | |
1132 | |
1133 DEFUNX ("S_ISFIFO", FS_ISFIFO, args, , | |
1134 "-*- texinfo -*-\n\ | |
1135 @deftypefn {Built-in Function} {} S_ISFIFO (@var{mode})\n\ | |
1136 Return true if @var{mode} corresponds to a fifo. The value\n\ | |
1137 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ | |
1138 @seealso{stat, lstat}\n\ | |
1139 @end deftypefn") | |
1140 { | |
1141 octave_value retval = false; | |
1142 | |
1143 if (args.length () == 1) | |
1144 { | |
1145 double mode = args(0).double_value (); | |
1146 | |
1147 if (! error_state) | |
1148 retval = file_stat::is_fifo (static_cast<mode_t> (mode)); | |
1149 else | |
1150 error ("S_ISFIFO: invalid mode value"); | |
1151 } | |
1152 else | |
5823 | 1153 print_usage (); |
5476 | 1154 |
1155 return retval; | |
1156 } | |
1157 | |
1158 DEFUNX ("S_ISLNK", FS_ISLNK, args, , | |
1159 "-*- texinfo -*-\n\ | |
1160 @deftypefn {Built-in Function} {} S_ISLNK (@var{mode})\n\ | |
1161 Return true if @var{mode} corresponds to a symbolic link. The value\n\ | |
1162 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ | |
1163 @seealso{stat, lstat}\n\ | |
1164 @end deftypefn") | |
1165 { | |
1166 octave_value retval = false; | |
1167 | |
1168 if (args.length () == 1) | |
1169 { | |
1170 double mode = args(0).double_value (); | |
1171 | |
1172 if (! error_state) | |
1173 retval = file_stat::is_lnk (static_cast<mode_t> (mode)); | |
1174 else | |
1175 error ("S_ISLNK: invalid mode value"); | |
1176 } | |
1177 else | |
5823 | 1178 print_usage (); |
5476 | 1179 |
1180 return retval; | |
1181 } | |
1182 | |
1183 DEFUNX ("S_ISSOCK", FS_ISSOCK, args, , | |
1184 "-*- texinfo -*-\n\ | |
1185 @deftypefn {Built-in Function} {} S_ISSOCK (@var{mode})\n\ | |
1186 @seealso{stat, lstat}\n\ | |
1187 @end deftypefn") | |
1188 { | |
1189 octave_value retval = false; | |
1190 | |
1191 if (args.length () == 1) | |
1192 { | |
1193 double mode = args(0).double_value (); | |
1194 | |
1195 if (! error_state) | |
1196 retval = file_stat::is_sock (static_cast<mode_t> (mode)); | |
1197 else | |
1198 error ("S_ISSOCK: invalid mode value"); | |
1199 } | |
1200 else | |
5823 | 1201 print_usage (); |
5476 | 1202 |
1203 return retval; | |
1204 } | |
1205 | |
5547 | 1206 DEFUN (uname, args, , |
1207 "-*- texinfo -*-\n\ | |
1208 @deftypefn {Built-in Function} {[@var{uts}, @var{err}, @var{msg}] =} uname ()\n\ | |
1209 Return system information in the structure. For example,\n\ | |
1210 \n\ | |
1211 @example\n\ | |
1212 @group\n\ | |
1213 uname ()\n\ | |
1214 @result{} @{\n\ | |
5656 | 1215 sysname = x86_64\n\ |
1216 nodename = segfault\n\ | |
1217 release = 2.6.15-1-amd64-k8-smp\n\ | |
1218 version = Linux\n\ | |
1219 machine = #2 SMP Thu Feb 23 04:57:49 UTC 2006\n\ | |
5547 | 1220 @}\n\ |
1221 @end group\n\ | |
1222 @end example\n\ | |
1223 \n\ | |
1224 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ | |
1225 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
1226 system-dependent error message.\n\ | |
1227 @end deftypefn") | |
1228 { | |
1229 octave_value_list retval; | |
1230 | |
1231 if (args.length () == 0) | |
1232 { | |
1233 octave_uname sysinfo; | |
1234 | |
1235 Octave_map m; | |
1236 | |
1237 m.assign ("sysname", sysinfo.sysname ()); | |
1238 m.assign ("nodename", sysinfo.nodename ()); | |
1239 m.assign ("release", sysinfo.release ()); | |
1240 m.assign ("version", sysinfo.version ()); | |
1241 m.assign ("machine", sysinfo.machine ()); | |
1242 | |
1243 retval(2) = sysinfo.message (); | |
1244 retval(1) = sysinfo.error (); | |
1245 retval(0) = m; | |
1246 } | |
1247 else | |
5823 | 1248 print_usage (); |
5547 | 1249 |
1250 return retval; | |
1251 } | |
1252 | |
2075 | 1253 DEFUN (unlink, args, , |
3301 | 1254 "-*- texinfo -*-\n\ |
1255 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} unlink (@var{file})\n\ | |
1256 Delete the file named @var{file}.\n\ | |
2075 | 1257 \n\ |
3301 | 1258 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
1259 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
1260 system-dependent error message.\n\ | |
1261 @end deftypefn") | |
2075 | 1262 { |
2669 | 1263 octave_value_list retval; |
1264 | |
3523 | 1265 retval(1) = std::string (); |
4294 | 1266 retval(0) = -1; |
2075 | 1267 |
1268 int nargin = args.length (); | |
1269 | |
1270 if (nargin == 1) | |
1271 { | |
1272 if (args(0).is_string ()) | |
1273 { | |
3523 | 1274 std::string name = args(0).string_value (); |
2075 | 1275 |
3523 | 1276 std::string msg; |
2669 | 1277 |
2926 | 1278 int status = file_ops::unlink (name, msg); |
2669 | 1279 |
4233 | 1280 retval(0) = status; |
2937 | 1281 retval(1) = msg; |
2075 | 1282 } |
1283 else | |
1284 error ("unlink: file name must be a string"); | |
1285 } | |
1286 else | |
5823 | 1287 print_usage (); |
2075 | 1288 |
1289 return retval; | |
1290 } | |
1291 | |
1292 DEFUN (waitpid, args, , | |
3301 | 1293 "-*- texinfo -*-\n\ |
5453 | 1294 @deftypefn {Built-in Function} {[@var{pid}, @var{status}, @var{msg}] =} waitpid (@var{pid}, @var{options})\n\ |
3301 | 1295 Wait for process @var{pid} to terminate. The @var{pid} argument can be:\n\ |
2075 | 1296 \n\ |
3301 | 1297 @table @asis\n\ |
1298 @item @minus{}1\n\ | |
1299 Wait for any child process.\n\ | |
2075 | 1300 \n\ |
3301 | 1301 @item 0\n\ |
1302 Wait for any child process whose process group ID is equal to that of\n\ | |
1303 the Octave interpreter process.\n\ | |
2075 | 1304 \n\ |
3301 | 1305 @item > 0\n\ |
1306 Wait for termination of the child process with ID @var{pid}.\n\ | |
1307 @end table\n\ | |
1308 \n\ | |
5453 | 1309 The @var{options} argument can be a bitwise OR of zero or more of\n\ |
1310 the following constants:\n\ | |
2075 | 1311 \n\ |
5453 | 1312 @table @code\n\ |
3301 | 1313 @item 0\n\ |
1314 Wait until signal is received or a child process exits (this is the\n\ | |
1315 default if the @var{options} argument is missing).\n\ | |
1316 \n\ | |
5453 | 1317 @item WNOHANG\n\ |
3301 | 1318 Do not hang if status is not immediately available.\n\ |
2075 | 1319 \n\ |
5453 | 1320 @item WUNTRACED\n\ |
3301 | 1321 Report the status of any child processes that are stopped, and whose\n\ |
1322 status has not yet been reported since they stopped.\n\ | |
1323 \n\ | |
8286
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7924
diff
changeset
|
1324 @item WCONTINUE\n\ |
5453 | 1325 Return if a stopped child has been resumed by delivery of @code{SIGCONT}.\n\ |
1326 This value may not be meaningful on all systems.\n\ | |
3301 | 1327 @end table\n\ |
1328 \n\ | |
1329 If the returned value of @var{pid} is greater than 0, it is the process\n\ | |
1330 ID of the child process that exited. If an error occurs, @var{pid} will\n\ | |
1331 be less than zero and @var{msg} will contain a system-dependent error\n\ | |
7001 | 1332 message. The value of @var{status} contains additional system-dependent\n\ |
5453 | 1333 information about the subprocess that exited.\n\ |
8286
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7924
diff
changeset
|
1334 @seealso{WCONTINUE, WCOREDUMP, WEXITSTATUS, WIFCONTINUED, WIFSIGNALED, WIFSTOPPED, WNOHANG, WSTOPSIG, WTERMSIG, WUNTRACED}\n\ |
3301 | 1335 @end deftypefn") |
2075 | 1336 { |
2669 | 1337 octave_value_list retval; |
1338 | |
5453 | 1339 retval(2) = std::string (); |
1340 retval(1) = 0; | |
4294 | 1341 retval(0) = -1; |
2075 | 1342 |
1343 int nargin = args.length (); | |
1344 | |
1345 if (nargin == 1 || nargin == 2) | |
1346 { | |
3202 | 1347 pid_t pid = args(0).int_value (true); |
2075 | 1348 |
1349 if (! error_state) | |
1350 { | |
3202 | 1351 int options = 0; |
2075 | 1352 |
3202 | 1353 if (args.length () == 2) |
5453 | 1354 options = args(1).int_value (true); |
2937 | 1355 |
3202 | 1356 if (! error_state) |
1357 { | |
3523 | 1358 std::string msg; |
2669 | 1359 |
5453 | 1360 int status = 0; |
1361 | |
1362 pid_t result = octave_syscalls::waitpid (pid, &status, options, msg); | |
3202 | 1363 |
5453 | 1364 retval(0) = result; |
1365 retval(1) = status; | |
1366 retval(2) = msg; | |
2075 | 1367 } |
5453 | 1368 else |
1369 error ("waitpid: OPTIONS must be an integer"); | |
2075 | 1370 } |
3202 | 1371 else |
1372 error ("waitpid: PID must be an integer value"); | |
2075 | 1373 } |
1374 else | |
5823 | 1375 print_usage (); |
2075 | 1376 |
1377 return retval; | |
1378 } | |
1379 | |
5453 | 1380 DEFUNX ("WIFEXITED", FWIFEXITED, args, , |
1381 "-*- texinfo -*-\n\ | |
1382 @deftypefn {Built-in Function} {} WIFEXITED (@var{status})\n\ | |
1383 Given @var{status} from a call to @code{waitpid}, return true if the\n\ | |
1384 child terminated normally.\n\ | |
1385 @seealso{waitpid, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ | |
5646 | 1386 @end deftypefn") |
5453 | 1387 { |
1388 octave_value retval = 0.0; | |
1389 | |
1390 #if defined (WIFEXITED) | |
1391 if (args.length () == 1) | |
1392 { | |
1393 int status = args(0).int_value (); | |
1394 | |
1395 if (! error_state) | |
1396 retval = WIFEXITED (status); | |
1397 else | |
1398 error ("WIFEXITED: expecting integer argument"); | |
1399 } | |
1400 #else | |
1401 warning ("WIFEXITED always returns false in this version of Octave") | |
1402 #endif | |
1403 | |
1404 return retval; | |
1405 } | |
1406 | |
1407 DEFUNX ("WEXITSTATUS", FWEXITSTATUS, args, , | |
1408 "-*- texinfo -*-\n\ | |
1409 @deftypefn {Built-in Function} {} WEXITSTATUS (@var{status})\n\ | |
1410 Given @var{status} from a call to @code{waitpid}, return the exit\n\ | |
1411 status of the child. This function should only be employed if\n\ | |
1412 @code{WIFEXITED} returned true.\n\ | |
1413 @seealso{waitpid, WIFEXITED, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ | |
1414 @end deftypefn") | |
1415 { | |
1416 octave_value retval = 0.0; | |
1417 | |
1418 #if defined (WEXITSTATUS) | |
1419 if (args.length () == 1) | |
1420 { | |
1421 int status = args(0).int_value (); | |
1422 | |
1423 if (! error_state) | |
1424 retval = WEXITSTATUS (status); | |
1425 else | |
1426 error ("WEXITSTATUS: expecting integer argument"); | |
1427 } | |
1428 #else | |
1429 warning ("WEXITSTATUS always returns false in this version of Octave") | |
1430 #endif | |
1431 | |
1432 return retval; | |
1433 } | |
1434 | |
1435 DEFUNX ("WIFSIGNALED", FWIFSIGNALED, args, , | |
1436 "-*- texinfo -*-\n\ | |
1437 @deftypefn {Built-in Function} {} WIFSIGNALED (@var{status})\n\ | |
1438 Given @var{status} from a call to @code{waitpid}, return true if the\n\ | |
1439 child process was terminated by a signal.\n\ | |
1440 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ | |
1441 @end deftypefn") | |
1442 { | |
1443 octave_value retval = 0.0; | |
1444 | |
1445 #if defined (WIFSIGNALED) | |
1446 if (args.length () == 1) | |
1447 { | |
1448 int status = args(0).int_value (); | |
1449 | |
1450 if (! error_state) | |
1451 retval = WIFSIGNALED (status); | |
1452 else | |
1453 error ("WIFSIGNALED: expecting integer argument"); | |
1454 } | |
1455 #else | |
5455 | 1456 warning ("WIFSIGNALED always returns false in this version of Octave"); |
5453 | 1457 #endif |
1458 | |
1459 return retval; | |
1460 } | |
1461 | |
1462 DEFUNX ("WTERMSIG", FWTERMSIG, args, , | |
1463 "-*- texinfo -*-\n\ | |
1464 @deftypefn {Built-in Function} {} WTERMSIG (@var{status})\n\ | |
1465 Given @var{status} from a call to @code{waitpid}, return the number of\n\ | |
1466 the signal that caused the child process to terminate. This function\n\ | |
1467 should only be employed if @code{WIFSIGNALED} returned true.\n\ | |
1468 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ | |
1469 @end deftypefn") | |
1470 { | |
1471 octave_value retval = 0.0; | |
1472 | |
1473 #if defined (WTERMSIG) | |
1474 if (args.length () == 1) | |
1475 { | |
1476 int status = args(0).int_value (); | |
1477 | |
1478 if (! error_state) | |
1479 retval = WTERMSIG (status); | |
1480 else | |
1481 error ("WTERMSIG: expecting integer argument"); | |
1482 } | |
1483 #else | |
5455 | 1484 warning ("WTERMSIG always returns false in this version of Octave"); |
5453 | 1485 #endif |
1486 | |
1487 return retval; | |
1488 } | |
1489 | |
1490 DEFUNX ("WCOREDUMP", FWCOREDUMP, args, , | |
1491 "-*- texinfo -*-\n\ | |
1492 @deftypefn {Built-in Function} {} WCOREDUMP (@var{status})\n\ | |
1493 Given @var{status} from a call to @code{waitpid}, return true if the\n\ | |
1494 child produced a core dump. This function should only be employed if\n\ | |
1495 @code{WIFSIGNALED} returned true. The macro used to implement this\n\ | |
1496 function is not specified in POSIX.1-2001 and is not available on some\n\ | |
1497 Unix implementations (e.g., AIX, SunOS).\n\ | |
1498 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ | |
1499 @end deftypefn") | |
1500 { | |
1501 octave_value retval = 0.0; | |
1502 | |
1503 #if defined (WCOREDUMP) | |
1504 if (args.length () == 1) | |
1505 { | |
1506 int status = args(0).int_value (); | |
1507 | |
1508 if (! error_state) | |
1509 retval = WCOREDUMP (status); | |
1510 else | |
1511 error ("WCOREDUMP: expecting integer argument"); | |
1512 } | |
1513 #else | |
5455 | 1514 warning ("WCOREDUMP always returns false in this version of Octave"); |
5453 | 1515 #endif |
1516 | |
1517 return retval; | |
1518 } | |
1519 | |
1520 DEFUNX ("WIFSTOPPED", FWIFSTOPPED, args, , | |
1521 "-*- texinfo -*-\n\ | |
1522 @deftypefn {Built-in Function} {} WIFSTOPPED (@var{status})\n\ | |
1523 Given @var{status} from a call to @code{waitpid}, return true if the\n\ | |
1524 child process was stopped by delivery of a signal; this is only\n\ | |
1525 possible if the call was done using @code{WUNTRACED} or when the child\n\ | |
1526 is being traced (see ptrace(2)).\n\ | |
1527 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WSTOPSIG, WIFCONTINUED}\n\ | |
1528 @end deftypefn") | |
1529 { | |
1530 octave_value retval = 0.0; | |
1531 | |
1532 #if defined (WIFSTOPPED) | |
1533 if (args.length () == 1) | |
1534 { | |
1535 int status = args(0).int_value (); | |
1536 | |
1537 if (! error_state) | |
1538 retval = WIFSTOPPED (status); | |
1539 else | |
1540 error ("WIFSTOPPED: expecting integer argument"); | |
1541 } | |
1542 #else | |
5455 | 1543 warning ("WIFSTOPPED always returns false in this version of Octave"); |
5453 | 1544 #endif |
1545 | |
1546 return retval; | |
1547 } | |
1548 | |
1549 DEFUNX ("WSTOPSIG", FWSTOPSIG, args, , | |
1550 "-*- texinfo -*-\n\ | |
1551 @deftypefn {Built-in Function} {} WSTOPSIG (@var{status})\n\ | |
1552 Given @var{status} from a call to @code{waitpid}, return the number of\n\ | |
1553 the signal which caused the child to stop. This function should only\n\ | |
1554 be employed if @code{WIFSTOPPED} returned true.\n\ | |
1555 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WIFCONTINUED}\n\ | |
1556 @end deftypefn") | |
1557 { | |
1558 octave_value retval = 0.0; | |
1559 | |
1560 #if defined (WSTOPSIG) | |
1561 if (args.length () == 1) | |
1562 { | |
1563 int status = args(0).int_value (); | |
1564 | |
1565 if (! error_state) | |
1566 retval = WSTOPSIG (status); | |
1567 else | |
1568 error ("WSTOPSIG: expecting integer argument"); | |
1569 } | |
1570 #else | |
5455 | 1571 warning ("WSTOPSIG always returns false in this version of Octave"); |
5453 | 1572 #endif |
1573 | |
1574 return retval; | |
1575 } | |
1576 | |
1577 DEFUNX ("WIFCONTINUED", FWIFCONTINUED, args, , | |
1578 "-*- texinfo -*-\n\ | |
1579 @deftypefn {Built-in Function} {} WIFCONTINUED (@var{status})\n\ | |
1580 Given @var{status} from a call to @code{waitpid}, return true if the\n\ | |
1581 child process was resumed by delivery of @code{SIGCONT}.\n\ | |
1582 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG}\n\ | |
1583 @end deftypefn") | |
1584 { | |
1585 octave_value retval = 0.0; | |
1586 | |
1587 #if defined (WIFCONTINUED) | |
1588 if (args.length () == 1) | |
1589 { | |
1590 int status = args(0).int_value (); | |
1591 | |
1592 if (! error_state) | |
1593 retval = WIFCONTINUED (status); | |
1594 else | |
1595 error ("WIFCONTINUED: expecting integer argument"); | |
1596 } | |
1597 #else | |
5455 | 1598 warning ("WIFCONTINUED always returns false in this version of Octave"); |
5453 | 1599 #endif |
1600 | |
1601 return retval; | |
1602 } | |
1603 | |
5138 | 1604 DEFUN (canonicalize_file_name, args, , |
1605 "-*- texinfo -*-\n\ | |
1606 @deftypefn {Built-in Function} {[@var{cname}, @var{status}, @var{msg}]} canonicalize_file_name (@var{name})\n\ | |
1607 Return the canonical name of file @var{name}.\n\ | |
1608 @end deftypefn") | |
1609 { | |
1610 octave_value_list retval; | |
1611 | |
1612 if (args.length () == 1) | |
1613 { | |
1614 std::string name = args(0).string_value (); | |
1615 | |
1616 if (! error_state) | |
1617 { | |
1618 std::string msg; | |
1619 | |
1620 std::string result = file_ops::canonicalize_file_name (name, msg); | |
1621 | |
1622 retval(2) = msg; | |
1623 retval(1) = msg.empty () ? 0 : -1; | |
1624 retval(0) = result; | |
1625 } | |
1626 else | |
1627 error ("canonicalize_file_name: argument must be a character string"); | |
1628 } | |
1629 else | |
5823 | 1630 print_usage (); |
5138 | 1631 |
1632 return retval; | |
1633 } | |
1634 | |
5749 | 1635 static octave_value |
7924 | 1636 const_value (const octave_value_list& args, int val) |
5749 | 1637 { |
1638 octave_value retval; | |
1639 | |
1640 int nargin = args.length (); | |
1641 | |
1642 if (nargin == 0) | |
1643 retval = val; | |
1644 else | |
5823 | 1645 print_usage (); |
5749 | 1646 |
1647 return retval; | |
1648 } | |
1649 | |
2075 | 1650 #if !defined (O_NONBLOCK) && defined (O_NDELAY) |
1651 #define O_NONBLOCK O_NDELAY | |
1652 #endif | |
1653 | |
5749 | 1654 #if defined (F_DUPFD) |
1655 DEFUNX ("F_DUPFD", FF_DUPFD, args, , | |
1656 "-*- texinfo -*-\n\ | |
1657 @deftypefn {Built-in Function} {} F_DUPFD ()\n\ | |
1658 Return the value required to request that @code{fcntl} return a\n\ | |
1659 duplicate file descriptor.\n\ | |
1660 @seealso{fcntl, F_GETFD, F_GETFL, F_SETFD, F_SETFL}\n\ | |
1661 @end deftypefn") | |
2075 | 1662 { |
7924 | 1663 return const_value (args, F_DUPFD); |
5749 | 1664 } |
2075 | 1665 #endif |
1666 | |
1667 #if defined (F_GETFD) | |
5749 | 1668 DEFUNX ("F_GETFD", FF_GETFD, args, , |
1669 "-*- texinfo -*-\n\ | |
1670 @deftypefn {Built-in Function} {} F_GETFD ()\n\ | |
1671 Return the value required to request that @code{fcntl} to return the\n\ | |
1672 file descriptor flags.\n\ | |
5333 | 1673 @seealso{fcntl, F_DUPFD, F_GETFL, F_SETFD, F_SETFL}\n\ |
5749 | 1674 @end deftypefn") |
1675 { | |
7924 | 1676 return const_value (args, F_GETFD); |
5749 | 1677 } |
2075 | 1678 #endif |
1679 | |
1680 #if defined (F_GETFL) | |
5749 | 1681 DEFUNX ("F_GETFL", FF_GETFL, args, , |
1682 "-*- texinfo -*-\n\ | |
1683 @deftypefn {Built-in Function} {} F_GETFL ()\n\ | |
1684 Return the value required to request that @code{fcntl} to return the\n\ | |
1685 file status flags.\n\ | |
5333 | 1686 @seealso{fcntl, F_DUPFD, F_GETFD, F_SETFD, F_SETFL}\n\ |
5749 | 1687 @end deftypefn") |
1688 { | |
7924 | 1689 return const_value (args, F_GETFL); |
5749 | 1690 } |
2075 | 1691 #endif |
1692 | |
1693 #if defined (F_SETFD) | |
5749 | 1694 DEFUNX ("F_SETFD", FF_SETFD, args, , |
1695 "-*- texinfo -*-\n\ | |
1696 @deftypefn {Built-in Function} {} F_SETFD ()\n\ | |
1697 Return the value required to request that @code{fcntl} to set the file\n\ | |
1698 descriptor flags.\n\ | |
5333 | 1699 @seealso{fcntl, F_DUPFD, F_GETFD, F_GETFL, F_SETFL}\n\ |
5749 | 1700 @end deftypefn") |
1701 { | |
7924 | 1702 return const_value (args, F_SETFD); |
5749 | 1703 } |
2075 | 1704 #endif |
1705 | |
1706 #if defined (F_SETFL) | |
5749 | 1707 DEFUNX ("F_SETFL", FF_SETFL, args, , |
1708 "-*- texinfo -*-\n\ | |
1709 @deftypefn {Built-in Function} {} F_SETFL ()\n\ | |
1710 Return the value required to request that @code{fcntl} to set the file\n\ | |
1711 status flags.\n\ | |
5333 | 1712 @seealso{fcntl, F_DUPFD, F_GETFD, F_GETFL, F_SETFD}\n\ |
5749 | 1713 @end deftypefn") |
1714 { | |
7924 | 1715 return const_value (args, F_SETFL); |
5749 | 1716 } |
2075 | 1717 #endif |
1718 | |
1719 #if defined (O_APPEND) | |
5749 | 1720 DEFUNX ("O_APPEND", FO_APPEND, args, , |
1721 "-*- texinfo -*-\n\ | |
1722 @deftypefn {Built-in Function} {} O_APPEND ()\n\ | |
1723 Return the numerical value of the file status flag that may be\n\ | |
1724 returned by @code{fcntl} to indicate each write operation appends,\n\ | |
1725 or that may be passed to @code{fcntl} to set the write mode to append.\ | |
5333 | 1726 @seealso{fcntl, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749 | 1727 @end deftypefn") |
1728 { | |
7924 | 1729 return const_value (args, O_APPEND); |
5749 | 1730 } |
2075 | 1731 #endif |
1732 | |
2669 | 1733 #if defined (O_ASYNC) |
5749 | 1734 DEFUNX ("O_ASYNC", FO_ASYNC, args, , |
1735 "-*- texinfo -*-\n\ | |
1736 @deftypefn {Built-in Function} {} O_ASYNC ()\n\ | |
1737 Return the numerical value of the file status flag that may be\n\ | |
1738 returned by @code{fcntl} to indicate asynchronous I/O.\n\ | |
5333 | 1739 @seealso{fcntl, O_APPEND, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749 | 1740 @end deftypefn") |
1741 { | |
7924 | 1742 return const_value (args, O_ASYNC); |
5749 | 1743 } |
2669 | 1744 #endif |
1745 | |
2075 | 1746 #if defined (O_CREAT) |
5749 | 1747 DEFUNX ("O_CREAT", FO_CREAT, args, , |
1748 "-*- texinfo -*-\n\ | |
1749 @deftypefn {Built-in Function} {} O_CREAT ()\n\ | |
1750 Return the numerical value of the file status flag that may be\n\ | |
1751 returned by @code{fcntl} to indicate that a file should be\n\ | |
1752 created if it does not exist.\n\ | |
5333 | 1753 @seealso{fcntl, O_APPEND, O_ASYNC, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749 | 1754 @end deftypefn") |
1755 { | |
7924 | 1756 return const_value (args, O_CREAT); |
5749 | 1757 } |
2075 | 1758 #endif |
1759 | |
1760 #if defined (O_EXCL) | |
5749 | 1761 DEFUNX ("O_EXCL", FO_EXCL, args, , |
1762 "-*- texinfo -*-\n\ | |
1763 @deftypefn {Built-in Function} {} O_EXCL ()\n\ | |
1764 Return the numerical value of the file status flag that may be\n\ | |
1765 returned by @code{fcntl} to indicate that file locking is used.\n\ | |
5333 | 1766 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749 | 1767 @end deftypefn") |
1768 { | |
7924 | 1769 return const_value (args, O_EXCL); |
5749 | 1770 } |
2075 | 1771 #endif |
1772 | |
1773 #if defined (O_NONBLOCK) | |
5749 | 1774 DEFUNX ("O_NONBLOCK", FO_NONBLOCK, args, , |
1775 "-*- texinfo -*-\n\ | |
1776 @deftypefn {Built-in Function} {} O_NONBLOCK ()\n\ | |
1777 Return the numerical value of the file status flag that may be\n\ | |
1778 returned by @code{fcntl} to indicate that non-blocking I/O is in use,\n\ | |
1779 or that may be passsed to @code{fcntl} to set non-blocking I/O.\n\ | |
5333 | 1780 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749 | 1781 @end deftypefn") |
1782 { | |
7924 | 1783 return const_value (args, O_NONBLOCK); |
5749 | 1784 } |
2075 | 1785 #endif |
1786 | |
1787 #if defined (O_RDONLY) | |
5749 | 1788 DEFUNX ("O_RDONLY", FO_RDONLY, args, , |
1789 "-*- texinfo -*-\n\ | |
1790 @deftypefn {Built-in Function} {} O_RDONLY ()\n\ | |
1791 Return the numerical value of the file status flag that may be\n\ | |
1792 returned by @code{fcntl} to indicate that a file is open for\n\ | |
1793 reading only.\n\ | |
5333 | 1794 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749 | 1795 @end deftypefn") |
1796 { | |
7924 | 1797 return const_value (args, O_RDONLY); |
5749 | 1798 } |
2075 | 1799 #endif |
1800 | |
1801 #if defined (O_RDWR) | |
5749 | 1802 DEFUNX ("O_RDWR", FO_RDWR, args, , |
1803 "-*- texinfo -*-\n\ | |
1804 @deftypefn {Built-in Function} {} O_RDWR ()\n\ | |
1805 Return the numerical value of the file status flag that may be\n\ | |
1806 returned by @code{fcntl} to indicate that a file is open for both\n\ | |
1807 reading and writing.\n\ | |
5333 | 1808 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749 | 1809 @end deftypefn") |
1810 { | |
7924 | 1811 return const_value (args, O_RDWR); |
5749 | 1812 } |
2075 | 1813 #endif |
1814 | |
2669 | 1815 #if defined (O_SYNC) |
5749 | 1816 DEFUNX ("O_SYNC", FO_SYNC, args, , |
1817 "-*- texinfo -*-\n\ | |
1818 @deftypefn {Built-in Function} {} O_SYNC ()\n\ | |
1819 Return the numerical value of the file status flag that may be\n\ | |
1820 returned by @code{fcntl} to indicate that a file is open for\n\ | |
1821 synchronous I/O.\n\ | |
5333 | 1822 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY}\n\ |
5749 | 1823 @end deftypefn") |
1824 { | |
7924 | 1825 return const_value (args, O_SYNC); |
5749 | 1826 } |
2669 | 1827 #endif |
1828 | |
2075 | 1829 #if defined (O_TRUNC) |
5749 | 1830 DEFUNX ("O_TRUNC", FO_TRUNC, args, , |
1831 "-*- texinfo -*-\n\ | |
1832 @deftypefn {Built-in Variable} O_TRUNC ()\n\ | |
1833 Return the numerical value of the file status flag that may be\n\ | |
1834 returned by @code{fcntl} to indicate that if file exists, it should\n\ | |
1835 be truncated when writing.\n\ | |
5333 | 1836 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_WRONLY}\n\ |
5749 | 1837 @end deftypefn") |
1838 { | |
7924 | 1839 return const_value (args, O_TRUNC); |
5749 | 1840 } |
2075 | 1841 #endif |
1842 | |
1843 #if defined (O_WRONLY) | |
5749 | 1844 DEFUNX ("O_WRONLY", FO_WRONLY, args, , |
1845 "-*- texinfo -*-\n\ | |
1846 @deftypefn {Built-in Function} {} O_WRONLY ()\n\ | |
1847 Return the numerical value of the file status flag that may be\n\ | |
1848 returned by @code{fcntl} to indicate that a file is open for\n\ | |
1849 writing only.\n\ | |
5333 | 1850 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC}\n\ |
5749 | 1851 @end deftypefn") |
1852 { | |
7924 | 1853 return const_value (args, O_WRONLY); |
5749 | 1854 } |
2075 | 1855 #endif |
3446 | 1856 |
5453 | 1857 #if !defined (WNOHANG) |
1858 #define WNOHANG 0 | |
1859 #endif | |
1860 | |
5749 | 1861 DEFUNX ("WNOHANG", FWNOHANG, args, , |
1862 "-*- texinfo -*-\n\ | |
1863 @deftypefn {Built-in Function} {} WNOHANG ()\n\ | |
1864 Return the numerical value of the option argument that may be\n\ | |
1865 passed to @code{waitpid} to indicate that it should return its\n\ | |
1866 status immediately instead of waiting for a process to exit.\n\ | |
5453 | 1867 @seealso{waitpid, WUNTRACED, WCONTINUE}\n\ |
5749 | 1868 @end deftypefn") |
1869 { | |
7924 | 1870 return const_value (args, WNOHANG); |
5749 | 1871 } |
5453 | 1872 |
1873 #if !defined (WUNTRACED) | |
1874 #define WUNTRACED 0 | |
1875 #endif | |
1876 | |
5749 | 1877 DEFUNX ("WUNTRACED", FWUNTRACED, args, , |
1878 "-*- texinfo -*-\n\ | |
1879 @deftypefn {Built-in Function} {} WUNTRACED ()\n\ | |
1880 Return the numerical value of the option argument that may be\n\ | |
1881 passed to @code{waitpid} to indicate that it should also return\n\ | |
1882 if the child process has stopped but is not traced via the\n\ | |
1883 @code{ptrace} system call\n\ | |
5453 | 1884 @seealso{waitpid, WNOHANG, WCONTINUE}\n\ |
5749 | 1885 @end deftypefn") |
1886 { | |
7924 | 1887 return const_value (args, WUNTRACED); |
5749 | 1888 } |
5453 | 1889 |
1890 #if !defined (WCONTINUE) | |
1891 #define WCONTINUE 0 | |
1892 #endif | |
1893 | |
5749 | 1894 DEFUNX ("WCONTINUE", FWCONTINUE, args, , |
1895 "-*- texinfo -*-\n\ | |
1896 @deftypefn {Built-in Function} WCONINTUE ()\n\ | |
1897 Return the numerical value of the option argument that may be\n\ | |
1898 passed to @code{waitpid} to indicate that it should also return\n\ | |
1899 if a stopped child has been resumed by delivery of a @code{SIGCONT}\n\ | |
1900 signal.\n\ | |
5453 | 1901 @seealso{waitpid, WNOHANG, WUNTRACED}\n\ |
5749 | 1902 @end deftypefn") |
1903 { | |
7924 | 1904 return const_value (args, WCONTINUE); |
2075 | 1905 } |
1906 | |
1907 /* | |
1908 ;;; Local Variables: *** | |
1909 ;;; mode: C++ *** | |
1910 ;;; End: *** | |
1911 */ |