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