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