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" |
2926
|
50 |
2075
|
51 #include "defun.h" |
|
52 #include "error.h" |
2078
|
53 #include "gripes.h" |
2075
|
54 #include "lo-utils.h" |
|
55 #include "oct-map.h" |
|
56 #include "oct-obj.h" |
|
57 #include "oct-stdstrm.h" |
|
58 #include "oct-stream.h" |
|
59 #include "sysdep.h" |
|
60 #include "utils.h" |
2366
|
61 #include "variables.h" |
2075
|
62 |
|
63 static Octave_map |
|
64 mk_stat_map (const file_stat& fs) |
|
65 { |
|
66 Octave_map m; |
|
67 |
4675
|
68 m.assign ("dev", static_cast<double> (fs.dev ())); |
|
69 m.assign ("ino", fs.ino ()); |
5476
|
70 m.assign ("mode", fs.mode ()); |
4675
|
71 m.assign ("modestr", fs.mode_as_string ()); |
|
72 m.assign ("nlink", fs.nlink ()); |
|
73 m.assign ("uid", fs.uid ()); |
|
74 m.assign ("gid", fs.gid ()); |
3887
|
75 #if defined (HAVE_STRUCT_STAT_ST_RDEV) |
4675
|
76 m.assign ("rdev", static_cast<double> (fs.rdev ())); |
2075
|
77 #endif |
4675
|
78 m.assign ("size", fs.size ()); |
|
79 m.assign ("atime", fs.atime ()); |
|
80 m.assign ("mtime", fs.mtime ()); |
|
81 m.assign ("ctime", fs.ctime ()); |
3887
|
82 #if defined (HAVE_STRUCT_STAT_ST_BLKSIZE) |
4675
|
83 m.assign ("blksize", fs.blksize ()); |
2075
|
84 #endif |
3887
|
85 #if defined (HAVE_STRUCT_STAT_ST_BLOCKS) |
4675
|
86 m.assign ("blocks", fs.blocks ()); |
2075
|
87 #endif |
|
88 |
|
89 return m; |
|
90 } |
|
91 |
2457
|
92 DEFUN (dup2, args, , |
3301
|
93 "-*- texinfo -*-\n\ |
|
94 @deftypefn {Built-in Function} {[@var{fid}, @var{msg}] =} dup2 (@var{old}, @var{new})\n\ |
2669
|
95 Duplicate a file descriptor.\n\ |
|
96 \n\ |
3301
|
97 If successful, @var{fid} is greater than zero and contains the new file\n\ |
|
98 ID. Otherwise, @var{fid} is negative and @var{msg} contains a\n\ |
|
99 system-dependent error message.\n\ |
|
100 @end deftypefn") |
2075
|
101 { |
2669
|
102 octave_value_list retval; |
|
103 |
3523
|
104 retval(1) = std::string (); |
4294
|
105 retval(0) = -1; |
2075
|
106 |
|
107 int nargin = args.length (); |
|
108 |
|
109 if (nargin == 2) |
|
110 { |
3341
|
111 octave_stream old_stream |
|
112 = octave_stream_list::lookup (args(0), "dup2"); |
2075
|
113 |
3341
|
114 if (! error_state) |
2075
|
115 { |
3341
|
116 octave_stream new_stream |
|
117 = octave_stream_list::lookup (args(1), "dup2"); |
2075
|
118 |
3341
|
119 if (! error_state) |
3145
|
120 { |
3341
|
121 int i_old = old_stream.file_number (); |
|
122 int i_new = new_stream.file_number (); |
2937
|
123 |
3341
|
124 if (i_old >= 0 && i_new >= 0) |
|
125 { |
3523
|
126 std::string msg; |
2669
|
127 |
3341
|
128 int status = octave_syscalls::dup2 (i_old, i_new, msg); |
|
129 |
4233
|
130 retval(0) = status; |
3341
|
131 retval(1) = msg; |
|
132 } |
2075
|
133 } |
|
134 } |
3145
|
135 else |
|
136 error ("dup2: invalid stream"); |
2075
|
137 } |
|
138 else |
|
139 print_usage ("dup2"); |
|
140 |
|
141 return retval; |
|
142 } |
|
143 |
2457
|
144 DEFUN (exec, args, , |
3301
|
145 "-*- texinfo -*-\n\ |
|
146 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} exec (@var{file}, @var{args})\n\ |
|
147 Replace current process with a new process. Calling @code{exec} without\n\ |
|
148 first calling @code{fork} will terminate your current Octave process and\n\ |
|
149 replace it with the program named by @var{file}. For example,\n\ |
2669
|
150 \n\ |
3301
|
151 @example\n\ |
|
152 exec (\"ls\" \"-l\")\n\ |
|
153 @end example\n\ |
2669
|
154 \n\ |
3301
|
155 @noindent\n\ |
|
156 will run @code{ls} and return you to your shell prompt.\n\ |
|
157 \n\ |
|
158 If successful, @code{exec} does not return. If @code{exec} does return,\n\ |
|
159 @var{err} will be nonzero, and @var{msg} will contain a system-dependent\n\ |
|
160 error message.\n\ |
|
161 @end deftypefn") |
2075
|
162 { |
2669
|
163 octave_value_list retval; |
|
164 |
3523
|
165 retval(1) = std::string (); |
4294
|
166 retval(0) = -1; |
2075
|
167 |
|
168 int nargin = args.length (); |
|
169 |
|
170 if (nargin == 1 || nargin == 2) |
|
171 { |
3523
|
172 std::string exec_file = args(0).string_value (); |
2075
|
173 |
|
174 if (! error_state) |
|
175 { |
2937
|
176 string_vector exec_args; |
2075
|
177 |
|
178 if (nargin == 2) |
|
179 { |
2937
|
180 string_vector tmp = args(1).all_strings (); |
2075
|
181 |
|
182 if (! error_state) |
|
183 { |
2937
|
184 int len = tmp.length (); |
2075
|
185 |
2937
|
186 exec_args.resize (len + 1); |
2075
|
187 |
2937
|
188 exec_args[0] = exec_file; |
2075
|
189 |
2937
|
190 for (int i = 0; i < len; i++) |
|
191 exec_args[i+1] = tmp[i]; |
2075
|
192 } |
|
193 else |
5138
|
194 error ("exec: arguments must be character strings"); |
2075
|
195 } |
|
196 else |
|
197 { |
2937
|
198 exec_args.resize (1); |
2075
|
199 |
2937
|
200 exec_args[0] = exec_file; |
2075
|
201 } |
|
202 |
|
203 if (! error_state) |
2669
|
204 { |
3523
|
205 std::string msg; |
2937
|
206 |
|
207 int status = octave_syscalls::execvp (exec_file, exec_args, msg); |
2669
|
208 |
4233
|
209 retval(0) = status; |
2937
|
210 retval(1) = msg; |
2669
|
211 } |
2075
|
212 } |
|
213 else |
|
214 error ("exec: first argument must be a string"); |
|
215 } |
|
216 else |
|
217 print_usage ("exec"); |
|
218 |
|
219 return retval; |
|
220 } |
|
221 |
2457
|
222 DEFUN (fcntl, args, , |
3301
|
223 "-*- texinfo -*-\n\ |
|
224 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} fcntl (@var{fid}, @var{request}, @var{arg})\n\ |
|
225 Change the properties of the open file @var{fid}. The following values\n\ |
|
226 may be passed as @var{request}:\n\ |
|
227 \n\ |
|
228 @vtable @code\n\ |
|
229 @item F_DUPFD\n\ |
|
230 Return a duplicate file descriptor.\n\ |
|
231 \n\ |
|
232 @item F_GETFD\n\ |
|
233 Return the file descriptor flags for @var{fid}.\n\ |
|
234 \n\ |
|
235 @item F_SETFD\n\ |
|
236 Set the file descriptor flags for @var{fid}.\n\ |
|
237 \n\ |
|
238 @item F_GETFL\n\ |
|
239 Return the file status flags for @var{fid}. The following codes may be\n\ |
|
240 returned (some of the flags may be undefined on some systems).\n\ |
|
241 \n\ |
|
242 @vtable @code\n\ |
|
243 @item O_RDONLY\n\ |
|
244 Open for reading only.\n\ |
|
245 \n\ |
|
246 @item O_WRONLY\n\ |
|
247 Open for writing only.\n\ |
2669
|
248 \n\ |
3301
|
249 @item O_RDWR\n\ |
|
250 Open for reading and writing.\n\ |
|
251 \n\ |
|
252 @item O_APPEND\n\ |
|
253 Append on each write.\n\ |
|
254 \n\ |
5040
|
255 @item O_CREAT\n\ |
|
256 Create the file if it does not exist.\n\ |
|
257 \n\ |
3301
|
258 @item O_NONBLOCK\n\ |
|
259 Nonblocking mode.\n\ |
|
260 \n\ |
|
261 @item O_SYNC\n\ |
|
262 Wait for writes to complete.\n\ |
2669
|
263 \n\ |
3301
|
264 @item O_ASYNC\n\ |
|
265 Asynchronous I/O.\n\ |
|
266 @end vtable\n\ |
|
267 \n\ |
|
268 @item F_SETFL\n\ |
|
269 Set the file status flags for @var{fid} to the value specified by\n\ |
|
270 @var{arg}. The only flags that can be changed are @code{O_APPEND} and\n\ |
|
271 @code{O_NONBLOCK}.\n\ |
|
272 @end vtable\n\ |
|
273 \n\ |
|
274 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
|
275 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ |
|
276 system-dependent error message.\n\ |
|
277 @end deftypefn") |
2075
|
278 { |
2669
|
279 octave_value_list retval; |
|
280 |
3523
|
281 retval(1) = std::string (); |
4294
|
282 retval(0) = -1; |
2075
|
283 |
|
284 int nargin = args.length (); |
|
285 |
|
286 if (nargin == 3) |
|
287 { |
3715
|
288 octave_stream strm = octave_stream_list::lookup (args (0), "fcntl"); |
2075
|
289 |
3202
|
290 if (! error_state) |
2075
|
291 { |
3715
|
292 int fid = strm.file_number (); |
|
293 |
|
294 int req = args(1).int_value (true); |
|
295 int arg = args(2).int_value (true); |
|
296 |
|
297 if (! error_state) |
2669
|
298 { |
3715
|
299 // XXX FIXME XXX -- Need better checking here? |
|
300 if (fid < 0) |
|
301 error ("fcntl: invalid file id"); |
|
302 else |
|
303 { |
|
304 std::string msg; |
2937
|
305 |
3715
|
306 int status = octave_syscalls::fcntl (fid, req, arg, msg); |
2669
|
307 |
4233
|
308 retval(0) = status; |
3715
|
309 retval(1) = msg; |
|
310 } |
2669
|
311 } |
2075
|
312 } |
|
313 else |
3202
|
314 error ("fcntl: file id, request, and argument must be integers"); |
2075
|
315 } |
|
316 else |
|
317 print_usage ("fcntl"); |
|
318 |
|
319 return retval; |
|
320 } |
|
321 |
2457
|
322 DEFUN (fork, args, , |
3301
|
323 "-*- texinfo -*-\n\ |
|
324 @deftypefn {Built-in Function} {[@var{pid}, @var{msg}] =} fork ()\n\ |
2669
|
325 Create a copy of the current process.\n\ |
|
326 \n\ |
3301
|
327 Fork can return one of the following values:\n\ |
|
328 \n\ |
|
329 @table @asis\n\ |
|
330 @item > 0\n\ |
|
331 You are in the parent process. The value returned from @code{fork} is\n\ |
|
332 the process id of the child process. You should probably arrange to\n\ |
|
333 wait for any child processes to exit.\n\ |
|
334 \n\ |
|
335 @item 0\n\ |
|
336 You are in the child process. You can call @code{exec} to start another\n\ |
|
337 process. If that fails, you should probably call @code{exit}.\n\ |
|
338 \n\ |
|
339 @item < 0\n\ |
|
340 The call to @code{fork} failed for some reason. You must take evasive\n\ |
|
341 action. A system dependent error message will be waiting in @var{msg}.\n\ |
|
342 @end table\n\ |
|
343 @end deftypefn") |
2075
|
344 { |
2669
|
345 octave_value_list retval; |
|
346 |
3523
|
347 retval(1) = std::string (); |
4294
|
348 retval(0) = -1; |
2075
|
349 |
|
350 int nargin = args.length (); |
|
351 |
|
352 if (nargin == 0) |
2475
|
353 { |
3523
|
354 std::string msg; |
2937
|
355 |
|
356 pid_t pid = octave_syscalls::fork (msg); |
2669
|
357 |
4233
|
358 retval(0) = pid; |
2937
|
359 retval(1) = msg; |
2475
|
360 } |
2075
|
361 else |
|
362 print_usage ("fork"); |
|
363 |
|
364 return retval; |
|
365 } |
|
366 |
2457
|
367 DEFUN (getpgrp, args, , |
3301
|
368 "-*- texinfo -*-\n\ |
|
369 @deftypefn {Built-in Function} {pgid =} getpgrp ()\n\ |
|
370 Return the process group id of the current process.\n\ |
|
371 @end deftypefn") |
2075
|
372 { |
2937
|
373 octave_value_list retval; |
|
374 |
3523
|
375 retval(1) = std::string (); |
4294
|
376 retval(0) = -1; |
2075
|
377 |
|
378 int nargin = args.length (); |
|
379 |
|
380 if (nargin == 0) |
2475
|
381 { |
3523
|
382 std::string msg; |
2937
|
383 |
4233
|
384 retval(0) = octave_syscalls::getpgrp (msg); |
2937
|
385 retval(1) = msg; |
2475
|
386 } |
2075
|
387 else |
|
388 print_usage ("getpgrp"); |
|
389 |
|
390 return retval; |
|
391 } |
|
392 |
2457
|
393 DEFUN (getpid, args, , |
3301
|
394 "-*- texinfo -*-\n\ |
|
395 @deftypefn {Built-in Function} {pid =} getpid ()\n\ |
|
396 Return the process id of the current process.\n\ |
|
397 @end deftypefn") |
2075
|
398 { |
4233
|
399 octave_value retval = -1; |
2075
|
400 |
|
401 int nargin = args.length (); |
|
402 |
|
403 if (nargin == 0) |
2937
|
404 retval = octave_syscalls::getpid (); |
2075
|
405 else |
|
406 print_usage ("getpid"); |
|
407 |
|
408 return retval; |
|
409 } |
|
410 |
2457
|
411 DEFUN (getppid, args, , |
3301
|
412 "-*- texinfo -*-\n\ |
|
413 @deftypefn {Built-in Function} {pid =} getppid ()\n\ |
|
414 Return the process id of the parent process.\n\ |
|
415 @end deftypefn") |
2075
|
416 { |
4233
|
417 octave_value retval = -1; |
2075
|
418 |
2475
|
419 int nargin = args.length (); |
|
420 |
|
421 if (nargin == 0) |
2937
|
422 retval = octave_syscalls::getppid (); |
2475
|
423 else |
|
424 print_usage ("getppid"); |
|
425 |
|
426 return retval; |
|
427 } |
|
428 |
|
429 DEFUN (getegid, args, , |
3301
|
430 "-*- texinfo -*-\n\ |
|
431 @deftypefn {Built-in Function} {egid =} getegid ()\n\ |
|
432 Return the effective group id of the current process.\n\ |
|
433 @end deftypefn") |
2475
|
434 { |
4233
|
435 octave_value retval = -1; |
2475
|
436 |
2075
|
437 int nargin = args.length (); |
|
438 |
|
439 if (nargin == 0) |
4254
|
440 retval = octave_syscalls::getegid (); |
2075
|
441 else |
2475
|
442 print_usage ("getegid"); |
|
443 |
|
444 return retval; |
|
445 } |
|
446 |
|
447 DEFUN (getgid, args, , |
3301
|
448 "-*- texinfo -*-\n\ |
|
449 @deftypefn {Built-in Function} {gid =} getgid ()\n\ |
|
450 Return the real group id of the current process.\n\ |
|
451 @end deftypefn") |
2475
|
452 { |
4233
|
453 octave_value retval = -1; |
2475
|
454 |
|
455 int nargin = args.length (); |
|
456 |
|
457 if (nargin == 0) |
4254
|
458 retval = octave_syscalls::getgid (); |
2475
|
459 else |
|
460 print_usage ("getgid"); |
2075
|
461 |
|
462 return retval; |
|
463 } |
|
464 |
2473
|
465 DEFUN (geteuid, args, , |
3301
|
466 "-*- texinfo -*-\n\ |
|
467 @deftypefn {Built-in Function} {euid =} geteuid ()\n\ |
|
468 Return the effective user id of the current process.\n\ |
|
469 @end deftypefn") |
2472
|
470 { |
4233
|
471 octave_value retval = -1; |
2472
|
472 |
|
473 int nargin = args.length (); |
|
474 |
|
475 if (nargin == 0) |
4254
|
476 retval = octave_syscalls::geteuid (); |
2472
|
477 else |
|
478 print_usage ("geteuid"); |
2473
|
479 |
|
480 return retval; |
2472
|
481 } |
|
482 |
2473
|
483 DEFUN (getuid, args, , |
3301
|
484 "-*- texinfo -*-\n\ |
|
485 @deftypefn {Built-in Function} {uid =} getuid ()\n\ |
|
486 Return the real user id of the current process.\n\ |
|
487 @end deftypefn") |
2472
|
488 { |
4233
|
489 octave_value retval = -1; |
2472
|
490 |
|
491 int nargin = args.length (); |
|
492 |
|
493 if (nargin == 0) |
4254
|
494 retval = octave_syscalls::getuid (); |
2472
|
495 else |
|
496 print_usage ("getuid"); |
2473
|
497 |
|
498 return retval; |
2472
|
499 } |
|
500 |
4294
|
501 DEFUN (kill, args, , |
4371
|
502 "-*- texinfo -*-\n\ |
4294
|
503 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} kill (@var{pid}, @var{sig})\n\ |
|
504 Send signal @var{sig} to process @var{pid}.\n\ |
|
505 \n\ |
|
506 If @var{pid} is positive, then signal @var{sig} is sent to @var{pid}.\n\ |
|
507 \n\ |
|
508 If @var{pid} is 0, then signal @var{sig} is sent to every process\n\ |
|
509 in the process group of the current process.\n\ |
|
510 \n\ |
|
511 If @var{pid} is -1, then signal @var{sig} is sent to every process\n\ |
|
512 except process 1.\n\ |
|
513 \n\ |
|
514 If @var{pid} is less than -1, then signal @var{sig} is sent to every\n\ |
|
515 process in the process group @var{-pid}.\n\ |
|
516 \n\ |
4371
|
517 If @var{sig} is 0, then no signal is sent, but error checking is still\n\ |
4294
|
518 performed.\n\ |
|
519 \n\ |
|
520 Return 0 if sucessful, otherwise return -1.\n\ |
|
521 @end deftypefn") |
|
522 { |
|
523 octave_value_list retval; |
|
524 |
|
525 retval(1) = std::string (); |
|
526 retval(0) = -1; |
|
527 |
|
528 if (args.length () == 2) |
|
529 { |
|
530 pid_t pid = args(0).int_value (true); |
|
531 |
|
532 if (! error_state) |
|
533 { |
|
534 int sig = args(1).int_value (true); |
|
535 |
|
536 if (! error_state) |
|
537 { |
|
538 std::string msg; |
|
539 |
|
540 int status = octave_syscalls::kill (pid, sig, msg); |
|
541 |
|
542 retval(1) = msg; |
|
543 retval(0) = status; |
|
544 } |
|
545 } |
|
546 } |
|
547 else |
|
548 print_usage ("kill"); |
|
549 |
|
550 return retval; |
|
551 } |
|
552 |
2075
|
553 DEFUN (lstat, args, , |
3458
|
554 "-*- texinfo -*-\n\ |
|
555 @deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{file})\n\ |
|
556 See stat.\n\ |
|
557 @end deftypefn") |
2075
|
558 { |
2263
|
559 octave_value_list retval; |
2075
|
560 |
|
561 if (args.length () == 1) |
|
562 { |
3523
|
563 std::string fname = file_ops::tilde_expand (args(0).string_value ()); |
2075
|
564 |
|
565 if (! error_state) |
|
566 { |
|
567 file_stat fs (fname, false); |
|
568 |
2263
|
569 if (fs) |
2262
|
570 { |
3523
|
571 retval(2) = std::string (); |
4294
|
572 retval(1) = 0; |
4233
|
573 retval(0) = mk_stat_map (fs); |
2262
|
574 } |
|
575 else |
|
576 { |
|
577 retval(2) = fs.error (); |
4294
|
578 retval(1) = -1; |
2262
|
579 retval(0) = Matrix (); |
|
580 } |
2075
|
581 } |
|
582 } |
|
583 else |
|
584 print_usage ("lstat"); |
|
585 |
|
586 return retval; |
|
587 } |
|
588 |
3301
|
589 |
|
590 |
2075
|
591 DEFUN (mkfifo, args, , |
3345
|
592 "-*- texinfo -*-\n\ |
4825
|
593 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} mkfifo (@var{name}, @var{mode})\n\ |
4928
|
594 Create a @var{fifo} special file named @var{name} with file mode @var{mode}\n\ |
2075
|
595 \n\ |
3301
|
596 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
|
597 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ |
|
598 system-dependent error message.\n\ |
|
599 @end deftypefn") |
2075
|
600 { |
2669
|
601 octave_value_list retval; |
|
602 |
3523
|
603 retval(1) = std::string (); |
4294
|
604 retval(0) = -1; |
2075
|
605 |
|
606 int nargin = args.length (); |
|
607 |
|
608 if (nargin == 2) |
|
609 { |
|
610 if (args(0).is_string ()) |
|
611 { |
3523
|
612 std::string name = args(0).string_value (); |
2075
|
613 |
|
614 if (args(1).is_scalar_type ()) |
|
615 { |
4254
|
616 long mode = args(1).long_value (); |
2075
|
617 |
4254
|
618 if (! error_state) |
|
619 { |
|
620 std::string msg; |
|
621 |
|
622 int status = file_ops::mkfifo (name, mode, msg); |
2669
|
623 |
4254
|
624 retval(0) = status; |
2669
|
625 |
4254
|
626 if (status < 0) |
|
627 retval(1) = msg; |
|
628 } |
|
629 else |
|
630 error ("mkfifo: invalid MODE"); |
2075
|
631 } |
|
632 else |
|
633 error ("mkfifo: MODE must be an integer"); |
|
634 } |
|
635 else |
|
636 error ("mkfifo: file name must be a string"); |
|
637 } |
|
638 else |
|
639 print_usage ("mkfifo"); |
|
640 |
|
641 return retval; |
|
642 } |
|
643 |
|
644 DEFUN (pipe, args, , |
3301
|
645 "-*- texinfo -*-\n\ |
|
646 @deftypefn {Built-in Function} {[@var{file_ids}, @var{err}, @var{msg}] =} pipe ()\n\ |
|
647 Create a pipe and return the vector @var{file_ids}, which corresponding\n\ |
|
648 to the reading and writing ends of the pipe.\n\ |
2669
|
649 \n\ |
3301
|
650 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
|
651 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ |
|
652 system-dependent error message.\n\ |
|
653 @end deftypefn") |
2075
|
654 { |
2669
|
655 octave_value_list retval; |
|
656 |
3523
|
657 retval(2) = std::string (); |
4294
|
658 retval(1) = -1; |
2669
|
659 retval(0) = Matrix (); |
2075
|
660 |
|
661 int nargin = args.length (); |
|
662 |
|
663 if (nargin == 0) |
|
664 { |
|
665 int fid[2]; |
|
666 |
3523
|
667 std::string msg; |
2937
|
668 |
|
669 int status = octave_syscalls::pipe (fid, msg); |
2669
|
670 |
|
671 if (status < 0) |
2937
|
672 retval(2) = msg; |
2669
|
673 else |
2075
|
674 { |
3340
|
675 FILE *ifile = fdopen (fid[0], "r"); |
|
676 FILE *ofile = fdopen (fid[1], "w"); |
2075
|
677 |
4327
|
678 std::string nm; |
|
679 |
|
680 octave_stream is = octave_stdiostream::create (nm, ifile, |
|
681 std::ios::in); |
|
682 |
|
683 octave_stream os = octave_stdiostream::create (nm, ofile, |
|
684 std::ios::out); |
2075
|
685 |
2902
|
686 octave_value_list file_ids; |
2075
|
687 |
2902
|
688 file_ids(1) = octave_stream_list::insert (os); |
|
689 file_ids(0) = octave_stream_list::insert (is); |
2075
|
690 |
4233
|
691 retval(1) = status; |
2902
|
692 retval(0) = octave_value (file_ids); |
2669
|
693 } |
2075
|
694 } |
|
695 else |
|
696 print_usage ("pipe"); |
|
697 |
|
698 return retval; |
|
699 } |
|
700 |
|
701 DEFUN (stat, args, , |
3301
|
702 "-*- texinfo -*-\n\ |
|
703 @deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} stat (@var{file})\n\ |
|
704 @deftypefnx {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{file})\n\ |
|
705 Return a structure @var{s} containing the following information about\n\ |
|
706 @var{file}.\n\ |
|
707 \n\ |
|
708 @table @code\n\ |
|
709 @item dev\n\ |
|
710 ID of device containing a directory entry for this file.\n\ |
|
711 \n\ |
|
712 @item ino\n\ |
|
713 File number of the file.\n\ |
|
714 \n\ |
5476
|
715 @item mode\n\ |
|
716 File mode, as an integer. Use the functions @code{S_ISREG},\n\ |
|
717 @code{S_ISDIR}, @code{S_ISCHR}, @code{S_ISBLK}, @code{S_ISFIFO},\n\ |
|
718 @code{S_ISLNK}, or @code{S_ISSOCK} to extract information from this\n\ |
|
719 value.\n\ |
|
720 \n\ |
3301
|
721 @item modestr\n\ |
|
722 File mode, as a string of ten letters or dashes as would be returned by\n\ |
|
723 @kbd{ls -l}.\n\ |
|
724 \n\ |
|
725 @item nlink\n\ |
|
726 Number of links.\n\ |
2075
|
727 \n\ |
3301
|
728 @item uid\n\ |
|
729 User ID of file's owner.\n\ |
|
730 \n\ |
|
731 @item gid\n\ |
|
732 Group ID of file's group.\n\ |
|
733 \n\ |
|
734 @item rdev\n\ |
|
735 ID of device for block or character special files.\n\ |
|
736 \n\ |
|
737 @item size\n\ |
|
738 Size in bytes.\n\ |
|
739 \n\ |
|
740 @item atime\n\ |
|
741 Time of last access in the same form as time values returned from\n\ |
|
742 @code{time}. @xref{Timing Utilities}.\n\ |
|
743 \n\ |
|
744 @item mtime\n\ |
|
745 Time of last modification in the same form as time values returned from\n\ |
|
746 @code{time}. @xref{Timing Utilities}.\n\ |
2075
|
747 \n\ |
3301
|
748 @item ctime\n\ |
|
749 Time of last file status change in the same form as time values\n\ |
|
750 returned from @code{time}. @xref{Timing Utilities}.\n\ |
|
751 \n\ |
|
752 @item blksize\n\ |
|
753 Size of blocks in the file.\n\ |
|
754 \n\ |
|
755 @item blocks\n\ |
|
756 Number of blocks allocated for file.\n\ |
|
757 @end table\n\ |
|
758 \n\ |
|
759 If the call is successful @var{err} is 0 and @var{msg} is an empty\n\ |
|
760 string. If the file does not exist, or some other error occurs, @var{s}\n\ |
|
761 is an empty matrix, @var{err} is @minus{}1, and @var{msg} contains the\n\ |
|
762 corresponding system error message.\n\ |
|
763 \n\ |
|
764 If @var{file} is a symbolic link, @code{stat} will return information\n\ |
|
765 about the actual file the is referenced by the link. Use @code{lstat}\n\ |
|
766 if you want information about the symbolic link itself.\n\ |
|
767 \n\ |
|
768 For example,\n\ |
2075
|
769 \n\ |
3301
|
770 @example\n\ |
|
771 @group\n\ |
|
772 [s, err, msg] = stat (\"/vmlinuz\")\n\ |
|
773 @result{} s =\n\ |
|
774 @{\n\ |
|
775 atime = 855399756\n\ |
|
776 rdev = 0\n\ |
|
777 ctime = 847219094\n\ |
|
778 uid = 0\n\ |
|
779 size = 389218\n\ |
|
780 blksize = 4096\n\ |
|
781 mtime = 847219094\n\ |
|
782 gid = 6\n\ |
|
783 nlink = 1\n\ |
|
784 blocks = 768\n\ |
5476
|
785 mode = -rw-r--r--\n\ |
3301
|
786 modestr = -rw-r--r--\n\ |
|
787 ino = 9316\n\ |
|
788 dev = 2049\n\ |
|
789 @}\n\ |
|
790 @result{} err = 0\n\ |
|
791 @result{} msg = \n\ |
|
792 @end group\n\ |
|
793 @end example\n\ |
|
794 @end deftypefn") |
2075
|
795 { |
2262
|
796 octave_value_list retval; |
2075
|
797 |
|
798 if (args.length () == 1) |
|
799 { |
3523
|
800 std::string fname = file_ops::tilde_expand (args(0).string_value ()); |
2075
|
801 |
|
802 if (! error_state) |
|
803 { |
|
804 file_stat fs (fname); |
|
805 |
|
806 if (fs) |
2262
|
807 { |
3523
|
808 retval(2) = std::string (); |
4294
|
809 retval(1) = 0; |
2262
|
810 retval(0) = octave_value (mk_stat_map (fs)); |
|
811 } |
|
812 else |
|
813 { |
|
814 retval(2) = fs.error (); |
4294
|
815 retval(1) = -1; |
2262
|
816 retval(0) = Matrix (); |
|
817 } |
2075
|
818 } |
|
819 } |
|
820 else |
|
821 print_usage ("stat"); |
|
822 |
|
823 return retval; |
|
824 } |
|
825 |
5476
|
826 DEFUNX ("S_ISREG", FS_ISREG, args, , |
|
827 "-*- texinfo -*-\n\ |
|
828 @deftypefn {Built-in Function} {} S_ISREG (@var{mode})\n\ |
|
829 Return true if @var{mode} corresponds to a regular file. The value\n\ |
|
830 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ |
|
831 @seealso{stat, lstat}\n\ |
|
832 @end deftypefn") |
|
833 { |
|
834 octave_value retval = false; |
|
835 |
|
836 if (args.length () == 1) |
|
837 { |
|
838 double mode = args(0).double_value (); |
|
839 |
|
840 if (! error_state) |
|
841 retval = file_stat::is_reg (static_cast<mode_t> (mode)); |
|
842 else |
|
843 error ("S_ISREG: invalid mode value"); |
|
844 } |
|
845 else |
|
846 print_usage ("S_ISREG"); |
|
847 |
|
848 return retval; |
|
849 } |
|
850 |
|
851 DEFUNX ("S_ISDIR", FS_ISDIR, args, , |
|
852 "-*- texinfo -*-\n\ |
|
853 @deftypefn {Built-in Function} {} S_ISDIR (@var{mode})\n\ |
|
854 Return true if @var{mode} corresponds to a directory. The value\n\ |
|
855 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ |
|
856 @seealso{stat, lstat}\n\ |
|
857 @end deftypefn") |
|
858 { |
|
859 octave_value retval = false; |
|
860 |
|
861 if (args.length () == 1) |
|
862 { |
|
863 double mode = args(0).double_value (); |
|
864 |
|
865 if (! error_state) |
|
866 retval = file_stat::is_dir (static_cast<mode_t> (mode)); |
|
867 else |
|
868 error ("S_ISDIR: invalid mode value"); |
|
869 } |
|
870 else |
|
871 print_usage ("S_ISDIR"); |
|
872 |
|
873 return retval; |
|
874 } |
|
875 |
|
876 DEFUNX ("S_ISCHR", FS_ISCHR, args, , |
|
877 "-*- texinfo -*-\n\ |
|
878 @deftypefn {Built-in Function} {} S_ISCHR (@var{mode})\n\ |
|
879 Return true if @var{mode} corresponds to a character devicey. The value\n\ |
|
880 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ |
|
881 @seealso{stat, lstat}\n\ |
|
882 @end deftypefn") |
|
883 { |
|
884 octave_value retval = false; |
|
885 |
|
886 if (args.length () == 1) |
|
887 { |
|
888 double mode = args(0).double_value (); |
|
889 |
|
890 if (! error_state) |
|
891 retval = file_stat::is_chr (static_cast<mode_t> (mode)); |
|
892 else |
|
893 error ("S_ISCHR: invalid mode value"); |
|
894 } |
|
895 else |
|
896 print_usage ("S_ISCHR"); |
|
897 |
|
898 return retval; |
|
899 } |
|
900 |
|
901 DEFUNX ("S_ISBLK", FS_ISBLK, args, , |
|
902 "-*- texinfo -*-\n\ |
|
903 @deftypefn {Built-in Function} {} S_ISBLK (@var{mode})\n\ |
|
904 Return true if @var{mode} corresponds to a block device. The value\n\ |
|
905 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ |
|
906 @seealso{stat, lstat}\n\ |
|
907 @end deftypefn") |
|
908 { |
|
909 octave_value retval = false; |
|
910 |
|
911 if (args.length () == 1) |
|
912 { |
|
913 double mode = args(0).double_value (); |
|
914 |
|
915 if (! error_state) |
|
916 retval = file_stat::is_blk (static_cast<mode_t> (mode)); |
|
917 else |
|
918 error ("S_ISBLK: invalid mode value"); |
|
919 } |
|
920 else |
|
921 print_usage ("S_ISBLK"); |
|
922 |
|
923 return retval; |
|
924 } |
|
925 |
|
926 DEFUNX ("S_ISFIFO", FS_ISFIFO, args, , |
|
927 "-*- texinfo -*-\n\ |
|
928 @deftypefn {Built-in Function} {} S_ISFIFO (@var{mode})\n\ |
|
929 Return true if @var{mode} corresponds to a fifo. The value\n\ |
|
930 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ |
|
931 @seealso{stat, lstat}\n\ |
|
932 @end deftypefn") |
|
933 { |
|
934 octave_value retval = false; |
|
935 |
|
936 if (args.length () == 1) |
|
937 { |
|
938 double mode = args(0).double_value (); |
|
939 |
|
940 if (! error_state) |
|
941 retval = file_stat::is_fifo (static_cast<mode_t> (mode)); |
|
942 else |
|
943 error ("S_ISFIFO: invalid mode value"); |
|
944 } |
|
945 else |
|
946 print_usage ("S_ISFIFO"); |
|
947 |
|
948 return retval; |
|
949 } |
|
950 |
|
951 DEFUNX ("S_ISLNK", FS_ISLNK, args, , |
|
952 "-*- texinfo -*-\n\ |
|
953 @deftypefn {Built-in Function} {} S_ISLNK (@var{mode})\n\ |
|
954 Return true if @var{mode} corresponds to a symbolic link. The value\n\ |
|
955 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ |
|
956 @seealso{stat, lstat}\n\ |
|
957 @end deftypefn") |
|
958 { |
|
959 octave_value retval = false; |
|
960 |
|
961 if (args.length () == 1) |
|
962 { |
|
963 double mode = args(0).double_value (); |
|
964 |
|
965 if (! error_state) |
|
966 retval = file_stat::is_lnk (static_cast<mode_t> (mode)); |
|
967 else |
|
968 error ("S_ISLNK: invalid mode value"); |
|
969 } |
|
970 else |
|
971 print_usage ("S_ISLNK"); |
|
972 |
|
973 return retval; |
|
974 } |
|
975 |
|
976 DEFUNX ("S_ISSOCK", FS_ISSOCK, args, , |
|
977 "-*- texinfo -*-\n\ |
|
978 @deftypefn {Built-in Function} {} S_ISSOCK (@var{mode})\n\ |
|
979 @seealso{stat, lstat}\n\ |
|
980 @end deftypefn") |
|
981 { |
|
982 octave_value retval = false; |
|
983 |
|
984 if (args.length () == 1) |
|
985 { |
|
986 double mode = args(0).double_value (); |
|
987 |
|
988 if (! error_state) |
|
989 retval = file_stat::is_sock (static_cast<mode_t> (mode)); |
|
990 else |
|
991 error ("S_ISSOCK: invalid mode value"); |
|
992 } |
|
993 else |
|
994 print_usage ("S_ISSOCK"); |
|
995 |
|
996 return retval; |
|
997 } |
|
998 |
2075
|
999 DEFUN (unlink, args, , |
3301
|
1000 "-*- texinfo -*-\n\ |
|
1001 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} unlink (@var{file})\n\ |
|
1002 Delete the file named @var{file}.\n\ |
2075
|
1003 \n\ |
3301
|
1004 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
|
1005 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ |
|
1006 system-dependent error message.\n\ |
|
1007 @end deftypefn") |
2075
|
1008 { |
2669
|
1009 octave_value_list retval; |
|
1010 |
3523
|
1011 retval(1) = std::string (); |
4294
|
1012 retval(0) = -1; |
2075
|
1013 |
|
1014 int nargin = args.length (); |
|
1015 |
|
1016 if (nargin == 1) |
|
1017 { |
|
1018 if (args(0).is_string ()) |
|
1019 { |
3523
|
1020 std::string name = args(0).string_value (); |
2075
|
1021 |
3523
|
1022 std::string msg; |
2669
|
1023 |
2926
|
1024 int status = file_ops::unlink (name, msg); |
2669
|
1025 |
4233
|
1026 retval(0) = status; |
2937
|
1027 retval(1) = msg; |
2075
|
1028 } |
|
1029 else |
|
1030 error ("unlink: file name must be a string"); |
|
1031 } |
|
1032 else |
|
1033 print_usage ("unlink"); |
|
1034 |
|
1035 return retval; |
|
1036 } |
|
1037 |
|
1038 DEFUN (waitpid, args, , |
3301
|
1039 "-*- texinfo -*-\n\ |
5453
|
1040 @deftypefn {Built-in Function} {[@var{pid}, @var{status}, @var{msg}] =} waitpid (@var{pid}, @var{options})\n\ |
3301
|
1041 Wait for process @var{pid} to terminate. The @var{pid} argument can be:\n\ |
2075
|
1042 \n\ |
3301
|
1043 @table @asis\n\ |
|
1044 @item @minus{}1\n\ |
|
1045 Wait for any child process.\n\ |
2075
|
1046 \n\ |
3301
|
1047 @item 0\n\ |
|
1048 Wait for any child process whose process group ID is equal to that of\n\ |
|
1049 the Octave interpreter process.\n\ |
2075
|
1050 \n\ |
3301
|
1051 @item > 0\n\ |
|
1052 Wait for termination of the child process with ID @var{pid}.\n\ |
|
1053 @end table\n\ |
|
1054 \n\ |
5453
|
1055 The @var{options} argument can be a bitwise OR of zero or more of\n\ |
|
1056 the following constants:\n\ |
2075
|
1057 \n\ |
5453
|
1058 @table @code\n\ |
3301
|
1059 @item 0\n\ |
|
1060 Wait until signal is received or a child process exits (this is the\n\ |
|
1061 default if the @var{options} argument is missing).\n\ |
|
1062 \n\ |
5453
|
1063 @item WNOHANG\n\ |
3301
|
1064 Do not hang if status is not immediately available.\n\ |
2075
|
1065 \n\ |
5453
|
1066 @item WUNTRACED\n\ |
3301
|
1067 Report the status of any child processes that are stopped, and whose\n\ |
|
1068 status has not yet been reported since they stopped.\n\ |
|
1069 \n\ |
5453
|
1070 @item WCONTINUED\n\ |
|
1071 Return if a stopped child has been resumed by delivery of @code{SIGCONT}.\n\ |
|
1072 This value may not be meaningful on all systems.\n\ |
3301
|
1073 @end table\n\ |
|
1074 \n\ |
|
1075 If the returned value of @var{pid} is greater than 0, it is the process\n\ |
|
1076 ID of the child process that exited. If an error occurs, @var{pid} will\n\ |
|
1077 be less than zero and @var{msg} will contain a system-dependent error\n\ |
5453
|
1078 message. The value of @var{status} contains additional system-depenent\n\ |
|
1079 information about the subprocess that exited.\n\ |
|
1080 @seealso{WNOHANG, WUNTRACED, WCONTINUED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ |
3301
|
1081 @end deftypefn") |
2075
|
1082 { |
2669
|
1083 octave_value_list retval; |
|
1084 |
5453
|
1085 retval(2) = std::string (); |
|
1086 retval(1) = 0; |
4294
|
1087 retval(0) = -1; |
2075
|
1088 |
|
1089 int nargin = args.length (); |
|
1090 |
|
1091 if (nargin == 1 || nargin == 2) |
|
1092 { |
3202
|
1093 pid_t pid = args(0).int_value (true); |
2075
|
1094 |
|
1095 if (! error_state) |
|
1096 { |
3202
|
1097 int options = 0; |
2075
|
1098 |
3202
|
1099 if (args.length () == 2) |
5453
|
1100 options = args(1).int_value (true); |
2937
|
1101 |
3202
|
1102 if (! error_state) |
|
1103 { |
3523
|
1104 std::string msg; |
2669
|
1105 |
5453
|
1106 int status = 0; |
|
1107 |
|
1108 pid_t result = octave_syscalls::waitpid (pid, &status, options, msg); |
3202
|
1109 |
5453
|
1110 retval(0) = result; |
|
1111 retval(1) = status; |
|
1112 retval(2) = msg; |
2075
|
1113 } |
5453
|
1114 else |
|
1115 error ("waitpid: OPTIONS must be an integer"); |
2075
|
1116 } |
3202
|
1117 else |
|
1118 error ("waitpid: PID must be an integer value"); |
2075
|
1119 } |
|
1120 else |
|
1121 print_usage ("waitpid"); |
|
1122 |
|
1123 return retval; |
|
1124 } |
|
1125 |
5453
|
1126 DEFUNX ("WIFEXITED", FWIFEXITED, args, , |
|
1127 "-*- texinfo -*-\n\ |
|
1128 @deftypefn {Built-in Function} {} WIFEXITED (@var{status})\n\ |
|
1129 Given @var{status} from a call to @code{waitpid}, return true if the\n\ |
|
1130 child terminated normally.\n\ |
|
1131 @seealso{waitpid, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ |
|
1132 @end deftypefn\n") |
|
1133 { |
|
1134 octave_value retval = 0.0; |
|
1135 |
|
1136 #if defined (WIFEXITED) |
|
1137 if (args.length () == 1) |
|
1138 { |
|
1139 int status = args(0).int_value (); |
|
1140 |
|
1141 if (! error_state) |
|
1142 retval = WIFEXITED (status); |
|
1143 else |
|
1144 error ("WIFEXITED: expecting integer argument"); |
|
1145 } |
|
1146 #else |
|
1147 warning ("WIFEXITED always returns false in this version of Octave") |
|
1148 #endif |
|
1149 |
|
1150 return retval; |
|
1151 } |
|
1152 |
|
1153 DEFUNX ("WEXITSTATUS", FWEXITSTATUS, args, , |
|
1154 "-*- texinfo -*-\n\ |
|
1155 @deftypefn {Built-in Function} {} WEXITSTATUS (@var{status})\n\ |
|
1156 Given @var{status} from a call to @code{waitpid}, return the exit\n\ |
|
1157 status of the child. This function should only be employed if\n\ |
|
1158 @code{WIFEXITED} returned true.\n\ |
|
1159 @seealso{waitpid, WIFEXITED, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ |
|
1160 @end deftypefn") |
|
1161 { |
|
1162 octave_value retval = 0.0; |
|
1163 |
|
1164 #if defined (WEXITSTATUS) |
|
1165 if (args.length () == 1) |
|
1166 { |
|
1167 int status = args(0).int_value (); |
|
1168 |
|
1169 if (! error_state) |
|
1170 retval = WEXITSTATUS (status); |
|
1171 else |
|
1172 error ("WEXITSTATUS: expecting integer argument"); |
|
1173 } |
|
1174 #else |
|
1175 warning ("WEXITSTATUS always returns false in this version of Octave") |
|
1176 #endif |
|
1177 |
|
1178 return retval; |
|
1179 } |
|
1180 |
|
1181 DEFUNX ("WIFSIGNALED", FWIFSIGNALED, args, , |
|
1182 "-*- texinfo -*-\n\ |
|
1183 @deftypefn {Built-in Function} {} WIFSIGNALED (@var{status})\n\ |
|
1184 Given @var{status} from a call to @code{waitpid}, return true if the\n\ |
|
1185 child process was terminated by a signal.\n\ |
|
1186 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ |
|
1187 @end deftypefn") |
|
1188 { |
|
1189 octave_value retval = 0.0; |
|
1190 |
|
1191 #if defined (WIFSIGNALED) |
|
1192 if (args.length () == 1) |
|
1193 { |
|
1194 int status = args(0).int_value (); |
|
1195 |
|
1196 if (! error_state) |
|
1197 retval = WIFSIGNALED (status); |
|
1198 else |
|
1199 error ("WIFSIGNALED: expecting integer argument"); |
|
1200 } |
|
1201 #else |
5455
|
1202 warning ("WIFSIGNALED always returns false in this version of Octave"); |
5453
|
1203 #endif |
|
1204 |
|
1205 return retval; |
|
1206 } |
|
1207 |
|
1208 DEFUNX ("WTERMSIG", FWTERMSIG, args, , |
|
1209 "-*- texinfo -*-\n\ |
|
1210 @deftypefn {Built-in Function} {} WTERMSIG (@var{status})\n\ |
|
1211 Given @var{status} from a call to @code{waitpid}, return the number of\n\ |
|
1212 the signal that caused the child process to terminate. This function\n\ |
|
1213 should only be employed if @code{WIFSIGNALED} returned true.\n\ |
|
1214 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ |
|
1215 @end deftypefn") |
|
1216 { |
|
1217 octave_value retval = 0.0; |
|
1218 |
|
1219 #if defined (WTERMSIG) |
|
1220 if (args.length () == 1) |
|
1221 { |
|
1222 int status = args(0).int_value (); |
|
1223 |
|
1224 if (! error_state) |
|
1225 retval = WTERMSIG (status); |
|
1226 else |
|
1227 error ("WTERMSIG: expecting integer argument"); |
|
1228 } |
|
1229 #else |
5455
|
1230 warning ("WTERMSIG always returns false in this version of Octave"); |
5453
|
1231 #endif |
|
1232 |
|
1233 return retval; |
|
1234 } |
|
1235 |
|
1236 DEFUNX ("WCOREDUMP", FWCOREDUMP, args, , |
|
1237 "-*- texinfo -*-\n\ |
|
1238 @deftypefn {Built-in Function} {} WCOREDUMP (@var{status})\n\ |
|
1239 Given @var{status} from a call to @code{waitpid}, return true if the\n\ |
|
1240 child produced a core dump. This function should only be employed if\n\ |
|
1241 @code{WIFSIGNALED} returned true. The macro used to implement this\n\ |
|
1242 function is not specified in POSIX.1-2001 and is not available on some\n\ |
|
1243 Unix implementations (e.g., AIX, SunOS).\n\ |
|
1244 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ |
|
1245 @end deftypefn") |
|
1246 { |
|
1247 octave_value retval = 0.0; |
|
1248 |
|
1249 #if defined (WCOREDUMP) |
|
1250 if (args.length () == 1) |
|
1251 { |
|
1252 int status = args(0).int_value (); |
|
1253 |
|
1254 if (! error_state) |
|
1255 retval = WCOREDUMP (status); |
|
1256 else |
|
1257 error ("WCOREDUMP: expecting integer argument"); |
|
1258 } |
|
1259 #else |
5455
|
1260 warning ("WCOREDUMP always returns false in this version of Octave"); |
5453
|
1261 #endif |
|
1262 |
|
1263 return retval; |
|
1264 } |
|
1265 |
|
1266 DEFUNX ("WIFSTOPPED", FWIFSTOPPED, args, , |
|
1267 "-*- texinfo -*-\n\ |
|
1268 @deftypefn {Built-in Function} {} WIFSTOPPED (@var{status})\n\ |
|
1269 Given @var{status} from a call to @code{waitpid}, return true if the\n\ |
|
1270 child process was stopped by delivery of a signal; this is only\n\ |
|
1271 possible if the call was done using @code{WUNTRACED} or when the child\n\ |
|
1272 is being traced (see ptrace(2)).\n\ |
|
1273 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WSTOPSIG, WIFCONTINUED}\n\ |
|
1274 @end deftypefn") |
|
1275 { |
|
1276 octave_value retval = 0.0; |
|
1277 |
|
1278 #if defined (WIFSTOPPED) |
|
1279 if (args.length () == 1) |
|
1280 { |
|
1281 int status = args(0).int_value (); |
|
1282 |
|
1283 if (! error_state) |
|
1284 retval = WIFSTOPPED (status); |
|
1285 else |
|
1286 error ("WIFSTOPPED: expecting integer argument"); |
|
1287 } |
|
1288 #else |
5455
|
1289 warning ("WIFSTOPPED always returns false in this version of Octave"); |
5453
|
1290 #endif |
|
1291 |
|
1292 return retval; |
|
1293 } |
|
1294 |
|
1295 DEFUNX ("WSTOPSIG", FWSTOPSIG, args, , |
|
1296 "-*- texinfo -*-\n\ |
|
1297 @deftypefn {Built-in Function} {} WSTOPSIG (@var{status})\n\ |
|
1298 Given @var{status} from a call to @code{waitpid}, return the number of\n\ |
|
1299 the signal which caused the child to stop. This function should only\n\ |
|
1300 be employed if @code{WIFSTOPPED} returned true.\n\ |
|
1301 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WIFCONTINUED}\n\ |
|
1302 @end deftypefn") |
|
1303 { |
|
1304 octave_value retval = 0.0; |
|
1305 |
|
1306 #if defined (WSTOPSIG) |
|
1307 if (args.length () == 1) |
|
1308 { |
|
1309 int status = args(0).int_value (); |
|
1310 |
|
1311 if (! error_state) |
|
1312 retval = WSTOPSIG (status); |
|
1313 else |
|
1314 error ("WSTOPSIG: expecting integer argument"); |
|
1315 } |
|
1316 #else |
5455
|
1317 warning ("WSTOPSIG always returns false in this version of Octave"); |
5453
|
1318 #endif |
|
1319 |
|
1320 return retval; |
|
1321 } |
|
1322 |
|
1323 DEFUNX ("WIFCONTINUED", FWIFCONTINUED, args, , |
|
1324 "-*- texinfo -*-\n\ |
|
1325 @deftypefn {Built-in Function} {} WIFCONTINUED (@var{status})\n\ |
|
1326 Given @var{status} from a call to @code{waitpid}, return true if the\n\ |
|
1327 child process was resumed by delivery of @code{SIGCONT}.\n\ |
|
1328 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG}\n\ |
|
1329 @end deftypefn") |
|
1330 { |
|
1331 octave_value retval = 0.0; |
|
1332 |
|
1333 #if defined (WIFCONTINUED) |
|
1334 if (args.length () == 1) |
|
1335 { |
|
1336 int status = args(0).int_value (); |
|
1337 |
|
1338 if (! error_state) |
|
1339 retval = WIFCONTINUED (status); |
|
1340 else |
|
1341 error ("WIFCONTINUED: expecting integer argument"); |
|
1342 } |
|
1343 #else |
5455
|
1344 warning ("WIFCONTINUED always returns false in this version of Octave"); |
5453
|
1345 #endif |
|
1346 |
|
1347 return retval; |
|
1348 } |
|
1349 |
5138
|
1350 DEFUN (canonicalize_file_name, args, , |
|
1351 "-*- texinfo -*-\n\ |
|
1352 @deftypefn {Built-in Function} {[@var{cname}, @var{status}, @var{msg}]} canonicalize_file_name (@var{name})\n\ |
|
1353 Return the canonical name of file @var{name}.\n\ |
|
1354 @end deftypefn") |
|
1355 { |
|
1356 octave_value_list retval; |
|
1357 |
|
1358 if (args.length () == 1) |
|
1359 { |
|
1360 std::string name = args(0).string_value (); |
|
1361 |
|
1362 if (! error_state) |
|
1363 { |
|
1364 std::string msg; |
|
1365 |
|
1366 std::string result = file_ops::canonicalize_file_name (name, msg); |
|
1367 |
|
1368 retval(2) = msg; |
|
1369 retval(1) = msg.empty () ? 0 : -1; |
|
1370 retval(0) = result; |
|
1371 } |
|
1372 else |
|
1373 error ("canonicalize_file_name: argument must be a character string"); |
|
1374 } |
|
1375 else |
|
1376 print_usage ("canonicalize_file_name"); |
|
1377 |
|
1378 return retval; |
|
1379 } |
|
1380 |
2075
|
1381 #if !defined (O_NONBLOCK) && defined (O_NDELAY) |
|
1382 #define O_NONBLOCK O_NDELAY |
|
1383 #endif |
|
1384 |
|
1385 void |
|
1386 symbols_of_syscalls (void) |
|
1387 { |
|
1388 #if defined (F_DUPFD) |
4233
|
1389 DEFCONSTX ("F_DUPFD", SBV_F_DUPFD, F_DUPFD, |
3446
|
1390 "-*- texinfo -*-\n\ |
5333
|
1391 @defvr {Built-in Constant} F_DUPFD\n\ |
5040
|
1392 Request to @code{fcntl} to return a duplicate file descriptor.\n\ |
5333
|
1393 @seealso{fcntl, F_GETFD, F_GETFL, F_SETFD, F_SETFL}\n\ |
3446
|
1394 @end defvr"); |
2075
|
1395 #endif |
|
1396 |
|
1397 #if defined (F_GETFD) |
4233
|
1398 DEFCONSTX ("F_GETFD", SBV_F_GETFD, F_GETFD, |
3446
|
1399 "-*- texinfo -*-\n\ |
5333
|
1400 @defvr {Built-in Constant} F_GETFD\n\ |
5040
|
1401 Request to @code{fcntl} to return the file descriptor flags.\n\ |
5333
|
1402 @seealso{fcntl, F_DUPFD, F_GETFL, F_SETFD, F_SETFL}\n\ |
3446
|
1403 @end defvr"); |
2075
|
1404 #endif |
|
1405 |
|
1406 #if defined (F_GETFL) |
4233
|
1407 DEFCONSTX ("F_GETFL", SBV_F_GETFL, F_GETFL, |
3446
|
1408 "-*- texinfo -*-\n\ |
5333
|
1409 @defvr {Built-in Constant} F_GETFL\n\ |
5040
|
1410 Request to @code{fcntl} to return the file status flags.\n\ |
5333
|
1411 @seealso{fcntl, F_DUPFD, F_GETFD, F_SETFD, F_SETFL}\n\ |
3446
|
1412 @end defvr"); |
2075
|
1413 #endif |
|
1414 |
|
1415 #if defined (F_SETFD) |
4233
|
1416 DEFCONSTX ("F_SETFD", SBV_F_SETFD, F_SETFD, |
3446
|
1417 "-*- texinfo -*-\n\ |
5333
|
1418 @defvr {Built-in Constant} F_SETFD\n\ |
5040
|
1419 Request to @code{fcntl} to set the file descriptor flags.\n\ |
5333
|
1420 @seealso{fcntl, F_DUPFD, F_GETFD, F_GETFL, F_SETFL}\n\ |
3446
|
1421 @end defvr"); |
2075
|
1422 #endif |
|
1423 |
|
1424 #if defined (F_SETFL) |
4233
|
1425 DEFCONSTX ("F_SETFL", SBV_F_SETFL, F_SETFL, |
3446
|
1426 "-*- texinfo -*-\n\ |
5333
|
1427 @defvr {Built-in Constant} F_SETFL\n\ |
5040
|
1428 Request to @code{fcntl} to set the file status flags.\n\ |
5333
|
1429 @seealso{fcntl, F_DUPFD, F_GETFD, F_GETFL, F_SETFD}\n\ |
3446
|
1430 @end defvr"); |
2075
|
1431 #endif |
|
1432 |
|
1433 #if defined (O_APPEND) |
4233
|
1434 DEFCONSTX ("O_APPEND", SBV_O_APPEND, O_APPEND, |
3446
|
1435 "-*- texinfo -*-\n\ |
5333
|
1436 @defvr {Built-in Constant} O_APPEND\n\ |
5040
|
1437 File status flag, append on each write.\n\ |
5333
|
1438 @seealso{fcntl, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
3446
|
1439 @end defvr"); |
2075
|
1440 #endif |
|
1441 |
2669
|
1442 #if defined (O_ASYNC) |
4233
|
1443 DEFCONSTX ("O_ASYNC", SBV_O_ASYNC, O_ASYNC, |
3446
|
1444 "-*- texinfo -*-\n\ |
5333
|
1445 @defvr {Built-in Constant} O_ASYNC\n\ |
5040
|
1446 File status flag, asynchronous I/O.\n\ |
5333
|
1447 @seealso{fcntl, O_APPEND, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
3446
|
1448 @end defvr"); |
2669
|
1449 #endif |
|
1450 |
2075
|
1451 #if defined (O_CREAT) |
4233
|
1452 DEFCONSTX ("O_CREAT", SBV_O_CREAT, O_CREAT, |
3446
|
1453 "-*- texinfo -*-\n\ |
5333
|
1454 @defvr {Built-in Constant} O_CREAT\n\ |
5040
|
1455 File status flag, create file if it does not exist.\n\ |
5333
|
1456 @seealso{fcntl, O_APPEND, O_ASYNC, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
3446
|
1457 @end defvr"); |
2075
|
1458 #endif |
|
1459 |
|
1460 #if defined (O_EXCL) |
4233
|
1461 DEFCONSTX ("O_EXCL", SBV_O_EXCL, O_EXCL, |
3446
|
1462 "-*- texinfo -*-\n\ |
5333
|
1463 @defvr {Built-in Constant} O_EXCL\n\ |
5040
|
1464 File status flag, file locking.\n\ |
5333
|
1465 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
3446
|
1466 @end defvr"); |
2075
|
1467 #endif |
|
1468 |
|
1469 #if defined (O_NONBLOCK) |
4233
|
1470 DEFCONSTX ("O_NONBLOCK", SBV_O_NONBLOCK, O_NONBLOCK, |
3446
|
1471 "-*- texinfo -*-\n\ |
5333
|
1472 @defvr {Built-in Constant} O_NONBLOCK\n\ |
5040
|
1473 File status flag, non-blocking I/O.\n\ |
5333
|
1474 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
3446
|
1475 @end defvr"); |
2075
|
1476 #endif |
|
1477 |
|
1478 #if defined (O_RDONLY) |
4233
|
1479 DEFCONSTX ("O_RDONLY", SBV_O_RDONLY, O_RDONLY, |
3446
|
1480 "-*- texinfo -*-\n\ |
5333
|
1481 @defvr {Built-in Constant} O_RDONLY\n\ |
5040
|
1482 File status flag, file opened for reading only.\n\ |
5333
|
1483 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
3446
|
1484 @end defvr"); |
2075
|
1485 #endif |
|
1486 |
|
1487 #if defined (O_RDWR) |
4233
|
1488 DEFCONSTX ("O_RDWR", SBV_O_RDWR, O_RDWR, |
3446
|
1489 "-*- texinfo -*-\n\ |
5333
|
1490 @defvr {Built-in Constant} O_RDWR\n\ |
5040
|
1491 File status flag, file open for both reading and writing.\n\ |
5333
|
1492 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
3446
|
1493 @end defvr"); |
2075
|
1494 #endif |
|
1495 |
2669
|
1496 #if defined (O_SYNC) |
4233
|
1497 DEFCONSTX ("O_SYNC", SBV_O_SYNC, O_SYNC, |
3446
|
1498 "-*- texinfo -*-\n\ |
5333
|
1499 @defvr {Built-in Constant} O_SYNC\n\ |
5040
|
1500 File status flag, file opened for synchronous I/O.\n\ |
5333
|
1501 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY}\n\ |
3446
|
1502 @end defvr"); |
2669
|
1503 #endif |
|
1504 |
2075
|
1505 #if defined (O_TRUNC) |
4233
|
1506 DEFCONSTX ("O_TRUNC", SBV_O_TRUNC, O_TRUNC, |
3446
|
1507 "-*- texinfo -*-\n\ |
|
1508 @defvr {Built-in Variable} O_TRUNC\n\ |
5040
|
1509 File status flag, if file exists, truncate it when writing.\n\ |
5333
|
1510 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_WRONLY}\n\ |
3446
|
1511 @end defvr"); |
2075
|
1512 #endif |
|
1513 |
|
1514 #if defined (O_WRONLY) |
4233
|
1515 DEFCONSTX ("O_WRONLY", SBV_O_WRONLY, O_WRONLY, |
3446
|
1516 "-*- texinfo -*-\n\ |
5333
|
1517 @defvr {Built-in Constant} O_WRONLY\n\ |
5040
|
1518 File status flag, file opened for writing only.\n\ |
5333
|
1519 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC}\n\ |
3446
|
1520 @end defvr"); |
2075
|
1521 #endif |
3446
|
1522 |
5453
|
1523 #if !defined (WNOHANG) |
|
1524 #define WNOHANG 0 |
|
1525 #endif |
|
1526 |
|
1527 DEFCONSTX ("WNOHANG", SBV_WNOHANG, WNOHANG, |
|
1528 "-*- texinfo -*-\n\ |
|
1529 @defvr {Built-in Constant} WNOHANG\n\ |
|
1530 Option value for @code{waitpid}.\n\ |
|
1531 @seealso{waitpid, WUNTRACED, WCONTINUE}\n\ |
|
1532 @end defvr"); |
|
1533 |
|
1534 #if !defined (WUNTRACED) |
|
1535 #define WUNTRACED 0 |
|
1536 #endif |
|
1537 |
|
1538 DEFCONSTX ("WUNTRACED", SBV_WUNTRACED, WUNTRACED, |
|
1539 "-*- texinfo -*-\n\ |
|
1540 @defvr {Built-in Constant} WUNTRACED\n\ |
|
1541 Option value for @code{waitpid}.\n\ |
|
1542 @seealso{waitpid, WNOHANG, WCONTINUE}\n\ |
|
1543 @end defvr"); |
|
1544 |
|
1545 #if !defined (WCONTINUE) |
|
1546 #define WCONTINUE 0 |
|
1547 #endif |
|
1548 |
|
1549 DEFCONSTX ("WCONTINUE", SBV_WCONTINUE, WCONTINUE, |
|
1550 "-*- texinfo -*-\n\ |
|
1551 @defvr {Built-in Constant} WCONINTUE\n\ |
|
1552 Option value for @code{waitpid}.\n\ |
|
1553 @seealso{waitpid, WNOHANG, WUNTRACED}\n\ |
|
1554 @end defvr"); |
|
1555 |
2075
|
1556 } |
|
1557 |
|
1558 /* |
|
1559 ;;; Local Variables: *** |
|
1560 ;;; mode: C++ *** |
|
1561 ;;; End: *** |
|
1562 */ |