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