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