Mercurial > hg > octave-nkf
annotate src/syscalls.cc @ 10784:ca2df6737d6b
generalize cell2mat optimization to n dimensions
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 12 Jul 2010 21:32:18 +0200 |
parents | d53eb6249892 |
children | 3140cb7a05a1 |
rev | line source |
---|---|
2075 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, |
8920 | 4 2006, 2007, 2008, 2009 John W. Eaton |
10521
4d1fc073fbb7
add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents:
10336
diff
changeset
|
5 Copyright (C) 2010 VZLU Prague |
2075 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
2075 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
2075 | 22 |
23 */ | |
24 | |
25 // Thomas Baier <baier@ci.tuwien.ac.at> added the original versions of | |
26 // the following functions: | |
27 // | |
28 // mkfifo unlink waitpid | |
29 | |
30 #ifdef HAVE_CONFIG_H | |
31 #include <config.h> | |
32 #endif | |
33 | |
34 #include <cstdio> | |
2669 | 35 #include <cstring> |
2075 | 36 |
37 #include <sys/types.h> | |
38 #include <unistd.h> | |
39 | |
40 #include <fcntl.h> | |
41 | |
2926 | 42 #include "file-ops.h" |
43 #include "file-stat.h" | |
2937 | 44 #include "oct-syscalls.h" |
5547 | 45 #include "oct-uname.h" |
2926 | 46 |
2075 | 47 #include "defun.h" |
48 #include "error.h" | |
2078 | 49 #include "gripes.h" |
2075 | 50 #include "lo-utils.h" |
51 #include "oct-map.h" | |
52 #include "oct-obj.h" | |
53 #include "oct-stdstrm.h" | |
54 #include "oct-stream.h" | |
55 #include "sysdep.h" | |
56 #include "utils.h" | |
2366 | 57 #include "variables.h" |
6321 | 58 #include "input.h" |
2075 | 59 |
10762
d53eb6249892
use scalar map in some syscalls
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
60 static octave_scalar_map |
8549 | 61 mk_stat_map (const base_file_stat& fs) |
2075 | 62 { |
10762
d53eb6249892
use scalar map in some syscalls
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
63 octave_scalar_map m; |
2075 | 64 |
4675 | 65 m.assign ("dev", static_cast<double> (fs.dev ())); |
66 m.assign ("ino", fs.ino ()); | |
5476 | 67 m.assign ("mode", fs.mode ()); |
4675 | 68 m.assign ("modestr", fs.mode_as_string ()); |
69 m.assign ("nlink", fs.nlink ()); | |
70 m.assign ("uid", fs.uid ()); | |
71 m.assign ("gid", fs.gid ()); | |
3887 | 72 #if defined (HAVE_STRUCT_STAT_ST_RDEV) |
4675 | 73 m.assign ("rdev", static_cast<double> (fs.rdev ())); |
2075 | 74 #endif |
4675 | 75 m.assign ("size", fs.size ()); |
76 m.assign ("atime", fs.atime ()); | |
77 m.assign ("mtime", fs.mtime ()); | |
78 m.assign ("ctime", fs.ctime ()); | |
3887 | 79 #if defined (HAVE_STRUCT_STAT_ST_BLKSIZE) |
4675 | 80 m.assign ("blksize", fs.blksize ()); |
2075 | 81 #endif |
3887 | 82 #if defined (HAVE_STRUCT_STAT_ST_BLOCKS) |
4675 | 83 m.assign ("blocks", fs.blocks ()); |
2075 | 84 #endif |
85 | |
86 return m; | |
87 } | |
88 | |
10336
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
89 static octave_value_list |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
90 mk_stat_result (const base_file_stat& fs) |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
91 { |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
92 octave_value_list retval; |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
93 |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
94 if (fs) |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
95 { |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
96 retval(2) = std::string (); |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
97 retval(1) = 0; |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
98 retval(0) = octave_value (mk_stat_map (fs)); |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
99 } |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
100 else |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
101 { |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
102 retval(2) = fs.error (); |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
103 retval(1) = -1; |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
104 retval(0) = Matrix (); |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
105 } |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
106 |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
107 return retval; |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
108 } |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
109 |
10299
c992efc0c2fa
use DEFUNX instead of DEFUN for all functions in syscalls.cc
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
110 DEFUNX ("dup2", Fdup2, args, , |
3301 | 111 "-*- texinfo -*-\n\ |
112 @deftypefn {Built-in Function} {[@var{fid}, @var{msg}] =} dup2 (@var{old}, @var{new})\n\ | |
2669 | 113 Duplicate a file descriptor.\n\ |
114 \n\ | |
3301 | 115 If successful, @var{fid} is greater than zero and contains the new file\n\ |
116 ID. Otherwise, @var{fid} is negative and @var{msg} contains a\n\ | |
117 system-dependent error message.\n\ | |
118 @end deftypefn") | |
2075 | 119 { |
2669 | 120 octave_value_list retval; |
121 | |
3523 | 122 retval(1) = std::string (); |
4294 | 123 retval(0) = -1; |
2075 | 124 |
125 int nargin = args.length (); | |
126 | |
127 if (nargin == 2) | |
128 { | |
3341 | 129 octave_stream old_stream |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
130 = octave_stream_list::lookup (args(0), "dup2"); |
2075 | 131 |
3341 | 132 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
133 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
134 octave_stream new_stream |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
135 = octave_stream_list::lookup (args(1), "dup2"); |
2075 | 136 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
137 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
138 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
139 int i_old = old_stream.file_number (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
140 int i_new = new_stream.file_number (); |
2937 | 141 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
142 if (i_old >= 0 && i_new >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
143 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
144 std::string msg; |
2669 | 145 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
146 int status = octave_syscalls::dup2 (i_old, i_new, msg); |
3341 | 147 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
148 retval(0) = status; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
149 retval(1) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
150 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
151 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
152 } |
3145 | 153 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
154 error ("dup2: invalid stream"); |
2075 | 155 } |
156 else | |
5823 | 157 print_usage (); |
2075 | 158 |
159 return retval; | |
160 } | |
161 | |
10299
c992efc0c2fa
use DEFUNX instead of DEFUN for all functions in syscalls.cc
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
162 DEFUNX ("exec", Fexec, args, , |
3301 | 163 "-*- texinfo -*-\n\ |
164 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} exec (@var{file}, @var{args})\n\ | |
165 Replace current process with a new process. Calling @code{exec} without\n\ | |
166 first calling @code{fork} will terminate your current Octave process and\n\ | |
167 replace it with the program named by @var{file}. For example,\n\ | |
2669 | 168 \n\ |
3301 | 169 @example\n\ |
170 exec (\"ls\" \"-l\")\n\ | |
171 @end example\n\ | |
2669 | 172 \n\ |
3301 | 173 @noindent\n\ |
174 will run @code{ls} and return you to your shell prompt.\n\ | |
175 \n\ | |
176 If successful, @code{exec} does not return. If @code{exec} does return,\n\ | |
177 @var{err} will be nonzero, and @var{msg} will contain a system-dependent\n\ | |
178 error message.\n\ | |
179 @end deftypefn") | |
2075 | 180 { |
2669 | 181 octave_value_list retval; |
182 | |
3523 | 183 retval(1) = std::string (); |
4294 | 184 retval(0) = -1; |
2075 | 185 |
186 int nargin = args.length (); | |
187 | |
188 if (nargin == 1 || nargin == 2) | |
189 { | |
3523 | 190 std::string exec_file = args(0).string_value (); |
2075 | 191 |
192 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
193 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
194 string_vector exec_args; |
2075 | 195 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
196 if (nargin == 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
197 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
198 string_vector tmp = args(1).all_strings (); |
2075 | 199 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
200 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
201 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
202 int len = tmp.length (); |
2075 | 203 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
204 exec_args.resize (len + 1); |
2075 | 205 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
206 exec_args[0] = exec_file; |
2075 | 207 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
208 for (int i = 0; i < len; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
209 exec_args[i+1] = tmp[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
210 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
211 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
212 error ("exec: arguments must be character strings"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
213 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
214 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
215 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
216 exec_args.resize (1); |
2075 | 217 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
218 exec_args[0] = exec_file; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
219 } |
2075 | 220 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
221 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
222 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
223 std::string msg; |
2937 | 224 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
225 int status = octave_syscalls::execvp (exec_file, exec_args, msg); |
2669 | 226 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
227 retval(0) = status; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
228 retval(1) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
229 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
230 } |
2075 | 231 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
232 error ("exec: first argument must be a string"); |
2075 | 233 } |
234 else | |
5823 | 235 print_usage (); |
2075 | 236 |
237 return retval; | |
238 } | |
239 | |
10299
c992efc0c2fa
use DEFUNX instead of DEFUN for all functions in syscalls.cc
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
240 DEFUNX ("popen2", Fpopen2, args, , |
6321 | 241 "-*- texinfo -*-\n\ |
6678 | 242 @deftypefn {Built-in Function} {[@var{in}, @var{out}, @var{pid}] =} popen2 (@var{command}, @var{args})\n\ |
6321 | 243 Start a subprocess with two-way communication. The name of the process\n\ |
244 is given by @var{command}, and @var{args} is an array of strings\n\ | |
245 containing options for the command. The file identifiers for the input\n\ | |
246 and output streams of the subprocess are returned in @var{in} and\n\ | |
247 @var{out}. If execution of the command is successful, @var{pid}\n\ | |
248 contains the process ID of the subprocess. Otherwise, @var{pid} is\n\ | |
249 @minus{}1.\n\ | |
250 \n\ | |
251 For example,\n\ | |
252 \n\ | |
253 @example\n\ | |
6923 | 254 [in, out, pid] = popen2 (\"sort\", \"-r\");\n\ |
6321 | 255 fputs (in, \"these\\nare\\nsome\\nstrings\\n\");\n\ |
256 fclose (in);\n\ | |
257 EAGAIN = errno (\"EAGAIN\");\n\ | |
258 done = false;\n\ | |
259 do\n\ | |
260 s = fgets (out);\n\ | |
261 if (ischar (s))\n\ | |
262 fputs (stdout, s);\n\ | |
263 elseif (errno () == EAGAIN)\n\ | |
264 sleep (0.1);\n\ | |
265 fclear (out);\n\ | |
266 else\n\ | |
267 done = true;\n\ | |
268 endif\n\ | |
269 until (done)\n\ | |
270 fclose (out);\n\ | |
9563
f5c28d8f5147
syscalls.cc: Recommend waitpid() in popen2() documentation.
Rob Mahurin <rob@utk.edu>
parents:
9209
diff
changeset
|
271 waitpid (pid);\n\ |
f5c28d8f5147
syscalls.cc: Recommend waitpid() in popen2() documentation.
Rob Mahurin <rob@utk.edu>
parents:
9209
diff
changeset
|
272 @print{} these\n\ |
6321 | 273 @print{} strings\n\ |
9563
f5c28d8f5147
syscalls.cc: Recommend waitpid() in popen2() documentation.
Rob Mahurin <rob@utk.edu>
parents:
9209
diff
changeset
|
274 @print{} some\n\ |
f5c28d8f5147
syscalls.cc: Recommend waitpid() in popen2() documentation.
Rob Mahurin <rob@utk.edu>
parents:
9209
diff
changeset
|
275 @print{} are\n\ |
6321 | 276 @end example\n\ |
9563
f5c28d8f5147
syscalls.cc: Recommend waitpid() in popen2() documentation.
Rob Mahurin <rob@utk.edu>
parents:
9209
diff
changeset
|
277 \n\ |
f5c28d8f5147
syscalls.cc: Recommend waitpid() in popen2() documentation.
Rob Mahurin <rob@utk.edu>
parents:
9209
diff
changeset
|
278 Note that @code{popen2}, unlike @code{popen}, will not \"reap\" the\n\ |
f5c28d8f5147
syscalls.cc: Recommend waitpid() in popen2() documentation.
Rob Mahurin <rob@utk.edu>
parents:
9209
diff
changeset
|
279 child process. If you don't use @code{waitpid} to check the child's\n\ |
9564 | 280 exit status, it will linger until Octave exits.\n\ |
6321 | 281 @end deftypefn") |
282 { | |
283 octave_value_list retval; | |
284 | |
285 retval(2) = -1; | |
286 retval(1) = Matrix (); | |
287 retval(0) = Matrix (); | |
288 | |
289 int nargin = args.length (); | |
290 | |
291 if (nargin >= 1 && nargin <= 3) | |
292 { | |
293 std::string exec_file = args(0).string_value(); | |
294 | |
295 if (! error_state) | |
296 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
297 string_vector arg_list; |
6321 | 298 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
299 if (nargin >= 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
300 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
301 string_vector tmp = args(1).all_strings (); |
6321 | 302 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
303 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
304 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
305 int len = tmp.length (); |
6321 | 306 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
307 arg_list.resize (len + 1); |
6321 | 308 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
309 arg_list[0] = exec_file; |
6321 | 310 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
311 for (int i = 0; i < len; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
312 arg_list[i+1] = tmp[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
313 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
314 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
315 error ("popen2: arguments must be character strings"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
316 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
317 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
318 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
319 arg_list.resize (1); |
6321 | 320 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
321 arg_list[0] = exec_file; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
322 } |
6321 | 323 |
324 if (! error_state) | |
325 { | |
326 bool sync_mode = (nargin == 3 ? args(2).bool_value() : false); | |
327 | |
328 if (! error_state) | |
329 { | |
330 int fildes[2]; | |
331 std::string msg; | |
332 pid_t pid; | |
333 | |
334 pid = octave_syscalls::popen2 (exec_file, arg_list, sync_mode, fildes, msg, interactive); | |
335 if (pid >= 0) | |
336 { | |
337 FILE *ifile = fdopen (fildes[1], "r"); | |
338 FILE *ofile = fdopen (fildes[0], "w"); | |
339 | |
340 std::string nm; | |
341 | |
342 octave_stream is = octave_stdiostream::create (nm, ifile, | |
343 std::ios::in); | |
344 | |
345 octave_stream os = octave_stdiostream::create (nm, ofile, | |
346 std::ios::out); | |
347 | |
348 Cell file_ids (1, 2); | |
349 | |
350 retval(0) = octave_stream_list::insert (os); | |
351 retval(1) = octave_stream_list::insert (is); | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
352 retval(2) = pid; |
6321 | 353 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
354 else |
6321 | 355 error (msg.c_str ()); |
356 } | |
357 } | |
358 else | |
359 error ("popen2: arguments must be character strings"); | |
360 } | |
361 else | |
362 error ("popen2: first argument must be a string"); | |
363 } | |
364 else | |
365 print_usage (); | |
366 | |
367 return retval; | |
368 } | |
369 | |
370 /* | |
371 | |
372 %!test | |
373 %! if (isunix()) | |
6923 | 374 %! [in, out, pid] = popen2 ("sort", "-r"); |
6321 | 375 %! EAGAIN = errno ("EAGAIN"); |
376 %! else | |
6322 | 377 %! [in, out, pid] = popen2 ("sort", "/R"); |
6321 | 378 %! EAGAIN = errno ("EINVAL"); |
379 %! endif | |
380 %! fputs (in, "these\nare\nsome\nstrings\n"); | |
381 %! fclose (in); | |
382 %! done = false; | |
383 %! str = {}; | |
384 %! idx = 0; | |
6545 | 385 %! errs = 0; |
6321 | 386 %! do |
387 %! if (!isunix()) | |
388 %! errno (0); | |
389 %! endif | |
390 %! s = fgets (out); | |
391 %! if (ischar (s)) | |
392 %! idx++; | |
393 %! str{idx} = s; | |
394 %! elseif (errno () == EAGAIN) | |
6543 | 395 %! fclear (out); |
6321 | 396 %! sleep (0.1); |
6545 | 397 %! if (++errs == 100) |
398 %! done = true; | |
399 %! endif | |
6321 | 400 %! else |
401 %! done = true; | |
402 %! endif | |
6545 | 403 %! until (done) |
6321 | 404 %! fclose (out); |
6324 | 405 %! if (isunix()) |
6322 | 406 %! assert(str,{"these\n","strings\n","some\n","are\n"}) |
407 %! else | |
408 %! assert(str,{"these\r\n","strings\r\n","some\r\n","are\r\n"}) | |
409 %! end | |
6321 | 410 |
411 */ | |
412 | |
10259 | 413 DEFUNX ("fcntl", Ffcntl, args, , |
3301 | 414 "-*- texinfo -*-\n\ |
415 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} fcntl (@var{fid}, @var{request}, @var{arg})\n\ | |
416 Change the properties of the open file @var{fid}. The following values\n\ | |
417 may be passed as @var{request}:\n\ | |
418 \n\ | |
419 @vtable @code\n\ | |
420 @item F_DUPFD\n\ | |
421 Return a duplicate file descriptor.\n\ | |
422 \n\ | |
423 @item F_GETFD\n\ | |
424 Return the file descriptor flags for @var{fid}.\n\ | |
425 \n\ | |
426 @item F_SETFD\n\ | |
427 Set the file descriptor flags for @var{fid}.\n\ | |
428 \n\ | |
429 @item F_GETFL\n\ | |
430 Return the file status flags for @var{fid}. The following codes may be\n\ | |
431 returned (some of the flags may be undefined on some systems).\n\ | |
432 \n\ | |
433 @vtable @code\n\ | |
434 @item O_RDONLY\n\ | |
435 Open for reading only.\n\ | |
436 \n\ | |
437 @item O_WRONLY\n\ | |
438 Open for writing only.\n\ | |
2669 | 439 \n\ |
3301 | 440 @item O_RDWR\n\ |
441 Open for reading and writing.\n\ | |
442 \n\ | |
443 @item O_APPEND\n\ | |
444 Append on each write.\n\ | |
445 \n\ | |
5040 | 446 @item O_CREAT\n\ |
447 Create the file if it does not exist.\n\ | |
448 \n\ | |
3301 | 449 @item O_NONBLOCK\n\ |
450 Nonblocking mode.\n\ | |
451 \n\ | |
452 @item O_SYNC\n\ | |
453 Wait for writes to complete.\n\ | |
2669 | 454 \n\ |
3301 | 455 @item O_ASYNC\n\ |
456 Asynchronous I/O.\n\ | |
457 @end vtable\n\ | |
458 \n\ | |
459 @item F_SETFL\n\ | |
460 Set the file status flags for @var{fid} to the value specified by\n\ | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
461 @var{arg}. The only flags that can be changed are @w{@code{O_APPEND}} and\n\ |
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
462 @w{@code{O_NONBLOCK}}.\n\ |
3301 | 463 @end vtable\n\ |
464 \n\ | |
465 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ | |
466 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
467 system-dependent error message.\n\ | |
468 @end deftypefn") | |
2075 | 469 { |
2669 | 470 octave_value_list retval; |
471 | |
3523 | 472 retval(1) = std::string (); |
4294 | 473 retval(0) = -1; |
2075 | 474 |
475 int nargin = args.length (); | |
476 | |
477 if (nargin == 3) | |
478 { | |
3715 | 479 octave_stream strm = octave_stream_list::lookup (args (0), "fcntl"); |
2075 | 480 |
3202 | 481 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
482 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
483 int fid = strm.file_number (); |
3715 | 484 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
485 int req = args(1).int_value (true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
486 int arg = args(2).int_value (true); |
3715 | 487 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
488 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
489 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
490 // FIXME -- Need better checking here? |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
491 if (fid < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
492 error ("fcntl: invalid file id"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
493 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
494 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
495 std::string msg; |
2937 | 496 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
497 int status = octave_fcntl (fid, req, arg, msg); |
2669 | 498 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
499 retval(0) = status; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
500 retval(1) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
501 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
502 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
503 } |
2075 | 504 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
505 error ("fcntl: file id, request, and argument must be integers"); |
2075 | 506 } |
507 else | |
5823 | 508 print_usage (); |
2075 | 509 |
510 return retval; | |
511 } | |
512 | |
10299
c992efc0c2fa
use DEFUNX instead of DEFUN for all functions in syscalls.cc
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
513 DEFUNX ("fork", Ffork, args, , |
3301 | 514 "-*- texinfo -*-\n\ |
515 @deftypefn {Built-in Function} {[@var{pid}, @var{msg}] =} fork ()\n\ | |
2669 | 516 Create a copy of the current process.\n\ |
517 \n\ | |
3301 | 518 Fork can return one of the following values:\n\ |
519 \n\ | |
520 @table @asis\n\ | |
521 @item > 0\n\ | |
522 You are in the parent process. The value returned from @code{fork} is\n\ | |
523 the process id of the child process. You should probably arrange to\n\ | |
524 wait for any child processes to exit.\n\ | |
525 \n\ | |
526 @item 0\n\ | |
527 You are in the child process. You can call @code{exec} to start another\n\ | |
528 process. If that fails, you should probably call @code{exit}.\n\ | |
529 \n\ | |
530 @item < 0\n\ | |
531 The call to @code{fork} failed for some reason. You must take evasive\n\ | |
532 action. A system dependent error message will be waiting in @var{msg}.\n\ | |
533 @end table\n\ | |
534 @end deftypefn") | |
2075 | 535 { |
2669 | 536 octave_value_list retval; |
537 | |
3523 | 538 retval(1) = std::string (); |
4294 | 539 retval(0) = -1; |
2075 | 540 |
541 int nargin = args.length (); | |
542 | |
543 if (nargin == 0) | |
2475 | 544 { |
3523 | 545 std::string msg; |
2937 | 546 |
547 pid_t pid = octave_syscalls::fork (msg); | |
2669 | 548 |
4233 | 549 retval(0) = pid; |
2937 | 550 retval(1) = msg; |
2475 | 551 } |
2075 | 552 else |
5823 | 553 print_usage (); |
2075 | 554 |
555 return retval; | |
556 } | |
557 | |
10299
c992efc0c2fa
use DEFUNX instead of DEFUN for all functions in syscalls.cc
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
558 DEFUNX ("getpgrp", Fgetpgrp, args, , |
3301 | 559 "-*- texinfo -*-\n\ |
560 @deftypefn {Built-in Function} {pgid =} getpgrp ()\n\ | |
561 Return the process group id of the current process.\n\ | |
562 @end deftypefn") | |
2075 | 563 { |
2937 | 564 octave_value_list retval; |
565 | |
3523 | 566 retval(1) = std::string (); |
4294 | 567 retval(0) = -1; |
2075 | 568 |
569 int nargin = args.length (); | |
570 | |
571 if (nargin == 0) | |
2475 | 572 { |
3523 | 573 std::string msg; |
2937 | 574 |
4233 | 575 retval(0) = octave_syscalls::getpgrp (msg); |
2937 | 576 retval(1) = msg; |
2475 | 577 } |
2075 | 578 else |
5823 | 579 print_usage (); |
2075 | 580 |
581 return retval; | |
582 } | |
583 | |
10299
c992efc0c2fa
use DEFUNX instead of DEFUN for all functions in syscalls.cc
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
584 DEFUNX ("getpid", Fgetpid, args, , |
3301 | 585 "-*- texinfo -*-\n\ |
586 @deftypefn {Built-in Function} {pid =} getpid ()\n\ | |
587 Return the process id of the current process.\n\ | |
588 @end deftypefn") | |
2075 | 589 { |
4233 | 590 octave_value retval = -1; |
2075 | 591 |
592 int nargin = args.length (); | |
593 | |
594 if (nargin == 0) | |
2937 | 595 retval = octave_syscalls::getpid (); |
2075 | 596 else |
5823 | 597 print_usage (); |
2075 | 598 |
599 return retval; | |
600 } | |
601 | |
10299
c992efc0c2fa
use DEFUNX instead of DEFUN for all functions in syscalls.cc
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
602 DEFUNX ("getppid", Fgetppid, args, , |
3301 | 603 "-*- texinfo -*-\n\ |
604 @deftypefn {Built-in Function} {pid =} getppid ()\n\ | |
605 Return the process id of the parent process.\n\ | |
606 @end deftypefn") | |
2075 | 607 { |
4233 | 608 octave_value retval = -1; |
2075 | 609 |
2475 | 610 int nargin = args.length (); |
611 | |
612 if (nargin == 0) | |
2937 | 613 retval = octave_syscalls::getppid (); |
2475 | 614 else |
5823 | 615 print_usage (); |
2475 | 616 |
617 return retval; | |
618 } | |
619 | |
10299
c992efc0c2fa
use DEFUNX instead of DEFUN for all functions in syscalls.cc
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
620 DEFUNX ("getegid", Fgetegid, args, , |
3301 | 621 "-*- texinfo -*-\n\ |
622 @deftypefn {Built-in Function} {egid =} getegid ()\n\ | |
623 Return the effective group id of the current process.\n\ | |
624 @end deftypefn") | |
2475 | 625 { |
4233 | 626 octave_value retval = -1; |
2475 | 627 |
2075 | 628 int nargin = args.length (); |
629 | |
630 if (nargin == 0) | |
4254 | 631 retval = octave_syscalls::getegid (); |
2075 | 632 else |
5823 | 633 print_usage (); |
2475 | 634 |
635 return retval; | |
636 } | |
637 | |
10299
c992efc0c2fa
use DEFUNX instead of DEFUN for all functions in syscalls.cc
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
638 DEFUNX ("getgid", Fgetgid, args, , |
3301 | 639 "-*- texinfo -*-\n\ |
640 @deftypefn {Built-in Function} {gid =} getgid ()\n\ | |
641 Return the real group id of the current process.\n\ | |
642 @end deftypefn") | |
2475 | 643 { |
4233 | 644 octave_value retval = -1; |
2475 | 645 |
646 int nargin = args.length (); | |
647 | |
648 if (nargin == 0) | |
4254 | 649 retval = octave_syscalls::getgid (); |
2475 | 650 else |
5823 | 651 print_usage (); |
2075 | 652 |
653 return retval; | |
654 } | |
655 | |
10299
c992efc0c2fa
use DEFUNX instead of DEFUN for all functions in syscalls.cc
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
656 DEFUNX ("geteuid", Fgeteuid, args, , |
3301 | 657 "-*- texinfo -*-\n\ |
658 @deftypefn {Built-in Function} {euid =} geteuid ()\n\ | |
659 Return the effective user id of the current process.\n\ | |
660 @end deftypefn") | |
2472 | 661 { |
4233 | 662 octave_value retval = -1; |
2472 | 663 |
664 int nargin = args.length (); | |
665 | |
666 if (nargin == 0) | |
4254 | 667 retval = octave_syscalls::geteuid (); |
2472 | 668 else |
5823 | 669 print_usage (); |
2473 | 670 |
671 return retval; | |
2472 | 672 } |
673 | |
10299
c992efc0c2fa
use DEFUNX instead of DEFUN for all functions in syscalls.cc
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
674 DEFUNX ("getuid", Fgetuid, args, , |
3301 | 675 "-*- texinfo -*-\n\ |
676 @deftypefn {Built-in Function} {uid =} getuid ()\n\ | |
677 Return the real user id of the current process.\n\ | |
678 @end deftypefn") | |
2472 | 679 { |
4233 | 680 octave_value retval = -1; |
2472 | 681 |
682 int nargin = args.length (); | |
683 | |
684 if (nargin == 0) | |
4254 | 685 retval = octave_syscalls::getuid (); |
2472 | 686 else |
5823 | 687 print_usage (); |
2473 | 688 |
689 return retval; | |
2472 | 690 } |
691 | |
10299
c992efc0c2fa
use DEFUNX instead of DEFUN for all functions in syscalls.cc
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
692 DEFUNX ("kill", Fkill, args, , |
4371 | 693 "-*- texinfo -*-\n\ |
4294 | 694 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} kill (@var{pid}, @var{sig})\n\ |
695 Send signal @var{sig} to process @var{pid}.\n\ | |
696 \n\ | |
697 If @var{pid} is positive, then signal @var{sig} is sent to @var{pid}.\n\ | |
698 \n\ | |
699 If @var{pid} is 0, then signal @var{sig} is sent to every process\n\ | |
700 in the process group of the current process.\n\ | |
701 \n\ | |
702 If @var{pid} is -1, then signal @var{sig} is sent to every process\n\ | |
703 except process 1.\n\ | |
704 \n\ | |
705 If @var{pid} is less than -1, then signal @var{sig} is sent to every\n\ | |
706 process in the process group @var{-pid}.\n\ | |
707 \n\ | |
4371 | 708 If @var{sig} is 0, then no signal is sent, but error checking is still\n\ |
4294 | 709 performed.\n\ |
710 \n\ | |
7001 | 711 Return 0 if successful, otherwise return -1.\n\ |
4294 | 712 @end deftypefn") |
713 { | |
714 octave_value_list retval; | |
715 | |
716 retval(1) = std::string (); | |
717 retval(0) = -1; | |
718 | |
719 if (args.length () == 2) | |
720 { | |
721 pid_t pid = args(0).int_value (true); | |
722 | |
723 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
724 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
725 int sig = args(1).int_value (true); |
4294 | 726 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
727 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
728 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
729 std::string msg; |
4294 | 730 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
731 int status = octave_syscalls::kill (pid, sig, msg); |
4294 | 732 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
733 retval(1) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
734 retval(0) = status; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
735 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
736 } |
4294 | 737 } |
738 else | |
5823 | 739 print_usage (); |
4294 | 740 |
741 return retval; | |
742 } | |
743 | |
10299
c992efc0c2fa
use DEFUNX instead of DEFUN for all functions in syscalls.cc
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
744 DEFUNX ("lstat", Flstat, args, , |
3458 | 745 "-*- texinfo -*-\n\ |
746 @deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{file})\n\ | |
747 See stat.\n\ | |
748 @end deftypefn") | |
2075 | 749 { |
2263 | 750 octave_value_list retval; |
2075 | 751 |
752 if (args.length () == 1) | |
753 { | |
5872 | 754 std::string fname = args(0).string_value (); |
2075 | 755 |
756 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
757 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
758 file_stat fs (fname, false); |
2075 | 759 |
10336
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
760 retval = mk_stat_result (fs); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
761 } |
2075 | 762 } |
763 else | |
5823 | 764 print_usage (); |
2075 | 765 |
766 return retval; | |
767 } | |
768 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
769 DEFUNX ("mkfifo", Fmkfifo, args, , |
3345 | 770 "-*- texinfo -*-\n\ |
4825 | 771 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} mkfifo (@var{name}, @var{mode})\n\ |
4928 | 772 Create a @var{fifo} special file named @var{name} with file mode @var{mode}\n\ |
2075 | 773 \n\ |
3301 | 774 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
775 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
776 system-dependent error message.\n\ | |
777 @end deftypefn") | |
2075 | 778 { |
2669 | 779 octave_value_list retval; |
780 | |
3523 | 781 retval(1) = std::string (); |
4294 | 782 retval(0) = -1; |
2075 | 783 |
784 int nargin = args.length (); | |
785 | |
786 if (nargin == 2) | |
787 { | |
788 if (args(0).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
789 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
790 std::string name = args(0).string_value (); |
2075 | 791 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
792 if (args(1).is_scalar_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
793 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
794 long mode = args(1).long_value (); |
2075 | 795 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
796 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
797 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
798 std::string msg; |
4254 | 799 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
800 int status = octave_mkfifo (name, mode, msg); |
2669 | 801 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
802 retval(0) = status; |
2669 | 803 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
804 if (status < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
805 retval(1) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
806 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
807 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
808 error ("mkfifo: invalid MODE"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
809 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
810 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
811 error ("mkfifo: MODE must be an integer"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
812 } |
2075 | 813 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
814 error ("mkfifo: file name must be a string"); |
2075 | 815 } |
816 else | |
5823 | 817 print_usage (); |
2075 | 818 |
819 return retval; | |
820 } | |
821 | |
10299
c992efc0c2fa
use DEFUNX instead of DEFUN for all functions in syscalls.cc
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
822 DEFUNX ("pipe", Fpipe, args, , |
3301 | 823 "-*- texinfo -*-\n\ |
6321 | 824 @deftypefn {Built-in Function} {[@var{read_fd}, @var{write_fd}, @var{err}, @var{msg}] =} pipe ()\n\ |
825 Create a pipe and return the reading and writing ends of the pipe\n\ | |
826 into @var{read_fd} and @var{write_fd} respectively.\n\ | |
2669 | 827 \n\ |
3301 | 828 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
829 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
830 system-dependent error message.\n\ | |
831 @end deftypefn") | |
2075 | 832 { |
2669 | 833 octave_value_list retval; |
834 | |
6321 | 835 retval(3) = std::string (); |
836 retval(2) = -1; | |
4294 | 837 retval(1) = -1; |
6321 | 838 retval(0) = -1; |
2075 | 839 |
840 int nargin = args.length (); | |
841 | |
842 if (nargin == 0) | |
843 { | |
844 int fid[2]; | |
845 | |
3523 | 846 std::string msg; |
2937 | 847 |
848 int status = octave_syscalls::pipe (fid, msg); | |
2669 | 849 |
850 if (status < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
851 retval(3) = msg; |
2669 | 852 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
853 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
854 FILE *ifile = fdopen (fid[0], "r"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
855 FILE *ofile = fdopen (fid[1], "w"); |
2075 | 856 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
857 std::string nm; |
4327 | 858 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
859 octave_stream is = octave_stdiostream::create (nm, ifile, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
860 std::ios::in); |
4327 | 861 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
862 octave_stream os = octave_stdiostream::create (nm, ofile, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
863 std::ios::out); |
2075 | 864 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
865 retval(1) = octave_stream_list::insert (os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
866 retval(0) = octave_stream_list::insert (is); |
2075 | 867 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
868 retval(2) = status; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
869 } |
2075 | 870 } |
871 else | |
5823 | 872 print_usage (); |
2075 | 873 |
874 return retval; | |
875 } | |
876 | |
10299
c992efc0c2fa
use DEFUNX instead of DEFUN for all functions in syscalls.cc
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
877 DEFUNX ("stat", Fstat, args, , |
3301 | 878 "-*- texinfo -*-\n\ |
879 @deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} stat (@var{file})\n\ | |
880 @deftypefnx {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{file})\n\ | |
881 Return a structure @var{s} containing the following information about\n\ | |
882 @var{file}.\n\ | |
883 \n\ | |
884 @table @code\n\ | |
885 @item dev\n\ | |
886 ID of device containing a directory entry for this file.\n\ | |
887 \n\ | |
888 @item ino\n\ | |
889 File number of the file.\n\ | |
890 \n\ | |
5476 | 891 @item mode\n\ |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
892 File mode, as an integer. Use the functions @w{@code{S_ISREG}},\n\ |
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
893 @w{@code{S_ISDIR}}, @w{@code{S_ISCHR}}, @w{@code{S_ISBLK}}, @w{@code{S_ISFIFO}},\n\ |
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
894 @w{@code{S_ISLNK}}, or @w{@code{S_ISSOCK}} to extract information from this\n\ |
5476 | 895 value.\n\ |
896 \n\ | |
3301 | 897 @item modestr\n\ |
898 File mode, as a string of ten letters or dashes as would be returned by\n\ | |
899 @kbd{ls -l}.\n\ | |
900 \n\ | |
901 @item nlink\n\ | |
902 Number of links.\n\ | |
2075 | 903 \n\ |
3301 | 904 @item uid\n\ |
905 User ID of file's owner.\n\ | |
906 \n\ | |
907 @item gid\n\ | |
908 Group ID of file's group.\n\ | |
909 \n\ | |
910 @item rdev\n\ | |
911 ID of device for block or character special files.\n\ | |
912 \n\ | |
913 @item size\n\ | |
914 Size in bytes.\n\ | |
915 \n\ | |
916 @item atime\n\ | |
917 Time of last access in the same form as time values returned from\n\ | |
918 @code{time}. @xref{Timing Utilities}.\n\ | |
919 \n\ | |
920 @item mtime\n\ | |
921 Time of last modification in the same form as time values returned from\n\ | |
922 @code{time}. @xref{Timing Utilities}.\n\ | |
2075 | 923 \n\ |
3301 | 924 @item ctime\n\ |
925 Time of last file status change in the same form as time values\n\ | |
926 returned from @code{time}. @xref{Timing Utilities}.\n\ | |
927 \n\ | |
928 @item blksize\n\ | |
929 Size of blocks in the file.\n\ | |
930 \n\ | |
931 @item blocks\n\ | |
932 Number of blocks allocated for file.\n\ | |
933 @end table\n\ | |
934 \n\ | |
935 If the call is successful @var{err} is 0 and @var{msg} is an empty\n\ | |
936 string. If the file does not exist, or some other error occurs, @var{s}\n\ | |
937 is an empty matrix, @var{err} is @minus{}1, and @var{msg} contains the\n\ | |
938 corresponding system error message.\n\ | |
939 \n\ | |
940 If @var{file} is a symbolic link, @code{stat} will return information\n\ | |
7001 | 941 about the actual file that is referenced by the link. Use @code{lstat}\n\ |
3301 | 942 if you want information about the symbolic link itself.\n\ |
943 \n\ | |
944 For example,\n\ | |
2075 | 945 \n\ |
3301 | 946 @example\n\ |
947 [s, err, msg] = stat (\"/vmlinuz\")\n\ | |
948 @result{} s =\n\ | |
949 @{\n\ | |
950 atime = 855399756\n\ | |
951 rdev = 0\n\ | |
952 ctime = 847219094\n\ | |
953 uid = 0\n\ | |
954 size = 389218\n\ | |
955 blksize = 4096\n\ | |
956 mtime = 847219094\n\ | |
957 gid = 6\n\ | |
958 nlink = 1\n\ | |
959 blocks = 768\n\ | |
5476 | 960 mode = -rw-r--r--\n\ |
3301 | 961 modestr = -rw-r--r--\n\ |
962 ino = 9316\n\ | |
963 dev = 2049\n\ | |
964 @}\n\ | |
965 @result{} err = 0\n\ | |
966 @result{} msg = \n\ | |
967 @end example\n\ | |
968 @end deftypefn") | |
2075 | 969 { |
2262 | 970 octave_value_list retval; |
2075 | 971 |
972 if (args.length () == 1) | |
973 { | |
10336
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
974 if (args(0).is_scalar_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
975 { |
10336
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
976 int fid = octave_stream_list::get_file_number (args(0)); |
2075 | 977 |
10336
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
978 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
979 { |
10336
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
980 file_fstat fs (fid); |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
981 |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
982 retval = mk_stat_result (fs); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
983 } |
10336
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
984 } |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
985 else |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
986 { |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
987 std::string fname = args(0).string_value (); |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
988 |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
989 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
990 { |
10336
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
991 file_stat fs (fname); |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
992 |
1603dfe72933
obsolete fstat, handle the functionality by stat
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
993 retval = mk_stat_result (fs); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
994 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
995 } |
2075 | 996 } |
997 else | |
5823 | 998 print_usage (); |
2075 | 999 |
1000 return retval; | |
1001 } | |
1002 | |
5476 | 1003 DEFUNX ("S_ISREG", FS_ISREG, args, , |
1004 "-*- texinfo -*-\n\ | |
1005 @deftypefn {Built-in Function} {} S_ISREG (@var{mode})\n\ | |
1006 Return true if @var{mode} corresponds to a regular file. The value\n\ | |
1007 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ | |
1008 @seealso{stat, lstat}\n\ | |
1009 @end deftypefn") | |
1010 { | |
1011 octave_value retval = false; | |
1012 | |
1013 if (args.length () == 1) | |
1014 { | |
1015 double mode = args(0).double_value (); | |
1016 | |
1017 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1018 retval = file_stat::is_reg (static_cast<mode_t> (mode)); |
5476 | 1019 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1020 error ("S_ISREG: invalid mode value"); |
5476 | 1021 } |
1022 else | |
5823 | 1023 print_usage (); |
5476 | 1024 |
1025 return retval; | |
1026 } | |
1027 | |
1028 DEFUNX ("S_ISDIR", FS_ISDIR, args, , | |
1029 "-*- texinfo -*-\n\ | |
1030 @deftypefn {Built-in Function} {} S_ISDIR (@var{mode})\n\ | |
1031 Return true if @var{mode} corresponds to a directory. The value\n\ | |
1032 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ | |
1033 @seealso{stat, lstat}\n\ | |
1034 @end deftypefn") | |
1035 { | |
1036 octave_value retval = false; | |
1037 | |
1038 if (args.length () == 1) | |
1039 { | |
1040 double mode = args(0).double_value (); | |
1041 | |
1042 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1043 retval = file_stat::is_dir (static_cast<mode_t> (mode)); |
5476 | 1044 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1045 error ("S_ISDIR: invalid mode value"); |
5476 | 1046 } |
1047 else | |
5823 | 1048 print_usage (); |
5476 | 1049 |
1050 return retval; | |
1051 } | |
1052 | |
1053 DEFUNX ("S_ISCHR", FS_ISCHR, args, , | |
1054 "-*- texinfo -*-\n\ | |
1055 @deftypefn {Built-in Function} {} S_ISCHR (@var{mode})\n\ | |
1056 Return true if @var{mode} corresponds to a character devicey. The value\n\ | |
1057 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ | |
1058 @seealso{stat, lstat}\n\ | |
1059 @end deftypefn") | |
1060 { | |
1061 octave_value retval = false; | |
1062 | |
1063 if (args.length () == 1) | |
1064 { | |
1065 double mode = args(0).double_value (); | |
1066 | |
1067 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1068 retval = file_stat::is_chr (static_cast<mode_t> (mode)); |
5476 | 1069 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1070 error ("S_ISCHR: invalid mode value"); |
5476 | 1071 } |
1072 else | |
5823 | 1073 print_usage (); |
5476 | 1074 |
1075 return retval; | |
1076 } | |
1077 | |
1078 DEFUNX ("S_ISBLK", FS_ISBLK, args, , | |
1079 "-*- texinfo -*-\n\ | |
1080 @deftypefn {Built-in Function} {} S_ISBLK (@var{mode})\n\ | |
1081 Return true if @var{mode} corresponds to a block device. The value\n\ | |
1082 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ | |
1083 @seealso{stat, lstat}\n\ | |
1084 @end deftypefn") | |
1085 { | |
1086 octave_value retval = false; | |
1087 | |
1088 if (args.length () == 1) | |
1089 { | |
1090 double mode = args(0).double_value (); | |
1091 | |
1092 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1093 retval = file_stat::is_blk (static_cast<mode_t> (mode)); |
5476 | 1094 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1095 error ("S_ISBLK: invalid mode value"); |
5476 | 1096 } |
1097 else | |
5823 | 1098 print_usage (); |
5476 | 1099 |
1100 return retval; | |
1101 } | |
1102 | |
1103 DEFUNX ("S_ISFIFO", FS_ISFIFO, args, , | |
1104 "-*- texinfo -*-\n\ | |
1105 @deftypefn {Built-in Function} {} S_ISFIFO (@var{mode})\n\ | |
1106 Return true if @var{mode} corresponds to a fifo. The value\n\ | |
1107 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ | |
1108 @seealso{stat, lstat}\n\ | |
1109 @end deftypefn") | |
1110 { | |
1111 octave_value retval = false; | |
1112 | |
1113 if (args.length () == 1) | |
1114 { | |
1115 double mode = args(0).double_value (); | |
1116 | |
1117 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1118 retval = file_stat::is_fifo (static_cast<mode_t> (mode)); |
5476 | 1119 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1120 error ("S_ISFIFO: invalid mode value"); |
5476 | 1121 } |
1122 else | |
5823 | 1123 print_usage (); |
5476 | 1124 |
1125 return retval; | |
1126 } | |
1127 | |
1128 DEFUNX ("S_ISLNK", FS_ISLNK, args, , | |
1129 "-*- texinfo -*-\n\ | |
1130 @deftypefn {Built-in Function} {} S_ISLNK (@var{mode})\n\ | |
1131 Return true if @var{mode} corresponds to a symbolic link. The value\n\ | |
1132 of @var{mode} is assumed to be returned from a call to @code{stat}.\n\ | |
1133 @seealso{stat, lstat}\n\ | |
1134 @end deftypefn") | |
1135 { | |
1136 octave_value retval = false; | |
1137 | |
1138 if (args.length () == 1) | |
1139 { | |
1140 double mode = args(0).double_value (); | |
1141 | |
1142 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1143 retval = file_stat::is_lnk (static_cast<mode_t> (mode)); |
5476 | 1144 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1145 error ("S_ISLNK: invalid mode value"); |
5476 | 1146 } |
1147 else | |
5823 | 1148 print_usage (); |
5476 | 1149 |
1150 return retval; | |
1151 } | |
1152 | |
1153 DEFUNX ("S_ISSOCK", FS_ISSOCK, args, , | |
1154 "-*- texinfo -*-\n\ | |
1155 @deftypefn {Built-in Function} {} S_ISSOCK (@var{mode})\n\ | |
1156 @seealso{stat, lstat}\n\ | |
1157 @end deftypefn") | |
1158 { | |
1159 octave_value retval = false; | |
1160 | |
1161 if (args.length () == 1) | |
1162 { | |
1163 double mode = args(0).double_value (); | |
1164 | |
1165 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1166 retval = file_stat::is_sock (static_cast<mode_t> (mode)); |
5476 | 1167 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1168 error ("S_ISSOCK: invalid mode value"); |
5476 | 1169 } |
1170 else | |
5823 | 1171 print_usage (); |
5476 | 1172 |
1173 return retval; | |
1174 } | |
1175 | |
5547 | 1176 DEFUN (uname, args, , |
1177 "-*- texinfo -*-\n\ | |
1178 @deftypefn {Built-in Function} {[@var{uts}, @var{err}, @var{msg}] =} uname ()\n\ | |
1179 Return system information in the structure. For example,\n\ | |
1180 \n\ | |
1181 @example\n\ | |
1182 @group\n\ | |
1183 uname ()\n\ | |
1184 @result{} @{\n\ | |
5656 | 1185 sysname = x86_64\n\ |
1186 nodename = segfault\n\ | |
1187 release = 2.6.15-1-amd64-k8-smp\n\ | |
1188 version = Linux\n\ | |
1189 machine = #2 SMP Thu Feb 23 04:57:49 UTC 2006\n\ | |
5547 | 1190 @}\n\ |
1191 @end group\n\ | |
1192 @end example\n\ | |
1193 \n\ | |
1194 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ | |
1195 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
1196 system-dependent error message.\n\ | |
1197 @end deftypefn") | |
1198 { | |
1199 octave_value_list retval; | |
1200 | |
1201 if (args.length () == 0) | |
1202 { | |
1203 octave_uname sysinfo; | |
1204 | |
10762
d53eb6249892
use scalar map in some syscalls
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
1205 octave_scalar_map m; |
5547 | 1206 |
1207 m.assign ("sysname", sysinfo.sysname ()); | |
1208 m.assign ("nodename", sysinfo.nodename ()); | |
1209 m.assign ("release", sysinfo.release ()); | |
1210 m.assign ("version", sysinfo.version ()); | |
1211 m.assign ("machine", sysinfo.machine ()); | |
1212 | |
1213 retval(2) = sysinfo.message (); | |
1214 retval(1) = sysinfo.error (); | |
1215 retval(0) = m; | |
1216 } | |
1217 else | |
5823 | 1218 print_usage (); |
5547 | 1219 |
1220 return retval; | |
1221 } | |
1222 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1223 DEFUNX ("unlink", Funlink, args, , |
3301 | 1224 "-*- texinfo -*-\n\ |
1225 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} unlink (@var{file})\n\ | |
1226 Delete the file named @var{file}.\n\ | |
2075 | 1227 \n\ |
3301 | 1228 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
1229 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
1230 system-dependent error message.\n\ | |
1231 @end deftypefn") | |
2075 | 1232 { |
2669 | 1233 octave_value_list retval; |
1234 | |
3523 | 1235 retval(1) = std::string (); |
4294 | 1236 retval(0) = -1; |
2075 | 1237 |
1238 int nargin = args.length (); | |
1239 | |
1240 if (nargin == 1) | |
1241 { | |
1242 if (args(0).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1243 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1244 std::string name = args(0).string_value (); |
2075 | 1245 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1246 std::string msg; |
2669 | 1247 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1248 int status = octave_unlink (name, msg); |
2669 | 1249 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1250 retval(0) = status; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1251 retval(1) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1252 } |
2075 | 1253 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1254 error ("unlink: file name must be a string"); |
2075 | 1255 } |
1256 else | |
5823 | 1257 print_usage (); |
2075 | 1258 |
1259 return retval; | |
1260 } | |
1261 | |
10299
c992efc0c2fa
use DEFUNX instead of DEFUN for all functions in syscalls.cc
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1262 DEFUNX ("waitpid", Fwaitpid, args, , |
3301 | 1263 "-*- texinfo -*-\n\ |
5453 | 1264 @deftypefn {Built-in Function} {[@var{pid}, @var{status}, @var{msg}] =} waitpid (@var{pid}, @var{options})\n\ |
3301 | 1265 Wait for process @var{pid} to terminate. The @var{pid} argument can be:\n\ |
2075 | 1266 \n\ |
3301 | 1267 @table @asis\n\ |
1268 @item @minus{}1\n\ | |
1269 Wait for any child process.\n\ | |
2075 | 1270 \n\ |
3301 | 1271 @item 0\n\ |
1272 Wait for any child process whose process group ID is equal to that of\n\ | |
1273 the Octave interpreter process.\n\ | |
2075 | 1274 \n\ |
3301 | 1275 @item > 0\n\ |
1276 Wait for termination of the child process with ID @var{pid}.\n\ | |
1277 @end table\n\ | |
1278 \n\ | |
5453 | 1279 The @var{options} argument can be a bitwise OR of zero or more of\n\ |
1280 the following constants:\n\ | |
2075 | 1281 \n\ |
5453 | 1282 @table @code\n\ |
3301 | 1283 @item 0\n\ |
1284 Wait until signal is received or a child process exits (this is the\n\ | |
1285 default if the @var{options} argument is missing).\n\ | |
1286 \n\ | |
5453 | 1287 @item WNOHANG\n\ |
3301 | 1288 Do not hang if status is not immediately available.\n\ |
2075 | 1289 \n\ |
5453 | 1290 @item WUNTRACED\n\ |
3301 | 1291 Report the status of any child processes that are stopped, and whose\n\ |
1292 status has not yet been reported since they stopped.\n\ | |
1293 \n\ | |
8286
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7924
diff
changeset
|
1294 @item WCONTINUE\n\ |
5453 | 1295 Return if a stopped child has been resumed by delivery of @code{SIGCONT}.\n\ |
1296 This value may not be meaningful on all systems.\n\ | |
3301 | 1297 @end table\n\ |
1298 \n\ | |
1299 If the returned value of @var{pid} is greater than 0, it is the process\n\ | |
1300 ID of the child process that exited. If an error occurs, @var{pid} will\n\ | |
1301 be less than zero and @var{msg} will contain a system-dependent error\n\ | |
7001 | 1302 message. The value of @var{status} contains additional system-dependent\n\ |
5453 | 1303 information about the subprocess that exited.\n\ |
8286
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7924
diff
changeset
|
1304 @seealso{WCONTINUE, WCOREDUMP, WEXITSTATUS, WIFCONTINUED, WIFSIGNALED, WIFSTOPPED, WNOHANG, WSTOPSIG, WTERMSIG, WUNTRACED}\n\ |
3301 | 1305 @end deftypefn") |
2075 | 1306 { |
2669 | 1307 octave_value_list retval; |
1308 | |
5453 | 1309 retval(2) = std::string (); |
1310 retval(1) = 0; | |
4294 | 1311 retval(0) = -1; |
2075 | 1312 |
1313 int nargin = args.length (); | |
1314 | |
1315 if (nargin == 1 || nargin == 2) | |
1316 { | |
3202 | 1317 pid_t pid = args(0).int_value (true); |
2075 | 1318 |
1319 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1320 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1321 int options = 0; |
2075 | 1322 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1323 if (args.length () == 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1324 options = args(1).int_value (true); |
2937 | 1325 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1326 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1327 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1328 std::string msg; |
2669 | 1329 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1330 int status = 0; |
5453 | 1331 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1332 pid_t result = octave_syscalls::waitpid (pid, &status, options, msg); |
3202 | 1333 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1334 retval(0) = result; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1335 retval(1) = status; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1336 retval(2) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1337 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1338 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1339 error ("waitpid: OPTIONS must be an integer"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1340 } |
3202 | 1341 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1342 error ("waitpid: PID must be an integer value"); |
2075 | 1343 } |
1344 else | |
5823 | 1345 print_usage (); |
2075 | 1346 |
1347 return retval; | |
1348 } | |
1349 | |
5453 | 1350 DEFUNX ("WIFEXITED", FWIFEXITED, args, , |
1351 "-*- texinfo -*-\n\ | |
1352 @deftypefn {Built-in Function} {} WIFEXITED (@var{status})\n\ | |
1353 Given @var{status} from a call to @code{waitpid}, return true if the\n\ | |
1354 child terminated normally.\n\ | |
1355 @seealso{waitpid, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ | |
5646 | 1356 @end deftypefn") |
5453 | 1357 { |
1358 octave_value retval = 0.0; | |
1359 | |
1360 #if defined (WIFEXITED) | |
1361 if (args.length () == 1) | |
1362 { | |
1363 int status = args(0).int_value (); | |
1364 | |
1365 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1366 retval = WIFEXITED (status); |
5453 | 1367 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1368 error ("WIFEXITED: expecting integer argument"); |
5453 | 1369 } |
1370 #else | |
1371 warning ("WIFEXITED always returns false in this version of Octave") | |
1372 #endif | |
1373 | |
1374 return retval; | |
1375 } | |
1376 | |
1377 DEFUNX ("WEXITSTATUS", FWEXITSTATUS, args, , | |
1378 "-*- texinfo -*-\n\ | |
1379 @deftypefn {Built-in Function} {} WEXITSTATUS (@var{status})\n\ | |
1380 Given @var{status} from a call to @code{waitpid}, return the exit\n\ | |
1381 status of the child. This function should only be employed if\n\ | |
1382 @code{WIFEXITED} returned true.\n\ | |
1383 @seealso{waitpid, WIFEXITED, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ | |
1384 @end deftypefn") | |
1385 { | |
1386 octave_value retval = 0.0; | |
1387 | |
1388 #if defined (WEXITSTATUS) | |
1389 if (args.length () == 1) | |
1390 { | |
1391 int status = args(0).int_value (); | |
1392 | |
1393 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1394 retval = WEXITSTATUS (status); |
5453 | 1395 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1396 error ("WEXITSTATUS: expecting integer argument"); |
5453 | 1397 } |
1398 #else | |
1399 warning ("WEXITSTATUS always returns false in this version of Octave") | |
1400 #endif | |
1401 | |
1402 return retval; | |
1403 } | |
1404 | |
1405 DEFUNX ("WIFSIGNALED", FWIFSIGNALED, args, , | |
1406 "-*- texinfo -*-\n\ | |
1407 @deftypefn {Built-in Function} {} WIFSIGNALED (@var{status})\n\ | |
1408 Given @var{status} from a call to @code{waitpid}, return true if the\n\ | |
1409 child process was terminated by a signal.\n\ | |
1410 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ | |
1411 @end deftypefn") | |
1412 { | |
1413 octave_value retval = 0.0; | |
1414 | |
1415 #if defined (WIFSIGNALED) | |
1416 if (args.length () == 1) | |
1417 { | |
1418 int status = args(0).int_value (); | |
1419 | |
1420 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1421 retval = WIFSIGNALED (status); |
5453 | 1422 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1423 error ("WIFSIGNALED: expecting integer argument"); |
5453 | 1424 } |
1425 #else | |
5455 | 1426 warning ("WIFSIGNALED always returns false in this version of Octave"); |
5453 | 1427 #endif |
1428 | |
1429 return retval; | |
1430 } | |
1431 | |
1432 DEFUNX ("WTERMSIG", FWTERMSIG, args, , | |
1433 "-*- texinfo -*-\n\ | |
1434 @deftypefn {Built-in Function} {} WTERMSIG (@var{status})\n\ | |
1435 Given @var{status} from a call to @code{waitpid}, return the number of\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
1436 the signal that caused the child process to terminate. This function\n\ |
5453 | 1437 should only be employed if @code{WIFSIGNALED} returned true.\n\ |
1438 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ | |
1439 @end deftypefn") | |
1440 { | |
1441 octave_value retval = 0.0; | |
1442 | |
1443 #if defined (WTERMSIG) | |
1444 if (args.length () == 1) | |
1445 { | |
1446 int status = args(0).int_value (); | |
1447 | |
1448 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1449 retval = WTERMSIG (status); |
5453 | 1450 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1451 error ("WTERMSIG: expecting integer argument"); |
5453 | 1452 } |
1453 #else | |
5455 | 1454 warning ("WTERMSIG always returns false in this version of Octave"); |
5453 | 1455 #endif |
1456 | |
1457 return retval; | |
1458 } | |
1459 | |
1460 DEFUNX ("WCOREDUMP", FWCOREDUMP, args, , | |
1461 "-*- texinfo -*-\n\ | |
1462 @deftypefn {Built-in Function} {} WCOREDUMP (@var{status})\n\ | |
1463 Given @var{status} from a call to @code{waitpid}, return true if the\n\ | |
1464 child produced a core dump. This function should only be employed if\n\ | |
1465 @code{WIFSIGNALED} returned true. The macro used to implement this\n\ | |
1466 function is not specified in POSIX.1-2001 and is not available on some\n\ | |
1467 Unix implementations (e.g., AIX, SunOS).\n\ | |
1468 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ | |
1469 @end deftypefn") | |
1470 { | |
1471 octave_value retval = 0.0; | |
1472 | |
1473 #if defined (WCOREDUMP) | |
1474 if (args.length () == 1) | |
1475 { | |
1476 int status = args(0).int_value (); | |
1477 | |
1478 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1479 retval = WCOREDUMP (status); |
5453 | 1480 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1481 error ("WCOREDUMP: expecting integer argument"); |
5453 | 1482 } |
1483 #else | |
5455 | 1484 warning ("WCOREDUMP always returns false in this version of Octave"); |
5453 | 1485 #endif |
1486 | |
1487 return retval; | |
1488 } | |
1489 | |
1490 DEFUNX ("WIFSTOPPED", FWIFSTOPPED, args, , | |
1491 "-*- texinfo -*-\n\ | |
1492 @deftypefn {Built-in Function} {} WIFSTOPPED (@var{status})\n\ | |
1493 Given @var{status} from a call to @code{waitpid}, return true if the\n\ | |
1494 child process was stopped by delivery of a signal; this is only\n\ | |
1495 possible if the call was done using @code{WUNTRACED} or when the child\n\ | |
1496 is being traced (see ptrace(2)).\n\ | |
1497 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WSTOPSIG, WIFCONTINUED}\n\ | |
1498 @end deftypefn") | |
1499 { | |
1500 octave_value retval = 0.0; | |
1501 | |
1502 #if defined (WIFSTOPPED) | |
1503 if (args.length () == 1) | |
1504 { | |
1505 int status = args(0).int_value (); | |
1506 | |
1507 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1508 retval = WIFSTOPPED (status); |
5453 | 1509 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1510 error ("WIFSTOPPED: expecting integer argument"); |
5453 | 1511 } |
1512 #else | |
5455 | 1513 warning ("WIFSTOPPED always returns false in this version of Octave"); |
5453 | 1514 #endif |
1515 | |
1516 return retval; | |
1517 } | |
1518 | |
1519 DEFUNX ("WSTOPSIG", FWSTOPSIG, args, , | |
1520 "-*- texinfo -*-\n\ | |
1521 @deftypefn {Built-in Function} {} WSTOPSIG (@var{status})\n\ | |
1522 Given @var{status} from a call to @code{waitpid}, return the number of\n\ | |
1523 the signal which caused the child to stop. This function should only\n\ | |
1524 be employed if @code{WIFSTOPPED} returned true.\n\ | |
1525 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WIFCONTINUED}\n\ | |
1526 @end deftypefn") | |
1527 { | |
1528 octave_value retval = 0.0; | |
1529 | |
1530 #if defined (WSTOPSIG) | |
1531 if (args.length () == 1) | |
1532 { | |
1533 int status = args(0).int_value (); | |
1534 | |
1535 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1536 retval = WSTOPSIG (status); |
5453 | 1537 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1538 error ("WSTOPSIG: expecting integer argument"); |
5453 | 1539 } |
1540 #else | |
5455 | 1541 warning ("WSTOPSIG always returns false in this version of Octave"); |
5453 | 1542 #endif |
1543 | |
1544 return retval; | |
1545 } | |
1546 | |
1547 DEFUNX ("WIFCONTINUED", FWIFCONTINUED, args, , | |
1548 "-*- texinfo -*-\n\ | |
1549 @deftypefn {Built-in Function} {} WIFCONTINUED (@var{status})\n\ | |
1550 Given @var{status} from a call to @code{waitpid}, return true if the\n\ | |
1551 child process was resumed by delivery of @code{SIGCONT}.\n\ | |
1552 @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG}\n\ | |
1553 @end deftypefn") | |
1554 { | |
1555 octave_value retval = 0.0; | |
1556 | |
1557 #if defined (WIFCONTINUED) | |
1558 if (args.length () == 1) | |
1559 { | |
1560 int status = args(0).int_value (); | |
1561 | |
1562 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1563 retval = WIFCONTINUED (status); |
5453 | 1564 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1565 error ("WIFCONTINUED: expecting integer argument"); |
5453 | 1566 } |
1567 #else | |
5455 | 1568 warning ("WIFCONTINUED always returns false in this version of Octave"); |
5453 | 1569 #endif |
1570 | |
1571 return retval; | |
1572 } | |
1573 | |
10249
14eba566f9f0
use DEFUNX instead of DEFUN for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
1574 DEFUNX ("canonicalize_file_name", Fcanonicalize_file_name, args, , |
5138 | 1575 "-*- texinfo -*-\n\ |
1576 @deftypefn {Built-in Function} {[@var{cname}, @var{status}, @var{msg}]} canonicalize_file_name (@var{name})\n\ | |
1577 Return the canonical name of file @var{name}.\n\ | |
1578 @end deftypefn") | |
1579 { | |
1580 octave_value_list retval; | |
1581 | |
1582 if (args.length () == 1) | |
1583 { | |
1584 std::string name = args(0).string_value (); | |
1585 | |
1586 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1587 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1588 std::string msg; |
5138 | 1589 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1590 std::string result = octave_canonicalize_file_name (name, msg); |
5138 | 1591 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1592 retval(2) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1593 retval(1) = msg.empty () ? 0 : -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1594 retval(0) = result; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1595 } |
5138 | 1596 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10299
diff
changeset
|
1597 error ("canonicalize_file_name: argument must be a character string"); |
5138 | 1598 } |
1599 else | |
5823 | 1600 print_usage (); |
5138 | 1601 |
1602 return retval; | |
1603 } | |
1604 | |
5749 | 1605 static octave_value |
7924 | 1606 const_value (const octave_value_list& args, int val) |
5749 | 1607 { |
1608 octave_value retval; | |
1609 | |
1610 int nargin = args.length (); | |
1611 | |
1612 if (nargin == 0) | |
1613 retval = val; | |
1614 else | |
5823 | 1615 print_usage (); |
5749 | 1616 |
1617 return retval; | |
1618 } | |
1619 | |
2075 | 1620 #if !defined (O_NONBLOCK) && defined (O_NDELAY) |
1621 #define O_NONBLOCK O_NDELAY | |
1622 #endif | |
1623 | |
5749 | 1624 #if defined (F_DUPFD) |
1625 DEFUNX ("F_DUPFD", FF_DUPFD, args, , | |
1626 "-*- texinfo -*-\n\ | |
1627 @deftypefn {Built-in Function} {} F_DUPFD ()\n\ | |
1628 Return the value required to request that @code{fcntl} return a\n\ | |
1629 duplicate file descriptor.\n\ | |
1630 @seealso{fcntl, F_GETFD, F_GETFL, F_SETFD, F_SETFL}\n\ | |
1631 @end deftypefn") | |
2075 | 1632 { |
7924 | 1633 return const_value (args, F_DUPFD); |
5749 | 1634 } |
2075 | 1635 #endif |
1636 | |
1637 #if defined (F_GETFD) | |
5749 | 1638 DEFUNX ("F_GETFD", FF_GETFD, args, , |
1639 "-*- texinfo -*-\n\ | |
1640 @deftypefn {Built-in Function} {} F_GETFD ()\n\ | |
1641 Return the value required to request that @code{fcntl} to return the\n\ | |
1642 file descriptor flags.\n\ | |
5333 | 1643 @seealso{fcntl, F_DUPFD, F_GETFL, F_SETFD, F_SETFL}\n\ |
5749 | 1644 @end deftypefn") |
1645 { | |
7924 | 1646 return const_value (args, F_GETFD); |
5749 | 1647 } |
2075 | 1648 #endif |
1649 | |
1650 #if defined (F_GETFL) | |
5749 | 1651 DEFUNX ("F_GETFL", FF_GETFL, args, , |
1652 "-*- texinfo -*-\n\ | |
1653 @deftypefn {Built-in Function} {} F_GETFL ()\n\ | |
1654 Return the value required to request that @code{fcntl} to return the\n\ | |
1655 file status flags.\n\ | |
5333 | 1656 @seealso{fcntl, F_DUPFD, F_GETFD, F_SETFD, F_SETFL}\n\ |
5749 | 1657 @end deftypefn") |
1658 { | |
7924 | 1659 return const_value (args, F_GETFL); |
5749 | 1660 } |
2075 | 1661 #endif |
1662 | |
1663 #if defined (F_SETFD) | |
5749 | 1664 DEFUNX ("F_SETFD", FF_SETFD, args, , |
1665 "-*- texinfo -*-\n\ | |
1666 @deftypefn {Built-in Function} {} F_SETFD ()\n\ | |
1667 Return the value required to request that @code{fcntl} to set the file\n\ | |
1668 descriptor flags.\n\ | |
5333 | 1669 @seealso{fcntl, F_DUPFD, F_GETFD, F_GETFL, F_SETFL}\n\ |
5749 | 1670 @end deftypefn") |
1671 { | |
7924 | 1672 return const_value (args, F_SETFD); |
5749 | 1673 } |
2075 | 1674 #endif |
1675 | |
1676 #if defined (F_SETFL) | |
5749 | 1677 DEFUNX ("F_SETFL", FF_SETFL, args, , |
1678 "-*- texinfo -*-\n\ | |
1679 @deftypefn {Built-in Function} {} F_SETFL ()\n\ | |
1680 Return the value required to request that @code{fcntl} to set the file\n\ | |
1681 status flags.\n\ | |
5333 | 1682 @seealso{fcntl, F_DUPFD, F_GETFD, F_GETFL, F_SETFD}\n\ |
5749 | 1683 @end deftypefn") |
1684 { | |
7924 | 1685 return const_value (args, F_SETFL); |
5749 | 1686 } |
2075 | 1687 #endif |
1688 | |
1689 #if defined (O_APPEND) | |
5749 | 1690 DEFUNX ("O_APPEND", FO_APPEND, args, , |
1691 "-*- texinfo -*-\n\ | |
1692 @deftypefn {Built-in Function} {} O_APPEND ()\n\ | |
1693 Return the numerical value of the file status flag that may be\n\ | |
1694 returned by @code{fcntl} to indicate each write operation appends,\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
1695 or that may be passed to @code{fcntl} to set the write mode to append.\\n\ |
5333 | 1696 @seealso{fcntl, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749 | 1697 @end deftypefn") |
1698 { | |
7924 | 1699 return const_value (args, O_APPEND); |
5749 | 1700 } |
2075 | 1701 #endif |
1702 | |
2669 | 1703 #if defined (O_ASYNC) |
5749 | 1704 DEFUNX ("O_ASYNC", FO_ASYNC, args, , |
1705 "-*- texinfo -*-\n\ | |
1706 @deftypefn {Built-in Function} {} O_ASYNC ()\n\ | |
1707 Return the numerical value of the file status flag that may be\n\ | |
1708 returned by @code{fcntl} to indicate asynchronous I/O.\n\ | |
5333 | 1709 @seealso{fcntl, O_APPEND, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749 | 1710 @end deftypefn") |
1711 { | |
7924 | 1712 return const_value (args, O_ASYNC); |
5749 | 1713 } |
2669 | 1714 #endif |
1715 | |
2075 | 1716 #if defined (O_CREAT) |
5749 | 1717 DEFUNX ("O_CREAT", FO_CREAT, args, , |
1718 "-*- texinfo -*-\n\ | |
1719 @deftypefn {Built-in Function} {} O_CREAT ()\n\ | |
1720 Return the numerical value of the file status flag that may be\n\ | |
1721 returned by @code{fcntl} to indicate that a file should be\n\ | |
1722 created if it does not exist.\n\ | |
5333 | 1723 @seealso{fcntl, O_APPEND, O_ASYNC, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749 | 1724 @end deftypefn") |
1725 { | |
7924 | 1726 return const_value (args, O_CREAT); |
5749 | 1727 } |
2075 | 1728 #endif |
1729 | |
1730 #if defined (O_EXCL) | |
5749 | 1731 DEFUNX ("O_EXCL", FO_EXCL, args, , |
1732 "-*- texinfo -*-\n\ | |
1733 @deftypefn {Built-in Function} {} O_EXCL ()\n\ | |
1734 Return the numerical value of the file status flag that may be\n\ | |
1735 returned by @code{fcntl} to indicate that file locking is used.\n\ | |
5333 | 1736 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749 | 1737 @end deftypefn") |
1738 { | |
7924 | 1739 return const_value (args, O_EXCL); |
5749 | 1740 } |
2075 | 1741 #endif |
1742 | |
1743 #if defined (O_NONBLOCK) | |
5749 | 1744 DEFUNX ("O_NONBLOCK", FO_NONBLOCK, args, , |
1745 "-*- texinfo -*-\n\ | |
1746 @deftypefn {Built-in Function} {} O_NONBLOCK ()\n\ | |
1747 Return the numerical value of the file status flag that may be\n\ | |
1748 returned by @code{fcntl} to indicate that non-blocking I/O is in use,\n\ | |
1749 or that may be passsed to @code{fcntl} to set non-blocking I/O.\n\ | |
5333 | 1750 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749 | 1751 @end deftypefn") |
1752 { | |
7924 | 1753 return const_value (args, O_NONBLOCK); |
5749 | 1754 } |
2075 | 1755 #endif |
1756 | |
1757 #if defined (O_RDONLY) | |
5749 | 1758 DEFUNX ("O_RDONLY", FO_RDONLY, args, , |
1759 "-*- texinfo -*-\n\ | |
1760 @deftypefn {Built-in Function} {} O_RDONLY ()\n\ | |
1761 Return the numerical value of the file status flag that may be\n\ | |
1762 returned by @code{fcntl} to indicate that a file is open for\n\ | |
1763 reading only.\n\ | |
5333 | 1764 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749 | 1765 @end deftypefn") |
1766 { | |
7924 | 1767 return const_value (args, O_RDONLY); |
5749 | 1768 } |
2075 | 1769 #endif |
1770 | |
1771 #if defined (O_RDWR) | |
5749 | 1772 DEFUNX ("O_RDWR", FO_RDWR, args, , |
1773 "-*- texinfo -*-\n\ | |
1774 @deftypefn {Built-in Function} {} O_RDWR ()\n\ | |
1775 Return the numerical value of the file status flag that may be\n\ | |
1776 returned by @code{fcntl} to indicate that a file is open for both\n\ | |
1777 reading and writing.\n\ | |
5333 | 1778 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_SYNC, O_TRUNC, O_WRONLY}\n\ |
5749 | 1779 @end deftypefn") |
1780 { | |
7924 | 1781 return const_value (args, O_RDWR); |
5749 | 1782 } |
2075 | 1783 #endif |
1784 | |
2669 | 1785 #if defined (O_SYNC) |
5749 | 1786 DEFUNX ("O_SYNC", FO_SYNC, args, , |
1787 "-*- texinfo -*-\n\ | |
1788 @deftypefn {Built-in Function} {} O_SYNC ()\n\ | |
1789 Return the numerical value of the file status flag that may be\n\ | |
1790 returned by @code{fcntl} to indicate that a file is open for\n\ | |
1791 synchronous I/O.\n\ | |
5333 | 1792 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY}\n\ |
5749 | 1793 @end deftypefn") |
1794 { | |
7924 | 1795 return const_value (args, O_SYNC); |
5749 | 1796 } |
2669 | 1797 #endif |
1798 | |
2075 | 1799 #if defined (O_TRUNC) |
5749 | 1800 DEFUNX ("O_TRUNC", FO_TRUNC, args, , |
1801 "-*- texinfo -*-\n\ | |
1802 @deftypefn {Built-in Variable} O_TRUNC ()\n\ | |
1803 Return the numerical value of the file status flag that may be\n\ | |
1804 returned by @code{fcntl} to indicate that if file exists, it should\n\ | |
1805 be truncated when writing.\n\ | |
5333 | 1806 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_WRONLY}\n\ |
5749 | 1807 @end deftypefn") |
1808 { | |
7924 | 1809 return const_value (args, O_TRUNC); |
5749 | 1810 } |
2075 | 1811 #endif |
1812 | |
1813 #if defined (O_WRONLY) | |
5749 | 1814 DEFUNX ("O_WRONLY", FO_WRONLY, args, , |
1815 "-*- texinfo -*-\n\ | |
1816 @deftypefn {Built-in Function} {} O_WRONLY ()\n\ | |
1817 Return the numerical value of the file status flag that may be\n\ | |
1818 returned by @code{fcntl} to indicate that a file is open for\n\ | |
1819 writing only.\n\ | |
5333 | 1820 @seealso{fcntl, O_APPEND, O_ASYNC, O_CREAT, O_EXCL, O_NONBLOCK, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC}\n\ |
5749 | 1821 @end deftypefn") |
1822 { | |
7924 | 1823 return const_value (args, O_WRONLY); |
5749 | 1824 } |
2075 | 1825 #endif |
3446 | 1826 |
5453 | 1827 #if !defined (WNOHANG) |
1828 #define WNOHANG 0 | |
1829 #endif | |
1830 | |
5749 | 1831 DEFUNX ("WNOHANG", FWNOHANG, args, , |
1832 "-*- texinfo -*-\n\ | |
1833 @deftypefn {Built-in Function} {} WNOHANG ()\n\ | |
1834 Return the numerical value of the option argument that may be\n\ | |
1835 passed to @code{waitpid} to indicate that it should return its\n\ | |
1836 status immediately instead of waiting for a process to exit.\n\ | |
5453 | 1837 @seealso{waitpid, WUNTRACED, WCONTINUE}\n\ |
5749 | 1838 @end deftypefn") |
1839 { | |
7924 | 1840 return const_value (args, WNOHANG); |
5749 | 1841 } |
5453 | 1842 |
1843 #if !defined (WUNTRACED) | |
1844 #define WUNTRACED 0 | |
1845 #endif | |
1846 | |
5749 | 1847 DEFUNX ("WUNTRACED", FWUNTRACED, args, , |
1848 "-*- texinfo -*-\n\ | |
1849 @deftypefn {Built-in Function} {} WUNTRACED ()\n\ | |
1850 Return the numerical value of the option argument that may be\n\ | |
1851 passed to @code{waitpid} to indicate that it should also return\n\ | |
1852 if the child process has stopped but is not traced via the\n\ | |
1853 @code{ptrace} system call\n\ | |
5453 | 1854 @seealso{waitpid, WNOHANG, WCONTINUE}\n\ |
5749 | 1855 @end deftypefn") |
1856 { | |
7924 | 1857 return const_value (args, WUNTRACED); |
5749 | 1858 } |
5453 | 1859 |
1860 #if !defined (WCONTINUE) | |
1861 #define WCONTINUE 0 | |
1862 #endif | |
1863 | |
5749 | 1864 DEFUNX ("WCONTINUE", FWCONTINUE, args, , |
1865 "-*- texinfo -*-\n\ | |
9724
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9564
diff
changeset
|
1866 @deftypefn {Built-in Function} {} WCONTINUE ()\n\ |
5749 | 1867 Return the numerical value of the option argument that may be\n\ |
1868 passed to @code{waitpid} to indicate that it should also return\n\ | |
1869 if a stopped child has been resumed by delivery of a @code{SIGCONT}\n\ | |
1870 signal.\n\ | |
5453 | 1871 @seealso{waitpid, WNOHANG, WUNTRACED}\n\ |
5749 | 1872 @end deftypefn") |
1873 { | |
7924 | 1874 return const_value (args, WCONTINUE); |
2075 | 1875 } |