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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 // Thomas Baier <baier@ci.tuwien.ac.at> added the original versions of |
|
24 // the following functions: |
|
25 // |
|
26 // mkfifo unlink waitpid |
|
27 |
|
28 #ifdef HAVE_CONFIG_H |
|
29 #include <config.h> |
|
30 #endif |
|
31 |
2669
|
32 #include <cerrno> |
2075
|
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 "syswait.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 |
2800
|
69 m["dev"] = static_cast<double> (fs.dev ()); |
|
70 m["ino"] = static_cast<double> (fs.ino ()); |
2075
|
71 m["modestr"] = fs.mode_as_string (); |
2800
|
72 m["nlink"] = static_cast<double> (fs.nlink ()); |
|
73 m["uid"] = static_cast<double> (fs.uid ()); |
|
74 m["gid"] = static_cast<double> (fs.gid ()); |
2075
|
75 #if defined (HAVE_ST_RDEV) |
2800
|
76 m["rdev"] = static_cast<double> (fs.rdev ()); |
2075
|
77 #endif |
2800
|
78 m["size"] = static_cast<double> (fs.size ()); |
|
79 m["atime"] = static_cast<double> (fs.atime ()); |
|
80 m["mtime"] = static_cast<double> (fs.mtime ()); |
|
81 m["ctime"] = static_cast<double> (fs.ctime ()); |
2075
|
82 #if defined (HAVE_ST_BLKSIZE) |
2800
|
83 m["blksize"] = static_cast<double> (fs.blksize ()); |
2075
|
84 #endif |
|
85 #if defined (HAVE_ST_BLOCKS) |
2800
|
86 m["blocks"] = static_cast<double> (fs.blocks ()); |
2075
|
87 #endif |
|
88 |
|
89 return m; |
|
90 } |
|
91 |
2457
|
92 DEFUN (dup2, args, , |
2669
|
93 "[FID, MSG] = dup2 (OLD, NEW)\n\ |
|
94 \n\ |
|
95 Duplicate a file descriptor.\n\ |
|
96 \n\ |
|
97 If successful, FID is greater than zero and contains the new file ID.\n\ |
|
98 Otherwise, FID is negative and MSG contains a system-dependent error message.") |
2075
|
99 { |
2669
|
100 octave_value_list retval; |
|
101 |
|
102 retval(1) = string (); |
|
103 retval(0) = -1.0; |
2075
|
104 |
|
105 int nargin = args.length (); |
|
106 |
|
107 if (nargin == 2) |
|
108 { |
|
109 double d_old = args(0).double_value (); |
|
110 double d_new = args(1).double_value (); |
|
111 |
|
112 if (! error_state) |
|
113 { |
|
114 if (D_NINT (d_old) == d_old && D_NINT (d_new) == d_new) |
|
115 { |
|
116 int i_old = NINT (d_old); |
|
117 int i_new = NINT (d_new); |
|
118 |
|
119 // XXX FIXME XXX -- are these checks sufficient? |
|
120 if (i_old >= 0 && i_new >= 0) |
2669
|
121 { |
2937
|
122 string msg; |
|
123 |
|
124 int status = octave_syscalls::dup2 (i_old, i_new, msg); |
2669
|
125 |
2800
|
126 retval(0) = static_cast<double> (status); |
2937
|
127 retval(1) = msg; |
2669
|
128 } |
2075
|
129 else |
|
130 error ("dup2: invalid file id"); |
|
131 } |
|
132 else |
|
133 error ("dup2: arguments must be integer values"); |
|
134 } |
|
135 } |
|
136 else |
|
137 print_usage ("dup2"); |
|
138 |
|
139 return retval; |
|
140 } |
|
141 |
2457
|
142 DEFUN (exec, args, , |
2669
|
143 "[STATUS, MSG] = exec (FILE, ARGS)\n\ |
|
144 \n\ |
|
145 Replace current process with a new process.\n\ |
|
146 \n\ |
2802
|
147 If successful, exec does not return. If exec does return, status will\n\ |
2669
|
148 be nonzero, and MSG will contain a system-dependent error message.") |
2075
|
149 { |
2669
|
150 octave_value_list retval; |
|
151 |
|
152 retval(1) = string (); |
|
153 retval(0) = -1.0; |
2075
|
154 |
|
155 int nargin = args.length (); |
|
156 |
|
157 if (nargin == 1 || nargin == 2) |
|
158 { |
|
159 string exec_file = args(0).string_value (); |
|
160 |
|
161 if (! error_state) |
|
162 { |
2937
|
163 string_vector exec_args; |
2075
|
164 |
|
165 if (nargin == 2) |
|
166 { |
2937
|
167 string_vector tmp = args(1).all_strings (); |
2075
|
168 |
|
169 if (! error_state) |
|
170 { |
2937
|
171 int len = tmp.length (); |
2075
|
172 |
2937
|
173 exec_args.resize (len + 1); |
2075
|
174 |
2937
|
175 exec_args[0] = exec_file; |
2075
|
176 |
2937
|
177 for (int i = 0; i < len; i++) |
|
178 exec_args[i+1] = tmp[i]; |
2075
|
179 } |
|
180 else |
|
181 error ("exec: arguments must be strings"); |
|
182 } |
|
183 else |
|
184 { |
2937
|
185 exec_args.resize (1); |
2075
|
186 |
2937
|
187 exec_args[0] = exec_file; |
2075
|
188 } |
|
189 |
|
190 if (! error_state) |
2669
|
191 { |
2937
|
192 string msg; |
|
193 |
|
194 int status = octave_syscalls::execvp (exec_file, exec_args, msg); |
2669
|
195 |
2800
|
196 retval(0) = static_cast<double> (status); |
2937
|
197 retval(1) = msg; |
2669
|
198 } |
2075
|
199 } |
|
200 else |
|
201 error ("exec: first argument must be a string"); |
|
202 } |
|
203 else |
|
204 print_usage ("exec"); |
|
205 |
|
206 return retval; |
|
207 } |
|
208 |
2457
|
209 DEFUN (fcntl, args, , |
2669
|
210 "[STATUS, MSG] = fcntl (FID, REQUEST, ARGUMENT)\n\ |
|
211 \n\ |
|
212 Control open file descriptors.\n\ |
|
213 \n\ |
|
214 If successful, STATUS is 0 and MSG is an empty string. Otherwise,\n\ |
|
215 STATUS is nonzero and MSG contains a system-dependent error message.") |
2075
|
216 { |
2669
|
217 octave_value_list retval; |
|
218 |
|
219 retval(1) = string (); |
|
220 retval(0) = -1.0; |
2075
|
221 |
|
222 int nargin = args.length (); |
|
223 |
|
224 if (nargin == 3) |
|
225 { |
|
226 double d_fid = args(0).double_value (); |
|
227 double d_req = args(1).double_value (); |
|
228 double d_arg = args(2).double_value (); |
|
229 |
|
230 if (! error_state |
|
231 && D_NINT (d_fid) == d_fid |
|
232 && D_NINT (d_req) == d_req |
|
233 && D_NINT (d_arg) == d_arg) |
|
234 { |
|
235 int fid = NINT (d_fid); |
|
236 int req = NINT (d_req); |
|
237 int arg = NINT (d_arg); |
|
238 |
|
239 // XXX FIXME XXX -- Need better checking here? |
|
240 if (fid < 0) |
|
241 error ("fcntl: invalid file id"); |
|
242 else |
2669
|
243 { |
2937
|
244 string msg; |
|
245 |
|
246 int status = octave_syscalls::fcntl (fid, req, arg, msg); |
2669
|
247 |
2800
|
248 retval(0) = static_cast<double> (status); |
2937
|
249 retval(1) = msg; |
2669
|
250 } |
2075
|
251 } |
|
252 else |
|
253 error ("fcntl: file id must be an integer"); |
|
254 } |
|
255 else |
|
256 print_usage ("fcntl"); |
|
257 |
|
258 return retval; |
|
259 } |
|
260 |
2457
|
261 DEFUN (fork, args, , |
2669
|
262 "[PID, MSG] = fork ()\n\ |
|
263 \n\ |
|
264 Create a copy of the current process.\n\ |
|
265 \n\ |
|
266 If successful, PID is either the process ID and you are in the parent,\n\ |
|
267 or 0, and you are in the child. If PID is less than zero, an error\n\ |
|
268 has occured, and MSG contains a system-dependent error message.") |
2075
|
269 { |
2669
|
270 octave_value_list retval; |
|
271 |
|
272 retval(1) = string (); |
|
273 retval(0) = -1.0; |
2075
|
274 |
|
275 int nargin = args.length (); |
|
276 |
|
277 if (nargin == 0) |
2475
|
278 { |
2937
|
279 string msg; |
|
280 |
|
281 pid_t pid = octave_syscalls::fork (msg); |
2669
|
282 |
2800
|
283 retval(0) = static_cast<double> (pid); |
2937
|
284 retval(1) = msg; |
2475
|
285 } |
2075
|
286 else |
|
287 print_usage ("fork"); |
|
288 |
|
289 return retval; |
|
290 } |
|
291 |
2457
|
292 DEFUN (getpgrp, args, , |
2075
|
293 "pgid = getpgrp (): return the process group id of the current process") |
|
294 { |
2937
|
295 octave_value_list retval; |
|
296 |
|
297 retval(1) = string (); |
|
298 retval(0) = -1.0; |
2075
|
299 |
|
300 int nargin = args.length (); |
|
301 |
|
302 if (nargin == 0) |
2475
|
303 { |
2937
|
304 string msg; |
|
305 |
|
306 retval(0) = static_cast<double> (octave_syscalls::getpgrp (msg)); |
|
307 retval(1) = msg; |
2475
|
308 } |
2075
|
309 else |
|
310 print_usage ("getpgrp"); |
|
311 |
|
312 return retval; |
|
313 } |
|
314 |
2457
|
315 DEFUN (getpid, args, , |
2075
|
316 "pid = getpid (): return the process id of the current process") |
|
317 { |
|
318 double retval = -1.0; |
|
319 |
|
320 int nargin = args.length (); |
|
321 |
|
322 if (nargin == 0) |
2937
|
323 retval = octave_syscalls::getpid (); |
2075
|
324 else |
|
325 print_usage ("getpid"); |
|
326 |
|
327 return retval; |
|
328 } |
|
329 |
2457
|
330 DEFUN (getppid, args, , |
2075
|
331 "pid = getppid (): return the process id of the parent process") |
|
332 { |
|
333 double retval = -1.0; |
|
334 |
2475
|
335 int nargin = args.length (); |
|
336 |
|
337 if (nargin == 0) |
2937
|
338 retval = octave_syscalls::getppid (); |
2475
|
339 else |
|
340 print_usage ("getppid"); |
|
341 |
|
342 return retval; |
|
343 } |
|
344 |
|
345 DEFUN (getegid, args, , |
|
346 "gid = getegid (): return the effective group id of the current process") |
|
347 { |
|
348 double retval = -1.0; |
|
349 |
2075
|
350 int nargin = args.length (); |
|
351 |
|
352 if (nargin == 0) |
2937
|
353 retval = octave_syscalls::getegid (); |
2075
|
354 else |
2475
|
355 print_usage ("getegid"); |
|
356 |
|
357 return retval; |
|
358 } |
|
359 |
|
360 DEFUN (getgid, args, , |
|
361 "gid = getgid (): return the real group id of the current process") |
|
362 { |
|
363 double retval = -1.0; |
|
364 |
|
365 int nargin = args.length (); |
|
366 |
|
367 if (nargin == 0) |
2937
|
368 retval = octave_syscalls::getgid (); |
2475
|
369 else |
|
370 print_usage ("getgid"); |
2075
|
371 |
|
372 return retval; |
|
373 } |
|
374 |
2473
|
375 DEFUN (geteuid, args, , |
2472
|
376 "uid = geteuid (): return the effective user id of the current process") |
|
377 { |
|
378 double retval = -1.0; |
|
379 |
|
380 int nargin = args.length (); |
|
381 |
|
382 if (nargin == 0) |
2937
|
383 retval = octave_syscalls::geteuid (); |
2472
|
384 else |
|
385 print_usage ("geteuid"); |
2473
|
386 |
|
387 return retval; |
2472
|
388 } |
|
389 |
2473
|
390 DEFUN (getuid, args, , |
2472
|
391 "uid = getuid (): return the real user id of the current process") |
|
392 { |
|
393 double retval = -1.0; |
|
394 |
|
395 int nargin = args.length (); |
|
396 |
|
397 if (nargin == 0) |
2937
|
398 retval = octave_syscalls::getuid (); |
2472
|
399 else |
|
400 print_usage ("getuid"); |
2473
|
401 |
|
402 return retval; |
2472
|
403 } |
|
404 |
2075
|
405 DEFUN (lstat, args, , |
2262
|
406 "[S, ERR, MSG] = lstat (NAME)\n\ |
2075
|
407 \n\ |
2262
|
408 Like [S, ERR, MSG] = stat (NAME), but if NAME refers to a symbolic\n\ |
|
409 link, returns information about the link itself, not the file that it\n\ |
|
410 points to.") |
2075
|
411 { |
2263
|
412 octave_value_list retval; |
2075
|
413 |
|
414 if (args.length () == 1) |
|
415 { |
2926
|
416 string fname = file_ops::tilde_expand (args(0).string_value ()); |
2075
|
417 |
|
418 if (! error_state) |
|
419 { |
|
420 file_stat fs (fname, false); |
|
421 |
2263
|
422 if (fs) |
2262
|
423 { |
|
424 retval(2) = string (); |
|
425 retval(1) = 0.0; |
|
426 retval(0) = octave_value (mk_stat_map (fs)); |
|
427 } |
|
428 else |
|
429 { |
|
430 retval(2) = fs.error (); |
|
431 retval(1) = -1.0; |
|
432 retval(0) = Matrix (); |
|
433 } |
2075
|
434 } |
|
435 } |
|
436 else |
|
437 print_usage ("lstat"); |
|
438 |
|
439 return retval; |
|
440 } |
|
441 |
|
442 DEFUN (mkfifo, args, , |
2669
|
443 "[STATUS, MSG] = mkfifo (NAME, MODE)\n\ |
2075
|
444 \n\ |
2669
|
445 Create a FIFO special file named NAME with file mode MODE\n\ |
2075
|
446 \n\ |
2669
|
447 If successful, STATUS is 0 and MSG is an empty string. Otherwise,\n\ |
|
448 STATUS is nonzero and MSG contains a system-dependent error message.") |
2075
|
449 { |
2669
|
450 octave_value_list retval; |
|
451 |
|
452 retval(1) = string (); |
|
453 retval(0) = -1.0; |
2075
|
454 |
|
455 int nargin = args.length (); |
|
456 |
|
457 if (nargin == 2) |
|
458 { |
|
459 if (args(0).is_string ()) |
|
460 { |
|
461 string name = args(0).string_value (); |
|
462 |
|
463 if (args(1).is_scalar_type ()) |
|
464 { |
2800
|
465 long mode = static_cast<long> (args(1).double_value ()); |
2075
|
466 |
2669
|
467 string msg; |
|
468 |
2926
|
469 int status = file_ops::mkfifo (name, mode, msg); |
2669
|
470 |
2800
|
471 retval(0) = static_cast<double> (status); |
2669
|
472 |
|
473 if (status < 0) |
|
474 retval(1) = msg; |
2075
|
475 } |
|
476 else |
|
477 error ("mkfifo: MODE must be an integer"); |
|
478 } |
|
479 else |
|
480 error ("mkfifo: file name must be a string"); |
|
481 } |
|
482 else |
|
483 print_usage ("mkfifo"); |
|
484 |
|
485 return retval; |
|
486 } |
|
487 |
|
488 DEFUN (pipe, args, , |
2902
|
489 "[FILE_LIST, STATUS, MSG] = pipe (): create an interprocess channel.\n\ |
2669
|
490 \n\ |
2902
|
491 Return the file objects corresponding to the reading and writing ends of\n\ |
|
492 the pipe, as a two-element list.\n\ |
2669
|
493 \n\ |
|
494 If successful, STATUS is 0 and MSG is an empty string. Otherwise,\n\ |
|
495 STATUS is nonzero and MSG contains a system-dependent error message.") |
2075
|
496 { |
2669
|
497 octave_value_list retval; |
|
498 |
|
499 retval(2) = string (); |
|
500 retval(1) = -1.0; |
|
501 retval(0) = Matrix (); |
2075
|
502 |
|
503 int nargin = args.length (); |
|
504 |
|
505 if (nargin == 0) |
|
506 { |
|
507 int fid[2]; |
|
508 |
2937
|
509 string msg; |
|
510 |
|
511 int status = octave_syscalls::pipe (fid, msg); |
2669
|
512 |
|
513 if (status < 0) |
2937
|
514 retval(2) = msg; |
2669
|
515 else |
2075
|
516 { |
|
517 FILE *in_file = fdopen (fid[0], "r"); |
|
518 FILE *out_file = fdopen (fid[1], "w"); |
|
519 |
|
520 octave_istdiostream *is |
|
521 = new octave_istdiostream (string (), in_file); |
|
522 |
|
523 octave_ostdiostream *os |
|
524 = new octave_ostdiostream (string (), out_file); |
|
525 |
2902
|
526 octave_value_list file_ids; |
2075
|
527 |
2902
|
528 file_ids(1) = octave_stream_list::insert (os); |
|
529 file_ids(0) = octave_stream_list::insert (is); |
2075
|
530 |
2800
|
531 retval(1) = static_cast<double> (status); |
2902
|
532 retval(0) = octave_value (file_ids); |
2669
|
533 } |
2075
|
534 } |
|
535 else |
|
536 print_usage ("pipe"); |
|
537 |
|
538 return retval; |
|
539 } |
|
540 |
|
541 DEFUN (stat, args, , |
2262
|
542 "[S, ERR, MSG] = stat (NAME)\n\ |
2075
|
543 \n\ |
2802
|
544 Given the name of a file, return a structure S with the following\n\ |
2075
|
545 elements:\n\ |
|
546 \n\ |
|
547 dev : id of device containing a directory entry for this file\n\ |
|
548 ino : file number of the file\n\ |
|
549 modestr : file mode, as a string of ten letters or dashes as in ls -l\n\ |
|
550 nlink : number of links\n\ |
|
551 uid : user id of file's owner\n\ |
|
552 gid : group id of file's group \n\ |
|
553 rdev : id of device for block or character special files\n\ |
|
554 size : size in bytes\n\ |
|
555 atime : time of last access\n\ |
|
556 mtime : time of last modification\n\ |
|
557 ctime : time of last file status change\n\ |
|
558 blksize : size of blocks in the file\n\ |
|
559 blocks : number of blocks allocated for file\n\ |
|
560 \n\ |
2262
|
561 If the call is successful, ERR is 0 and MSG is an empty string.\n\ |
|
562 \n\ |
|
563 If the file does not exist, or some other error occurs, S is an\n\ |
|
564 empty matrix, ERR is -1, and MSG contains the corresponding\n\ |
|
565 system error message.") |
2075
|
566 { |
2262
|
567 octave_value_list retval; |
2075
|
568 |
|
569 if (args.length () == 1) |
|
570 { |
2926
|
571 string fname = file_ops::tilde_expand (args(0).string_value ()); |
2075
|
572 |
|
573 if (! error_state) |
|
574 { |
|
575 file_stat fs (fname); |
|
576 |
|
577 if (fs) |
2262
|
578 { |
|
579 retval(2) = string (); |
|
580 retval(1) = 0.0; |
|
581 retval(0) = octave_value (mk_stat_map (fs)); |
|
582 } |
|
583 else |
|
584 { |
|
585 retval(2) = fs.error (); |
|
586 retval(1) = -1.0; |
|
587 retval(0) = Matrix (); |
|
588 } |
2075
|
589 } |
|
590 } |
|
591 else |
|
592 print_usage ("stat"); |
|
593 |
|
594 return retval; |
|
595 } |
|
596 |
|
597 DEFUN (unlink, args, , |
2669
|
598 "[STATUS, MSG] = unlink (NAME)\n\ |
2075
|
599 \n\ |
2669
|
600 Delete the file NAME\n\ |
2075
|
601 \n\ |
2669
|
602 If successful, STATUS is 0 and MSG is an empty string. Otherwise,\n\ |
|
603 STATUS is nonzero and MSG contains a system-dependent error message.") |
2075
|
604 { |
2669
|
605 octave_value_list retval; |
|
606 |
|
607 retval(1) = string (); |
|
608 retval(0) = -1.0; |
2075
|
609 |
|
610 int nargin = args.length (); |
|
611 |
|
612 if (nargin == 1) |
|
613 { |
|
614 if (args(0).is_string ()) |
|
615 { |
|
616 string name = args(0).string_value (); |
|
617 |
2669
|
618 string msg; |
|
619 |
2926
|
620 int status = file_ops::unlink (name, msg); |
2669
|
621 |
2800
|
622 retval(0) = static_cast<double> (status); |
2937
|
623 retval(1) = msg; |
2075
|
624 } |
|
625 else |
|
626 error ("unlink: file name must be a string"); |
|
627 } |
|
628 else |
|
629 print_usage ("unlink"); |
|
630 |
|
631 return retval; |
|
632 } |
|
633 |
|
634 DEFUN (waitpid, args, , |
2669
|
635 "[PID, MSG] = waitpid (PID, OPTIONS)\n\ |
2075
|
636 \n\ |
2669
|
637 Wait for process PID to terminate\n\ |
2075
|
638 \n\ |
|
639 PID can be:\n\ |
|
640 \n\ |
|
641 -1 : wait for any child process\n\ |
|
642 0 : wait for any child process whose process group ID is equal to\n\ |
|
643 that of the Octave interpreter process.\n\ |
|
644 > 0 : wait for termination of the child process with ID PID.\n\ |
|
645 \n\ |
|
646 OPTIONS is:\n\ |
|
647 \n\ |
|
648 0 : wait until signal is received or a child process exits (this\n\ |
|
649 is the default if the OPTIONS argument is missing) \n\ |
|
650 1 : do not hang if status is not immediately available\n\ |
|
651 2 : report the status of any child processes that are\n\ |
|
652 stopped, and whose status has not yet been reported\n\ |
|
653 since they stopped\n\ |
|
654 3 : implies both 1 and 2\n\ |
|
655 \n\ |
2669
|
656 If successful, PID is greater than 0 and contains the process ID of\n\ |
|
657 the child process that exited and MSG is an empty string.\n\ |
|
658 Otherwise, PID is less than zero and MSG contains a system-dependent\n\ |
|
659 error message.") |
2075
|
660 { |
2669
|
661 octave_value_list retval; |
|
662 |
|
663 retval(1) = string (); |
|
664 retval(0) = -1.0; |
2075
|
665 |
|
666 int nargin = args.length (); |
|
667 |
|
668 if (nargin == 1 || nargin == 2) |
|
669 { |
|
670 double pid_num = args(0).double_value (); |
|
671 |
|
672 if (! error_state) |
|
673 { |
|
674 if (D_NINT (pid_num) != pid_num) |
|
675 error ("waitpid: PID must be an integer value"); |
|
676 else |
|
677 { |
|
678 pid_t pid = (pid_t) pid_num; |
|
679 |
|
680 int options = 0; |
|
681 |
|
682 if (args.length () == 2) |
|
683 { |
|
684 double options_num = args(1).double_value (); |
|
685 |
|
686 if (! error_state) |
|
687 { |
|
688 if (D_NINT (options_num) != options_num) |
|
689 error ("waitpid: PID must be an integer value"); |
|
690 else |
|
691 { |
|
692 options = NINT (options_num); |
|
693 if (options < 0 || options > 3) |
|
694 error ("waitpid: invalid OPTIONS value specified"); |
|
695 } |
|
696 } |
|
697 } |
|
698 |
|
699 if (! error_state) |
2669
|
700 { |
2937
|
701 string msg; |
|
702 |
|
703 pid_t status |
|
704 = octave_syscalls::waitpid (pid, options, msg); |
2669
|
705 |
2800
|
706 retval(0) = static_cast<double> (status); |
2937
|
707 retval(1) = msg; |
2669
|
708 } |
2075
|
709 } |
|
710 } |
|
711 } |
|
712 else |
|
713 print_usage ("waitpid"); |
|
714 |
|
715 return retval; |
|
716 } |
|
717 |
|
718 #if !defined (O_NONBLOCK) && defined (O_NDELAY) |
|
719 #define O_NONBLOCK O_NDELAY |
|
720 #endif |
|
721 |
|
722 void |
|
723 symbols_of_syscalls (void) |
|
724 { |
|
725 #if defined (F_DUPFD) |
3141
|
726 DEFCONST (F_DUPFD, static_cast<double> (F_DUPFD), |
2075
|
727 ""); |
|
728 #endif |
|
729 |
|
730 #if defined (F_GETFD) |
3141
|
731 DEFCONST (F_GETFD, static_cast<double> (F_GETFD), |
2075
|
732 ""); |
|
733 #endif |
|
734 |
|
735 #if defined (F_GETFL) |
3141
|
736 DEFCONST (F_GETFL, static_cast<double> (F_GETFL), |
2075
|
737 ""); |
|
738 #endif |
|
739 |
|
740 #if defined (F_SETFD) |
3141
|
741 DEFCONST (F_SETFD, static_cast<double> (F_SETFD), |
2075
|
742 ""); |
|
743 #endif |
|
744 |
|
745 #if defined (F_SETFL) |
3141
|
746 DEFCONST (F_SETFL, static_cast<double> (F_SETFL), |
2075
|
747 ""); |
|
748 #endif |
|
749 |
|
750 #if defined (O_APPEND) |
3141
|
751 DEFCONST (O_APPEND, static_cast<double> (O_APPEND), |
2075
|
752 ""); |
|
753 #endif |
|
754 |
2669
|
755 #if defined (O_ASYNC) |
3141
|
756 DEFCONST (O_ASYNC, static_cast<double> (O_ASYNC), |
2669
|
757 ""); |
|
758 #endif |
|
759 |
2075
|
760 #if defined (O_CREAT) |
3141
|
761 DEFCONST (O_CREAT, static_cast<double> (O_CREAT), |
2075
|
762 ""); |
|
763 #endif |
|
764 |
|
765 #if defined (O_EXCL) |
3141
|
766 DEFCONST (O_EXCL, static_cast<double> (O_EXCL), |
2075
|
767 ""); |
|
768 #endif |
|
769 |
|
770 #if defined (O_NONBLOCK) |
3141
|
771 DEFCONST (O_NONBLOCK, static_cast<double> (O_NONBLOCK), |
2075
|
772 ""); |
|
773 #endif |
|
774 |
|
775 #if defined (O_RDONLY) |
3141
|
776 DEFCONST (O_RDONLY, static_cast<double> (O_RDONLY), |
2075
|
777 ""); |
|
778 #endif |
|
779 |
|
780 #if defined (O_RDWR) |
3141
|
781 DEFCONST (O_RDWR, static_cast<double> (O_RDWR), |
2075
|
782 ""); |
|
783 #endif |
|
784 |
2669
|
785 #if defined (O_SYNC) |
3141
|
786 DEFCONST (O_SYNC, static_cast<double> (O_SYNC), |
2669
|
787 ""); |
|
788 #endif |
|
789 |
2075
|
790 #if defined (O_TRUNC) |
3141
|
791 DEFCONST (O_TRUNC, static_cast<double> (O_TRUNC), |
2075
|
792 ""); |
|
793 #endif |
|
794 |
|
795 #if defined (O_WRONLY) |
3141
|
796 DEFCONST (O_WRONLY, static_cast<double> (O_WRONLY), |
2075
|
797 ""); |
|
798 #endif |
|
799 } |
|
800 |
|
801 /* |
|
802 ;;; Local Variables: *** |
|
803 ;;; mode: C++ *** |
|
804 ;;; End: *** |
|
805 */ |