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