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