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