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