2075
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, |
|
4 2006, 2007 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 |
|
66 mk_stat_map (const file_stat& fs) |
|
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 |
2075
|
725 DEFUN (lstat, args, , |
3458
|
726 "-*- texinfo -*-\n\ |
|
727 @deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{file})\n\ |
|
728 See stat.\n\ |
|
729 @end deftypefn") |
2075
|
730 { |
2263
|
731 octave_value_list retval; |
2075
|
732 |
|
733 if (args.length () == 1) |
|
734 { |
5872
|
735 std::string fname = args(0).string_value (); |
2075
|
736 |
|
737 if (! error_state) |
|
738 { |
|
739 file_stat fs (fname, false); |
|
740 |
2263
|
741 if (fs) |
2262
|
742 { |
3523
|
743 retval(2) = std::string (); |
4294
|
744 retval(1) = 0; |
4233
|
745 retval(0) = mk_stat_map (fs); |
2262
|
746 } |
|
747 else |
|
748 { |
|
749 retval(2) = fs.error (); |
4294
|
750 retval(1) = -1; |
2262
|
751 retval(0) = Matrix (); |
|
752 } |
2075
|
753 } |
|
754 } |
|
755 else |
5823
|
756 print_usage (); |
2075
|
757 |
|
758 return retval; |
|
759 } |
|
760 |
3301
|
761 |
|
762 |
2075
|
763 DEFUN (mkfifo, args, , |
3345
|
764 "-*- texinfo -*-\n\ |
4825
|
765 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} mkfifo (@var{name}, @var{mode})\n\ |
4928
|
766 Create a @var{fifo} special file named @var{name} with file mode @var{mode}\n\ |
2075
|
767 \n\ |
3301
|
768 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
|
769 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ |
|
770 system-dependent error message.\n\ |
|
771 @end deftypefn") |
2075
|
772 { |
2669
|
773 octave_value_list retval; |
|
774 |
3523
|
775 retval(1) = std::string (); |
4294
|
776 retval(0) = -1; |
2075
|
777 |
|
778 int nargin = args.length (); |
|
779 |
|
780 if (nargin == 2) |
|
781 { |
|
782 if (args(0).is_string ()) |
|
783 { |
3523
|
784 std::string name = args(0).string_value (); |
2075
|
785 |
|
786 if (args(1).is_scalar_type ()) |
|
787 { |
4254
|
788 long mode = args(1).long_value (); |
2075
|
789 |
4254
|
790 if (! error_state) |
|
791 { |
|
792 std::string msg; |
|
793 |
|
794 int status = file_ops::mkfifo (name, mode, msg); |
2669
|
795 |
4254
|
796 retval(0) = status; |
2669
|
797 |
4254
|
798 if (status < 0) |
|
799 retval(1) = msg; |
|
800 } |
|
801 else |
|
802 error ("mkfifo: invalid MODE"); |
2075
|
803 } |
|
804 else |
|
805 error ("mkfifo: MODE must be an integer"); |
|
806 } |
|
807 else |
|
808 error ("mkfifo: file name must be a string"); |
|
809 } |
|
810 else |
5823
|
811 print_usage (); |
2075
|
812 |
|
813 return retval; |
|
814 } |
|
815 |
|
816 DEFUN (pipe, args, , |
3301
|
817 "-*- texinfo -*-\n\ |
6321
|
818 @deftypefn {Built-in Function} {[@var{read_fd}, @var{write_fd}, @var{err}, @var{msg}] =} pipe ()\n\ |
|
819 Create a pipe and return the reading and writing ends of the pipe\n\ |
|
820 into @var{read_fd} and @var{write_fd} respectively.\n\ |
2669
|
821 \n\ |
3301
|
822 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
|
823 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ |
|
824 system-dependent error message.\n\ |
|
825 @end deftypefn") |
2075
|
826 { |
2669
|
827 octave_value_list retval; |
|
828 |
6321
|
829 retval(3) = std::string (); |
|
830 retval(2) = -1; |
4294
|
831 retval(1) = -1; |
6321
|
832 retval(0) = -1; |
2075
|
833 |
|
834 int nargin = args.length (); |
|
835 |
|
836 if (nargin == 0) |
|
837 { |
|
838 int fid[2]; |
|
839 |
3523
|
840 std::string msg; |
2937
|
841 |
|
842 int status = octave_syscalls::pipe (fid, msg); |
2669
|
843 |
|
844 if (status < 0) |
6321
|
845 retval(3) = msg; |
2669
|
846 else |
2075
|
847 { |
3340
|
848 FILE *ifile = fdopen (fid[0], "r"); |
|
849 FILE *ofile = fdopen (fid[1], "w"); |
2075
|
850 |
4327
|
851 std::string nm; |
|
852 |
|
853 octave_stream is = octave_stdiostream::create (nm, ifile, |
|
854 std::ios::in); |
|
855 |
|
856 octave_stream os = octave_stdiostream::create (nm, ofile, |
|
857 std::ios::out); |
2075
|
858 |
6321
|
859 retval(1) = octave_stream_list::insert (os); |
|
860 retval(0) = octave_stream_list::insert (is); |
2075
|
861 |
6321
|
862 retval(2) = status; |
2669
|
863 } |
2075
|
864 } |
|
865 else |
5823
|
866 print_usage (); |
2075
|
867 |
|
868 return retval; |
|
869 } |
|
870 |
|
871 DEFUN (stat, args, , |
3301
|
872 "-*- texinfo -*-\n\ |
|
873 @deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} stat (@var{file})\n\ |
|
874 @deftypefnx {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{file})\n\ |
|
875 Return a structure @var{s} containing the following information about\n\ |
|
876 @var{file}.\n\ |
|
877 \n\ |
|
878 @table @code\n\ |
|
879 @item dev\n\ |
|
880 ID of device containing a directory entry for this file.\n\ |
|
881 \n\ |
|
882 @item ino\n\ |
|
883 File number of the file.\n\ |
|
884 \n\ |
5476
|
885 @item mode\n\ |
|
886 File mode, as an integer. Use the functions @code{S_ISREG},\n\ |
|
887 @code{S_ISDIR}, @code{S_ISCHR}, @code{S_ISBLK}, @code{S_ISFIFO},\n\ |
|
888 @code{S_ISLNK}, or @code{S_ISSOCK} to extract information from this\n\ |
|
889 value.\n\ |
|
890 \n\ |
3301
|
891 @item modestr\n\ |
|
892 File mode, as a string of ten letters or dashes as would be returned by\n\ |
|
893 @kbd{ls -l}.\n\ |
|
894 \n\ |
|
895 @item nlink\n\ |
|
896 Number of links.\n\ |
2075
|
897 \n\ |
3301
|
898 @item uid\n\ |
|
899 User ID of file's owner.\n\ |
|
900 \n\ |
|
901 @item gid\n\ |
|
902 Group ID of file's group.\n\ |
|
903 \n\ |
|
904 @item rdev\n\ |
|
905 ID of device for block or character special files.\n\ |
|
906 \n\ |
|
907 @item size\n\ |
|
908 Size in bytes.\n\ |
|
909 \n\ |
|
910 @item atime\n\ |
|
911 Time of last access in the same form as time values returned from\n\ |
|
912 @code{time}. @xref{Timing Utilities}.\n\ |
|
913 \n\ |
|
914 @item mtime\n\ |
|
915 Time of last modification in the same form as time values returned from\n\ |
|
916 @code{time}. @xref{Timing Utilities}.\n\ |
2075
|
917 \n\ |
3301
|
918 @item ctime\n\ |
|
919 Time of last file status change in the same form as time values\n\ |
|
920 returned from @code{time}. @xref{Timing Utilities}.\n\ |
|
921 \n\ |
|
922 @item blksize\n\ |
|
923 Size of blocks in the file.\n\ |
|
924 \n\ |
|
925 @item blocks\n\ |
|
926 Number of blocks allocated for file.\n\ |
|
927 @end table\n\ |
|
928 \n\ |
|
929 If the call is successful @var{err} is 0 and @var{msg} is an empty\n\ |
|
930 string. If the file does not exist, or some other error occurs, @var{s}\n\ |
|
931 is an empty matrix, @var{err} is @minus{}1, and @var{msg} contains the\n\ |
|
932 corresponding system error message.\n\ |
|
933 \n\ |
|
934 If @var{file} is a symbolic link, @code{stat} will return information\n\ |
7001
|
935 about the actual file that is referenced by the link. Use @code{lstat}\n\ |
3301
|
936 if you want information about the symbolic link itself.\n\ |
|
937 \n\ |
|
938 For example,\n\ |
2075
|
939 \n\ |
3301
|
940 @example\n\ |
|
941 @group\n\ |
|
942 [s, err, msg] = stat (\"/vmlinuz\")\n\ |
|
943 @result{} s =\n\ |
|
944 @{\n\ |
|
945 atime = 855399756\n\ |
|
946 rdev = 0\n\ |
|
947 ctime = 847219094\n\ |
|
948 uid = 0\n\ |
|
949 size = 389218\n\ |
|
950 blksize = 4096\n\ |
|
951 mtime = 847219094\n\ |
|
952 gid = 6\n\ |
|
953 nlink = 1\n\ |
|
954 blocks = 768\n\ |
5476
|
955 mode = -rw-r--r--\n\ |
3301
|
956 modestr = -rw-r--r--\n\ |
|
957 ino = 9316\n\ |
|
958 dev = 2049\n\ |
|
959 @}\n\ |
|
960 @result{} err = 0\n\ |
|
961 @result{} msg = \n\ |
|
962 @end group\n\ |
|
963 @end example\n\ |
|
964 @end deftypefn") |
2075
|
965 { |
2262
|
966 octave_value_list retval; |
2075
|
967 |
|
968 if (args.length () == 1) |
|
969 { |
5872
|
970 std::string fname = args(0).string_value (); |
2075
|
971 |
|
972 if (! error_state) |
|
973 { |
|
974 file_stat fs (fname); |
|
975 |
|
976 if (fs) |
2262
|
977 { |
3523
|
978 retval(2) = std::string (); |
4294
|
979 retval(1) = 0; |
2262
|
980 retval(0) = octave_value (mk_stat_map (fs)); |
|
981 } |
|
982 else |
|
983 { |
|
984 retval(2) = fs.error (); |
4294
|
985 retval(1) = -1; |
2262
|
986 retval(0) = Matrix (); |
|
987 } |
2075
|
988 } |
|
989 } |
|
990 else |
5823
|
991 print_usage (); |
2075
|
992 |
|
993 return retval; |
|
994 } |
|
995 |
5476
|
996 DEFUNX ("S_ISREG", FS_ISREG, args, , |
|
997 "-*- texinfo -*-\n\ |
|
998 @deftypefn {Built-in Function} {} S_ISREG (@var{mode})\n\ |
|
999 Return true if @var{mode} corresponds to a regular file. The value\n\ |
|
1000 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ |
|
1001 @seealso{stat, lstat}\n\ |
|
1002 @end deftypefn") |
|
1003 { |
|
1004 octave_value retval = false; |
|
1005 |
|
1006 if (args.length () == 1) |
|
1007 { |
|
1008 double mode = args(0).double_value (); |
|
1009 |
|
1010 if (! error_state) |
|
1011 retval = file_stat::is_reg (static_cast<mode_t> (mode)); |
|
1012 else |
|
1013 error ("S_ISREG: invalid mode value"); |
|
1014 } |
|
1015 else |
5823
|
1016 print_usage (); |
5476
|
1017 |
|
1018 return retval; |
|
1019 } |
|
1020 |
|
1021 DEFUNX ("S_ISDIR", FS_ISDIR, args, , |
|
1022 "-*- texinfo -*-\n\ |
|
1023 @deftypefn {Built-in Function} {} S_ISDIR (@var{mode})\n\ |
|
1024 Return true if @var{mode} corresponds to a directory. The value\n\ |
|
1025 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ |
|
1026 @seealso{stat, lstat}\n\ |
|
1027 @end deftypefn") |
|
1028 { |
|
1029 octave_value retval = false; |
|
1030 |
|
1031 if (args.length () == 1) |
|
1032 { |
|
1033 double mode = args(0).double_value (); |
|
1034 |
|
1035 if (! error_state) |
|
1036 retval = file_stat::is_dir (static_cast<mode_t> (mode)); |
|
1037 else |
|
1038 error ("S_ISDIR: invalid mode value"); |
|
1039 } |
|
1040 else |
5823
|
1041 print_usage (); |
5476
|
1042 |
|
1043 return retval; |
|
1044 } |
|
1045 |
|
1046 DEFUNX ("S_ISCHR", FS_ISCHR, args, , |
|
1047 "-*- texinfo -*-\n\ |
|
1048 @deftypefn {Built-in Function} {} S_ISCHR (@var{mode})\n\ |
|
1049 Return true if @var{mode} corresponds to a character devicey. The value\n\ |
|
1050 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ |
|
1051 @seealso{stat, lstat}\n\ |
|
1052 @end deftypefn") |
|
1053 { |
|
1054 octave_value retval = false; |
|
1055 |
|
1056 if (args.length () == 1) |
|
1057 { |
|
1058 double mode = args(0).double_value (); |
|
1059 |
|
1060 if (! error_state) |
|
1061 retval = file_stat::is_chr (static_cast<mode_t> (mode)); |
|
1062 else |
|
1063 error ("S_ISCHR: invalid mode value"); |
|
1064 } |
|
1065 else |
5823
|
1066 print_usage (); |
5476
|
1067 |
|
1068 return retval; |
|
1069 } |
|
1070 |
|
1071 DEFUNX ("S_ISBLK", FS_ISBLK, args, , |
|
1072 "-*- texinfo -*-\n\ |
|
1073 @deftypefn {Built-in Function} {} S_ISBLK (@var{mode})\n\ |
|
1074 Return true if @var{mode} corresponds to a block device. The value\n\ |
|
1075 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ |
|
1076 @seealso{stat, lstat}\n\ |
|
1077 @end deftypefn") |
|
1078 { |
|
1079 octave_value retval = false; |
|
1080 |
|
1081 if (args.length () == 1) |
|
1082 { |
|
1083 double mode = args(0).double_value (); |
|
1084 |
|
1085 if (! error_state) |
|
1086 retval = file_stat::is_blk (static_cast<mode_t> (mode)); |
|
1087 else |
|
1088 error ("S_ISBLK: invalid mode value"); |
|
1089 } |
|
1090 else |
5823
|
1091 print_usage (); |
5476
|
1092 |
|
1093 return retval; |
|
1094 } |
|
1095 |
|
1096 DEFUNX ("S_ISFIFO", FS_ISFIFO, args, , |
|
1097 "-*- texinfo -*-\n\ |
|
1098 @deftypefn {Built-in Function} {} S_ISFIFO (@var{mode})\n\ |
|
1099 Return true if @var{mode} corresponds to a fifo. The value\n\ |
|
1100 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ |
|
1101 @seealso{stat, lstat}\n\ |
|
1102 @end deftypefn") |
|
1103 { |
|
1104 octave_value retval = false; |
|
1105 |
|
1106 if (args.length () == 1) |
|
1107 { |
|
1108 double mode = args(0).double_value (); |
|
1109 |
|
1110 if (! error_state) |
|
1111 retval = file_stat::is_fifo (static_cast<mode_t> (mode)); |
|
1112 else |
|
1113 error ("S_ISFIFO: invalid mode value"); |
|
1114 } |
|
1115 else |
5823
|
1116 print_usage (); |
5476
|
1117 |
|
1118 return retval; |
|
1119 } |
|
1120 |
|
1121 DEFUNX ("S_ISLNK", FS_ISLNK, args, , |
|
1122 "-*- texinfo -*-\n\ |
|
1123 @deftypefn {Built-in Function} {} S_ISLNK (@var{mode})\n\ |
|
1124 Return true if @var{mode} corresponds to a symbolic link. The value\n\ |
|
1125 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ |
|
1126 @seealso{stat, lstat}\n\ |
|
1127 @end deftypefn") |
|
1128 { |
|
1129 octave_value retval = false; |
|
1130 |
|
1131 if (args.length () == 1) |
|
1132 { |
|
1133 double mode = args(0).double_value (); |
|
1134 |
|
1135 if (! error_state) |
|
1136 retval = file_stat::is_lnk (static_cast<mode_t> (mode)); |
|
1137 else |
|
1138 error ("S_ISLNK: invalid mode value"); |
|
1139 } |
|
1140 else |
5823
|
1141 print_usage (); |
5476
|
1142 |
|
1143 return retval; |
|
1144 } |
|
1145 |
|
1146 DEFUNX ("S_ISSOCK", FS_ISSOCK, args, , |
|
1147 "-*- texinfo -*-\n\ |
|
1148 @deftypefn {Built-in Function} {} S_ISSOCK (@var{mode})\n\ |
|
1149 @seealso{stat, lstat}\n\ |
|
1150 @end deftypefn") |
|
1151 { |
|
1152 octave_value retval = false; |
|
1153 |
|
1154 if (args.length () == 1) |
|
1155 { |
|
1156 double mode = args(0).double_value (); |
|
1157 |
|
1158 if (! error_state) |
|
1159 retval = file_stat::is_sock (static_cast<mode_t> (mode)); |
|
1160 else |
|
1161 error ("S_ISSOCK: invalid mode value"); |
|
1162 } |
|
1163 else |
5823
|
1164 print_usage (); |
5476
|
1165 |
|
1166 return retval; |
|
1167 } |
|
1168 |
5547
|
1169 DEFUN (uname, args, , |
|
1170 "-*- texinfo -*-\n\ |
|
1171 @deftypefn {Built-in Function} {[@var{uts}, @var{err}, @var{msg}] =} uname ()\n\ |
|
1172 Return system information in the structure. For example,\n\ |
|
1173 \n\ |
|
1174 @example\n\ |
|
1175 @group\n\ |
|
1176 uname ()\n\ |
|
1177 @result{} @{\n\ |
5656
|
1178 sysname = x86_64\n\ |
|
1179 nodename = segfault\n\ |
|
1180 release = 2.6.15-1-amd64-k8-smp\n\ |
|
1181 version = Linux\n\ |
|
1182 machine = #2 SMP Thu Feb 23 04:57:49 UTC 2006\n\ |
5547
|
1183 @}\n\ |
|
1184 @end group\n\ |
|
1185 @end example\n\ |
|
1186 \n\ |
|
1187 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
|
1188 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ |
|
1189 system-dependent error message.\n\ |
|
1190 @end deftypefn") |
|
1191 { |
|
1192 octave_value_list retval; |
|
1193 |
|
1194 if (args.length () == 0) |
|
1195 { |
|
1196 octave_uname sysinfo; |
|
1197 |
|
1198 Octave_map m; |
|
1199 |
|
1200 m.assign ("sysname", sysinfo.sysname ()); |
|
1201 m.assign ("nodename", sysinfo.nodename ()); |
|
1202 m.assign ("release", sysinfo.release ()); |
|
1203 m.assign ("version", sysinfo.version ()); |
|
1204 m.assign ("machine", sysinfo.machine ()); |
|
1205 |
|
1206 retval(2) = sysinfo.message (); |
|
1207 retval(1) = sysinfo.error (); |
|
1208 retval(0) = m; |
|
1209 } |
|
1210 else |
5823
|
1211 print_usage (); |
5547
|
1212 |
|
1213 return retval; |
|
1214 } |
|
1215 |
2075
|
1216 DEFUN (unlink, args, , |
3301
|
1217 "-*- texinfo -*-\n\ |
|
1218 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} unlink (@var{file})\n\ |
|
1219 Delete the file named @var{file}.\n\ |
2075
|
1220 \n\ |
3301
|
1221 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
|
1222 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ |
|
1223 system-dependent error message.\n\ |
|
1224 @end deftypefn") |
2075
|
1225 { |
2669
|
1226 octave_value_list retval; |
|
1227 |
3523
|
1228 retval(1) = std::string (); |
4294
|
1229 retval(0) = -1; |
2075
|
1230 |
|
1231 int nargin = args.length (); |
|
1232 |
|
1233 if (nargin == 1) |
|
1234 { |
|
1235 if (args(0).is_string ()) |
|
1236 { |
3523
|
1237 std::string name = args(0).string_value (); |
2075
|
1238 |
3523
|
1239 std::string msg; |
2669
|
1240 |
2926
|
1241 int status = file_ops::unlink (name, msg); |
2669
|
1242 |
4233
|
1243 retval(0) = status; |
2937
|
1244 retval(1) = msg; |
2075
|
1245 } |
|
1246 else |
|
1247 error ("unlink: file name must be a string"); |
|
1248 } |
|
1249 else |
5823
|
1250 print_usage (); |
2075
|
1251 |
|
1252 return retval; |
|
1253 } |
|
1254 |
|
1255 DEFUN (waitpid, args, , |
3301
|
1256 "-*- texinfo -*-\n\ |
5453
|
1257 @deftypefn {Built-in Function} {[@var{pid}, @var{status}, @var{msg}] =} waitpid (@var{pid}, @var{options})\n\ |
3301
|
1258 Wait for process @var{pid} to terminate. The @var{pid} argument can be:\n\ |
2075
|
1259 \n\ |
3301
|
1260 @table @asis\n\ |
|
1261 @item @minus{}1\n\ |
|
1262 Wait for any child process.\n\ |
2075
|
1263 \n\ |
3301
|
1264 @item 0\n\ |
|
1265 Wait for any child process whose process group ID is equal to that of\n\ |
|
1266 the Octave interpreter process.\n\ |
2075
|
1267 \n\ |
3301
|
1268 @item > 0\n\ |
|
1269 Wait for termination of the child process with ID @var{pid}.\n\ |
|
1270 @end table\n\ |
|
1271 \n\ |
5453
|
1272 The @var{options} argument can be a bitwise OR of zero or more of\n\ |
|
1273 the following constants:\n\ |
2075
|
1274 \n\ |
5453
|
1275 @table @code\n\ |
3301
|
1276 @item 0\n\ |
|
1277 Wait until signal is received or a child process exits (this is the\n\ |
|
1278 default if the @var{options} argument is missing).\n\ |
|
1279 \n\ |
5453
|
1280 @item WNOHANG\n\ |
3301
|
1281 Do not hang if status is not immediately available.\n\ |
2075
|
1282 \n\ |
5453
|
1283 @item WUNTRACED\n\ |
3301
|
1284 Report the status of any child processes that are stopped, and whose\n\ |
|
1285 status has not yet been reported since they stopped.\n\ |
|
1286 \n\ |
5453
|
1287 @item WCONTINUED\n\ |
|
1288 Return if a stopped child has been resumed by delivery of @code{SIGCONT}.\n\ |
|
1289 This value may not be meaningful on all systems.\n\ |
3301
|
1290 @end table\n\ |
|
1291 \n\ |
|
1292 If the returned value of @var{pid} is greater than 0, it is the process\n\ |
|
1293 ID of the child process that exited. If an error occurs, @var{pid} will\n\ |
|
1294 be less than zero and @var{msg} will contain a system-dependent error\n\ |
7001
|
1295 message. The value of @var{status} contains additional system-dependent\n\ |
5453
|
1296 information about the subprocess that exited.\n\ |
7096
|
1297 @seealso{WCONTINUED, WCOREDUMP, WEXITSTATUS, WIFCONTINUED, WIFSIGNALED, WIFSTOPPED, WNOHANG, WSTOPSIG, WTERMSIG, WUNTRACED}\n\ |
3301
|
1298 @end deftypefn") |
2075
|
1299 { |
2669
|
1300 octave_value_list retval; |
|
1301 |
5453
|
1302 retval(2) = std::string (); |
|
1303 retval(1) = 0; |
4294
|
1304 retval(0) = -1; |
2075
|
1305 |
|
1306 int nargin = args.length (); |
|
1307 |
|
1308 if (nargin == 1 || nargin == 2) |
|
1309 { |
3202
|
1310 pid_t pid = args(0).int_value (true); |
2075
|
1311 |
|
1312 if (! error_state) |
|
1313 { |
3202
|
1314 int options = 0; |
2075
|
1315 |
3202
|
1316 if (args.length () == 2) |
5453
|
1317 options = args(1).int_value (true); |
2937
|
1318 |
3202
|
1319 if (! error_state) |
|
1320 { |
3523
|
1321 std::string msg; |
2669
|
1322 |
5453
|
1323 int status = 0; |
|
1324 |
|
1325 pid_t result = octave_syscalls::waitpid (pid, &status, options, msg); |
3202
|
1326 |
5453
|
1327 retval(0) = result; |
|
1328 retval(1) = status; |
|
1329 retval(2) = msg; |
2075
|
1330 } |
5453
|
1331 else |
|
1332 error ("waitpid: OPTIONS must be an integer"); |
2075
|
1333 } |
3202
|
1334 else |
|
1335 error ("waitpid: PID must be an integer value"); |
2075
|
1336 } |
|
1337 else |
5823
|
1338 print_usage (); |
2075
|
1339 |
|
1340 return retval; |
|
1341 } |
|
1342 |
5453
|
1343 DEFUNX ("WIFEXITED", FWIFEXITED, args, , |
|
1344 "-*- texinfo -*-\n\ |
|
1345 @deftypefn {Built-in Function} {} WIFEXITED (@var{status})\n\ |
|
1346 Given @var{status} from a call to @code{waitpid}, return true if the\n\ |
|
1347 child terminated normally.\n\ |
|
1348 @seealso{waitpid, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ |
5646
|
1349 @end deftypefn") |
5453
|
1350 { |
|
1351 octave_value retval = 0.0; |
|
1352 |
|
1353 #if defined (WIFEXITED) |
|
1354 if (args.length () == 1) |
|
1355 { |
|
1356 int status = args(0).int_value (); |
|
1357 |
|
1358 if (! error_state) |
|
1359 retval = WIFEXITED (status); |
|
1360 else |
|
1361 error ("WIFEXITED: expecting integer argument"); |
|
1362 } |
|
1363 #else |
|
1364 warning ("WIFEXITED always returns false in this version of Octave") |
|
1365 #endif |
|
1366 |
|
1367 return retval; |
|
1368 } |
|
1369 |
|
1370 DEFUNX ("WEXITSTATUS", FWEXITSTATUS, args, , |
|
1371 "-*- texinfo -*-\n\ |
|
1372 @deftypefn {Built-in Function} {} WEXITSTATUS (@var{status})\n\ |
|
1373 Given @var{status} from a call to @code{waitpid}, return the exit\n\ |
|
1374 status of the child. This function should only be employed if\n\ |
|
1375 @code{WIFEXITED} returned true.\n\ |
|
1376 @seealso{waitpid, WIFEXITED, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ |
|
1377 @end deftypefn") |
|
1378 { |
|
1379 octave_value retval = 0.0; |
|
1380 |
|
1381 #if defined (WEXITSTATUS) |
|
1382 if (args.length () == 1) |
|
1383 { |
|
1384 int status = args(0).int_value (); |
|
1385 |
|
1386 if (! error_state) |
|
1387 retval = WEXITSTATUS (status); |
|
1388 else |
|
1389 error ("WEXITSTATUS: expecting integer argument"); |
|
1390 } |
|
1391 #else |
|
1392 warning ("WEXITSTATUS always returns false in this version of Octave") |
|
1393 #endif |
|
1394 |
|
1395 return retval; |
|
1396 } |
|
1397 |
|
1398 DEFUNX ("WIFSIGNALED", FWIFSIGNALED, args, , |
|
1399 "-*- texinfo -*-\n\ |
|
1400 @deftypefn {Built-in Function} {} WIFSIGNALED (@var{status})\n\ |
|
1401 Given @var{status} from a call to @code{waitpid}, return true if the\n\ |
|
1402 child process was terminated by a signal.\n\ |
|
1403 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ |
|
1404 @end deftypefn") |
|
1405 { |
|
1406 octave_value retval = 0.0; |
|
1407 |
|
1408 #if defined (WIFSIGNALED) |
|
1409 if (args.length () == 1) |
|
1410 { |
|
1411 int status = args(0).int_value (); |
|
1412 |
|
1413 if (! error_state) |
|
1414 retval = WIFSIGNALED (status); |
|
1415 else |
|
1416 error ("WIFSIGNALED: expecting integer argument"); |
|
1417 } |
|
1418 #else |
5455
|
1419 warning ("WIFSIGNALED always returns false in this version of Octave"); |
5453
|
1420 #endif |
|
1421 |
|
1422 return retval; |
|
1423 } |
|
1424 |
|
1425 DEFUNX ("WTERMSIG", FWTERMSIG, args, , |
|
1426 "-*- texinfo -*-\n\ |
|
1427 @deftypefn {Built-in Function} {} WTERMSIG (@var{status})\n\ |
|
1428 Given @var{status} from a call to @code{waitpid}, return the number of\n\ |
|
1429 the signal that caused the child process to terminate. This function\n\ |
|
1430 should only be employed if @code{WIFSIGNALED} returned true.\n\ |
|
1431 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ |
|
1432 @end deftypefn") |
|
1433 { |
|
1434 octave_value retval = 0.0; |
|
1435 |
|
1436 #if defined (WTERMSIG) |
|
1437 if (args.length () == 1) |
|
1438 { |
|
1439 int status = args(0).int_value (); |
|
1440 |
|
1441 if (! error_state) |
|
1442 retval = WTERMSIG (status); |
|
1443 else |
|
1444 error ("WTERMSIG: expecting integer argument"); |
|
1445 } |
|
1446 #else |
5455
|
1447 warning ("WTERMSIG always returns false in this version of Octave"); |
5453
|
1448 #endif |
|
1449 |
|
1450 return retval; |
|
1451 } |
|
1452 |
|
1453 DEFUNX ("WCOREDUMP", FWCOREDUMP, args, , |
|
1454 "-*- texinfo -*-\n\ |
|
1455 @deftypefn {Built-in Function} {} WCOREDUMP (@var{status})\n\ |
|
1456 Given @var{status} from a call to @code{waitpid}, return true if the\n\ |
|
1457 child produced a core dump. This function should only be employed if\n\ |
|
1458 @code{WIFSIGNALED} returned true. The macro used to implement this\n\ |
|
1459 function is not specified in POSIX.1-2001 and is not available on some\n\ |
|
1460 Unix implementations (e.g., AIX, SunOS).\n\ |
|
1461 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ |
|
1462 @end deftypefn") |
|
1463 { |
|
1464 octave_value retval = 0.0; |
|
1465 |
|
1466 #if defined (WCOREDUMP) |
|
1467 if (args.length () == 1) |
|
1468 { |
|
1469 int status = args(0).int_value (); |
|
1470 |
|
1471 if (! error_state) |
|
1472 retval = WCOREDUMP (status); |
|
1473 else |
|
1474 error ("WCOREDUMP: expecting integer argument"); |
|
1475 } |
|
1476 #else |
5455
|
1477 warning ("WCOREDUMP always returns false in this version of Octave"); |
5453
|
1478 #endif |
|
1479 |
|
1480 return retval; |
|
1481 } |
|
1482 |
|
1483 DEFUNX ("WIFSTOPPED", FWIFSTOPPED, args, , |
|
1484 "-*- texinfo -*-\n\ |
|
1485 @deftypefn {Built-in Function} {} WIFSTOPPED (@var{status})\n\ |
|
1486 Given @var{status} from a call to @code{waitpid}, return true if the\n\ |
|
1487 child process was stopped by delivery of a signal; this is only\n\ |
|
1488 possible if the call was done using @code{WUNTRACED} or when the child\n\ |
|
1489 is being traced (see ptrace(2)).\n\ |
|
1490 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WSTOPSIG, WIFCONTINUED}\n\ |
|
1491 @end deftypefn") |
|
1492 { |
|
1493 octave_value retval = 0.0; |
|
1494 |
|
1495 #if defined (WIFSTOPPED) |
|
1496 if (args.length () == 1) |
|
1497 { |
|
1498 int status = args(0).int_value (); |
|
1499 |
|
1500 if (! error_state) |
|
1501 retval = WIFSTOPPED (status); |
|
1502 else |
|
1503 error ("WIFSTOPPED: expecting integer argument"); |
|
1504 } |
|
1505 #else |
5455
|
1506 warning ("WIFSTOPPED always returns false in this version of Octave"); |
5453
|
1507 #endif |
|
1508 |
|
1509 return retval; |
|
1510 } |
|
1511 |
|
1512 DEFUNX ("WSTOPSIG", FWSTOPSIG, args, , |
|
1513 "-*- texinfo -*-\n\ |
|
1514 @deftypefn {Built-in Function} {} WSTOPSIG (@var{status})\n\ |
|
1515 Given @var{status} from a call to @code{waitpid}, return the number of\n\ |
|
1516 the signal which caused the child to stop. This function should only\n\ |
|
1517 be employed if @code{WIFSTOPPED} returned true.\n\ |
|
1518 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WIFCONTINUED}\n\ |
|
1519 @end deftypefn") |
|
1520 { |
|
1521 octave_value retval = 0.0; |
|
1522 |
|
1523 #if defined (WSTOPSIG) |
|
1524 if (args.length () == 1) |
|
1525 { |
|
1526 int status = args(0).int_value (); |
|
1527 |
|
1528 if (! error_state) |
|
1529 retval = WSTOPSIG (status); |
|
1530 else |
|
1531 error ("WSTOPSIG: expecting integer argument"); |
|
1532 } |
|
1533 #else |
5455
|
1534 warning ("WSTOPSIG always returns false in this version of Octave"); |
5453
|
1535 #endif |
|
1536 |
|
1537 return retval; |
|
1538 } |
|
1539 |
|
1540 DEFUNX ("WIFCONTINUED", FWIFCONTINUED, args, , |
|
1541 "-*- texinfo -*-\n\ |
|
1542 @deftypefn {Built-in Function} {} WIFCONTINUED (@var{status})\n\ |
|
1543 Given @var{status} from a call to @code{waitpid}, return true if the\n\ |
|
1544 child process was resumed by delivery of @code{SIGCONT}.\n\ |
|
1545 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG}\n\ |
|
1546 @end deftypefn") |
|
1547 { |
|
1548 octave_value retval = 0.0; |
|
1549 |
|
1550 #if defined (WIFCONTINUED) |
|
1551 if (args.length () == 1) |
|
1552 { |
|
1553 int status = args(0).int_value (); |
|
1554 |
|
1555 if (! error_state) |
|
1556 retval = WIFCONTINUED (status); |
|
1557 else |
|
1558 error ("WIFCONTINUED: expecting integer argument"); |
|
1559 } |
|
1560 #else |
5455
|
1561 warning ("WIFCONTINUED always returns false in this version of Octave"); |
5453
|
1562 #endif |
|
1563 |
|
1564 return retval; |
|
1565 } |
|
1566 |
5138
|
1567 DEFUN (canonicalize_file_name, args, , |
|
1568 "-*- texinfo -*-\n\ |
|
1569 @deftypefn {Built-in Function} {[@var{cname}, @var{status}, @var{msg}]} canonicalize_file_name (@var{name})\n\ |
|
1570 Return the canonical name of file @var{name}.\n\ |
|
1571 @end deftypefn") |
|
1572 { |
|
1573 octave_value_list retval; |
|
1574 |
|
1575 if (args.length () == 1) |
|
1576 { |
|
1577 std::string name = args(0).string_value (); |
|
1578 |
|
1579 if (! error_state) |
|
1580 { |
|
1581 std::string msg; |
|
1582 |
|
1583 std::string result = file_ops::canonicalize_file_name (name, msg); |
|
1584 |
|
1585 retval(2) = msg; |
|
1586 retval(1) = msg.empty () ? 0 : -1; |
|
1587 retval(0) = result; |
|
1588 } |
|
1589 else |
|
1590 error ("canonicalize_file_name: argument must be a character string"); |
|
1591 } |
|
1592 else |
5823
|
1593 print_usage (); |
5138
|
1594 |
|
1595 return retval; |
|
1596 } |
|
1597 |
5749
|
1598 static octave_value |
7924
|
1599 const_value (const octave_value_list& args, int val) |
5749
|
1600 { |
|
1601 octave_value retval; |
|
1602 |
|
1603 int nargin = args.length (); |
|
1604 |
|
1605 if (nargin == 0) |
|
1606 retval = val; |
|
1607 else |
5823
|
1608 print_usage (); |
5749
|
1609 |
|
1610 return retval; |
|
1611 } |
|
1612 |
2075
|
1613 #if !defined (O_NONBLOCK) && defined (O_NDELAY) |
|
1614 #define O_NONBLOCK O_NDELAY |
|
1615 #endif |
|
1616 |
5749
|
1617 #if defined (F_DUPFD) |
|
1618 DEFUNX ("F_DUPFD", FF_DUPFD, args, , |
|
1619 "-*- texinfo -*-\n\ |
|
1620 @deftypefn {Built-in Function} {} F_DUPFD ()\n\ |
|
1621 Return the value required to request that @code{fcntl} return a\n\ |
|
1622 duplicate file descriptor.\n\ |
|
1623 @seealso{fcntl, F_GETFD, F_GETFL, F_SETFD, F_SETFL}\n\ |
|
1624 @end deftypefn") |
2075
|
1625 { |
7924
|
1626 return const_value (args, F_DUPFD); |
5749
|
1627 } |
2075
|
1628 #endif |
|
1629 |
|
1630 #if defined (F_GETFD) |
5749
|
1631 DEFUNX ("F_GETFD", FF_GETFD, args, , |
|
1632 "-*- texinfo -*-\n\ |
|
1633 @deftypefn {Built-in Function} {} F_GETFD ()\n\ |
|
1634 Return the value required to request that @code{fcntl} to return the\n\ |
|
1635 file descriptor flags.\n\ |
5333
|
1636 @seealso{fcntl, F_DUPFD, F_GETFL, F_SETFD, F_SETFL}\n\ |
5749
|
1637 @end deftypefn") |
|
1638 { |
7924
|
1639 return const_value (args, F_GETFD); |
5749
|
1640 } |
2075
|
1641 #endif |
|
1642 |
|
1643 #if defined (F_GETFL) |
5749
|
1644 DEFUNX ("F_GETFL", FF_GETFL, args, , |
|
1645 "-*- texinfo -*-\n\ |
|
1646 @deftypefn {Built-in Function} {} F_GETFL ()\n\ |
|
1647 Return the value required to request that @code{fcntl} to return the\n\ |
|
1648 file status flags.\n\ |
5333
|
1649 @seealso{fcntl, F_DUPFD, F_GETFD, F_SETFD, F_SETFL}\n\ |
5749
|
1650 @end deftypefn") |
|
1651 { |
7924
|
1652 return const_value (args, F_GETFL); |
5749
|
1653 } |
2075
|
1654 #endif |
|
1655 |
|
1656 #if defined (F_SETFD) |
5749
|
1657 DEFUNX ("F_SETFD", FF_SETFD, args, , |
|
1658 "-*- texinfo -*-\n\ |
|
1659 @deftypefn {Built-in Function} {} F_SETFD ()\n\ |
|
1660 Return the value required to request that @code{fcntl} to set the file\n\ |
|
1661 descriptor flags.\n\ |
5333
|
1662 @seealso{fcntl, F_DUPFD, F_GETFD, F_GETFL, F_SETFL}\n\ |
5749
|
1663 @end deftypefn") |
|
1664 { |
7924
|
1665 return const_value (args, F_SETFD); |
5749
|
1666 } |
2075
|
1667 #endif |
|
1668 |
|
1669 #if defined (F_SETFL) |
5749
|
1670 DEFUNX ("F_SETFL", FF_SETFL, args, , |
|
1671 "-*- texinfo -*-\n\ |
|
1672 @deftypefn {Built-in Function} {} F_SETFL ()\n\ |
|
1673 Return the value required to request that @code{fcntl} to set the file\n\ |
|
1674 status flags.\n\ |
5333
|
1675 @seealso{fcntl, F_DUPFD, F_GETFD, F_GETFL, F_SETFD}\n\ |
5749
|
1676 @end deftypefn") |
|
1677 { |
7924
|
1678 return const_value (args, F_SETFL); |
5749
|
1679 } |
2075
|
1680 #endif |
|
1681 |
|
1682 #if defined (O_APPEND) |
5749
|
1683 DEFUNX ("O_APPEND", FO_APPEND, args, , |
|
1684 "-*- texinfo -*-\n\ |
|
1685 @deftypefn {Built-in Function} {} O_APPEND ()\n\ |
|
1686 Return the numerical value of the file status flag that may be\n\ |
|
1687 returned by @code{fcntl} to indicate each write operation appends,\n\ |
|
1688 or that may be passed to @code{fcntl} to set the write mode to append.\ |
5333
|
1689 @seealso{fcntl, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749
|
1690 @end deftypefn") |
|
1691 { |
7924
|
1692 return const_value (args, O_APPEND); |
5749
|
1693 } |
2075
|
1694 #endif |
|
1695 |
2669
|
1696 #if defined (O_ASYNC) |
5749
|
1697 DEFUNX ("O_ASYNC", FO_ASYNC, args, , |
|
1698 "-*- texinfo -*-\n\ |
|
1699 @deftypefn {Built-in Function} {} O_ASYNC ()\n\ |
|
1700 Return the numerical value of the file status flag that may be\n\ |
|
1701 returned by @code{fcntl} to indicate asynchronous I/O.\n\ |
5333
|
1702 @seealso{fcntl, O_APPEND, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749
|
1703 @end deftypefn") |
|
1704 { |
7924
|
1705 return const_value (args, O_ASYNC); |
5749
|
1706 } |
2669
|
1707 #endif |
|
1708 |
2075
|
1709 #if defined (O_CREAT) |
5749
|
1710 DEFUNX ("O_CREAT", FO_CREAT, args, , |
|
1711 "-*- texinfo -*-\n\ |
|
1712 @deftypefn {Built-in Function} {} O_CREAT ()\n\ |
|
1713 Return the numerical value of the file status flag that may be\n\ |
|
1714 returned by @code{fcntl} to indicate that a file should be\n\ |
|
1715 created if it does not exist.\n\ |
5333
|
1716 @seealso{fcntl, O_APPEND, O_ASYNC, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749
|
1717 @end deftypefn") |
|
1718 { |
7924
|
1719 return const_value (args, O_CREAT); |
5749
|
1720 } |
2075
|
1721 #endif |
|
1722 |
|
1723 #if defined (O_EXCL) |
5749
|
1724 DEFUNX ("O_EXCL", FO_EXCL, args, , |
|
1725 "-*- texinfo -*-\n\ |
|
1726 @deftypefn {Built-in Function} {} O_EXCL ()\n\ |
|
1727 Return the numerical value of the file status flag that may be\n\ |
|
1728 returned by @code{fcntl} to indicate that file locking is used.\n\ |
5333
|
1729 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749
|
1730 @end deftypefn") |
|
1731 { |
7924
|
1732 return const_value (args, O_EXCL); |
5749
|
1733 } |
2075
|
1734 #endif |
|
1735 |
|
1736 #if defined (O_NONBLOCK) |
5749
|
1737 DEFUNX ("O_NONBLOCK", FO_NONBLOCK, args, , |
|
1738 "-*- texinfo -*-\n\ |
|
1739 @deftypefn {Built-in Function} {} O_NONBLOCK ()\n\ |
|
1740 Return the numerical value of the file status flag that may be\n\ |
|
1741 returned by @code{fcntl} to indicate that non-blocking I/O is in use,\n\ |
|
1742 or that may be passsed to @code{fcntl} to set non-blocking I/O.\n\ |
5333
|
1743 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749
|
1744 @end deftypefn") |
|
1745 { |
7924
|
1746 return const_value (args, O_NONBLOCK); |
5749
|
1747 } |
2075
|
1748 #endif |
|
1749 |
|
1750 #if defined (O_RDONLY) |
5749
|
1751 DEFUNX ("O_RDONLY", FO_RDONLY, args, , |
|
1752 "-*- texinfo -*-\n\ |
|
1753 @deftypefn {Built-in Function} {} O_RDONLY ()\n\ |
|
1754 Return the numerical value of the file status flag that may be\n\ |
|
1755 returned by @code{fcntl} to indicate that a file is open for\n\ |
|
1756 reading only.\n\ |
5333
|
1757 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749
|
1758 @end deftypefn") |
|
1759 { |
7924
|
1760 return const_value (args, O_RDONLY); |
5749
|
1761 } |
2075
|
1762 #endif |
|
1763 |
|
1764 #if defined (O_RDWR) |
5749
|
1765 DEFUNX ("O_RDWR", FO_RDWR, args, , |
|
1766 "-*- texinfo -*-\n\ |
|
1767 @deftypefn {Built-in Function} {} O_RDWR ()\n\ |
|
1768 Return the numerical value of the file status flag that may be\n\ |
|
1769 returned by @code{fcntl} to indicate that a file is open for both\n\ |
|
1770 reading and writing.\n\ |
5333
|
1771 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749
|
1772 @end deftypefn") |
|
1773 { |
7924
|
1774 return const_value (args, O_RDWR); |
5749
|
1775 } |
2075
|
1776 #endif |
|
1777 |
2669
|
1778 #if defined (O_SYNC) |
5749
|
1779 DEFUNX ("O_SYNC", FO_SYNC, args, , |
|
1780 "-*- texinfo -*-\n\ |
|
1781 @deftypefn {Built-in Function} {} O_SYNC ()\n\ |
|
1782 Return the numerical value of the file status flag that may be\n\ |
|
1783 returned by @code{fcntl} to indicate that a file is open for\n\ |
|
1784 synchronous I/O.\n\ |
5333
|
1785 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY}\n\ |
5749
|
1786 @end deftypefn") |
|
1787 { |
7924
|
1788 return const_value (args, O_SYNC); |
5749
|
1789 } |
2669
|
1790 #endif |
|
1791 |
2075
|
1792 #if defined (O_TRUNC) |
5749
|
1793 DEFUNX ("O_TRUNC", FO_TRUNC, args, , |
|
1794 "-*- texinfo -*-\n\ |
|
1795 @deftypefn {Built-in Variable} O_TRUNC ()\n\ |
|
1796 Return the numerical value of the file status flag that may be\n\ |
|
1797 returned by @code{fcntl} to indicate that if file exists, it should\n\ |
|
1798 be truncated when writing.\n\ |
5333
|
1799 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_WRONLY}\n\ |
5749
|
1800 @end deftypefn") |
|
1801 { |
7924
|
1802 return const_value (args, O_TRUNC); |
5749
|
1803 } |
2075
|
1804 #endif |
|
1805 |
|
1806 #if defined (O_WRONLY) |
5749
|
1807 DEFUNX ("O_WRONLY", FO_WRONLY, args, , |
|
1808 "-*- texinfo -*-\n\ |
|
1809 @deftypefn {Built-in Function} {} O_WRONLY ()\n\ |
|
1810 Return the numerical value of the file status flag that may be\n\ |
|
1811 returned by @code{fcntl} to indicate that a file is open for\n\ |
|
1812 writing only.\n\ |
5333
|
1813 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC}\n\ |
5749
|
1814 @end deftypefn") |
|
1815 { |
7924
|
1816 return const_value (args, O_WRONLY); |
5749
|
1817 } |
2075
|
1818 #endif |
3446
|
1819 |
5453
|
1820 #if !defined (WNOHANG) |
|
1821 #define WNOHANG 0 |
|
1822 #endif |
|
1823 |
5749
|
1824 DEFUNX ("WNOHANG", FWNOHANG, args, , |
|
1825 "-*- texinfo -*-\n\ |
|
1826 @deftypefn {Built-in Function} {} WNOHANG ()\n\ |
|
1827 Return the numerical value of the option argument that may be\n\ |
|
1828 passed to @code{waitpid} to indicate that it should return its\n\ |
|
1829 status immediately instead of waiting for a process to exit.\n\ |
5453
|
1830 @seealso{waitpid, WUNTRACED, WCONTINUE}\n\ |
5749
|
1831 @end deftypefn") |
|
1832 { |
7924
|
1833 return const_value (args, WNOHANG); |
5749
|
1834 } |
5453
|
1835 |
|
1836 #if !defined (WUNTRACED) |
|
1837 #define WUNTRACED 0 |
|
1838 #endif |
|
1839 |
5749
|
1840 DEFUNX ("WUNTRACED", FWUNTRACED, args, , |
|
1841 "-*- texinfo -*-\n\ |
|
1842 @deftypefn {Built-in Function} {} WUNTRACED ()\n\ |
|
1843 Return the numerical value of the option argument that may be\n\ |
|
1844 passed to @code{waitpid} to indicate that it should also return\n\ |
|
1845 if the child process has stopped but is not traced via the\n\ |
|
1846 @code{ptrace} system call\n\ |
5453
|
1847 @seealso{waitpid, WNOHANG, WCONTINUE}\n\ |
5749
|
1848 @end deftypefn") |
|
1849 { |
7924
|
1850 return const_value (args, WUNTRACED); |
5749
|
1851 } |
5453
|
1852 |
|
1853 #if !defined (WCONTINUE) |
|
1854 #define WCONTINUE 0 |
|
1855 #endif |
|
1856 |
5749
|
1857 DEFUNX ("WCONTINUE", FWCONTINUE, args, , |
|
1858 "-*- texinfo -*-\n\ |
|
1859 @deftypefn {Built-in Function} WCONINTUE ()\n\ |
|
1860 Return the numerical value of the option argument that may be\n\ |
|
1861 passed to @code{waitpid} to indicate that it should also return\n\ |
|
1862 if a stopped child has been resumed by delivery of a @code{SIGCONT}\n\ |
|
1863 signal.\n\ |
5453
|
1864 @seealso{waitpid, WNOHANG, WUNTRACED}\n\ |
5749
|
1865 @end deftypefn") |
|
1866 { |
7924
|
1867 return const_value (args, WCONTINUE); |
2075
|
1868 } |
|
1869 |
|
1870 /* |
|
1871 ;;; Local Variables: *** |
|
1872 ;;; mode: C++ *** |
|
1873 ;;; End: *** |
|
1874 */ |