Mercurial > octave-nkf
comparison liboctave/oct-syscalls.cc @ 10411:479cc8a0a846
use gnulib namespace
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 15 Mar 2010 15:57:23 -0400 |
parents | 07ebe522dac2 |
children | fd0a3ac60b0e |
comparison
equal
deleted
inserted
replaced
10410:b3ec24dc305a | 10411:479cc8a0a846 |
---|---|
61 msg = std::string (); | 61 msg = std::string (); |
62 | 62 |
63 int status = -1; | 63 int status = -1; |
64 | 64 |
65 #if defined (HAVE_DUP2) | 65 #if defined (HAVE_DUP2) |
66 status = ::dup2 (old_fd, new_fd); | 66 status = gnulib::dup2 (old_fd, new_fd); |
67 | 67 |
68 if (status < 0) | 68 if (status < 0) |
69 { | 69 msg = gnulib::strerror (errno); |
70 using namespace std; | |
71 msg = ::strerror (errno); | |
72 } | |
73 #else | 70 #else |
74 msg = NOT_SUPPORTED ("dup2"); | 71 msg = NOT_SUPPORTED ("dup2"); |
75 #endif | 72 #endif |
76 | 73 |
77 return status; | 74 return status; |
98 status = ::execvp (file.c_str (), argv); | 95 status = ::execvp (file.c_str (), argv); |
99 | 96 |
100 string_vector::delete_c_str_vec (argv); | 97 string_vector::delete_c_str_vec (argv); |
101 | 98 |
102 if (status < 0) | 99 if (status < 0) |
103 { | 100 msg = gnulib::strerror (errno); |
104 using namespace std; | |
105 msg = ::strerror (errno); | |
106 } | |
107 #else | 101 #else |
108 msg = NOT_SUPPORTED ("execvp"); | 102 msg = NOT_SUPPORTED ("execvp"); |
109 #endif | 103 #endif |
110 | 104 |
111 return status; | 105 return status; |
118 | 112 |
119 #if defined (HAVE_FORK) | 113 #if defined (HAVE_FORK) |
120 status = ::fork (); | 114 status = ::fork (); |
121 | 115 |
122 if (status < 0) | 116 if (status < 0) |
123 { | 117 msg = gnulib::strerror (errno); |
124 using namespace std; | |
125 msg = ::strerror (errno); | |
126 } | |
127 #else | 118 #else |
128 msg = NOT_SUPPORTED ("fork"); | 119 msg = NOT_SUPPORTED ("fork"); |
129 #endif | 120 #endif |
130 | 121 |
131 return status; | 122 return status; |
142 #else | 133 #else |
143 status = ::fork (); | 134 status = ::fork (); |
144 #endif | 135 #endif |
145 | 136 |
146 if (status < 0) | 137 if (status < 0) |
147 { | 138 msg = gnulib::strerror (errno); |
148 using namespace std; | |
149 msg = ::strerror (errno); | |
150 } | |
151 #else | 139 #else |
152 msg = NOT_SUPPORTED ("vfork"); | 140 msg = NOT_SUPPORTED ("vfork"); |
153 #endif | 141 #endif |
154 | 142 |
155 return status; | 143 return status; |
162 | 150 |
163 #if defined (HAVE_GETPGRP) | 151 #if defined (HAVE_GETPGRP) |
164 status = ::getpgrp (); | 152 status = ::getpgrp (); |
165 | 153 |
166 if (status < 0) | 154 if (status < 0) |
167 { | 155 msg = gnulib::strerror (errno); |
168 using namespace std; | |
169 msg = ::strerror (errno); | |
170 } | |
171 #else | 156 #else |
172 msg = NOT_SUPPORTED ("getpgrp"); | 157 msg = NOT_SUPPORTED ("getpgrp"); |
173 #endif | 158 #endif |
174 | 159 |
175 return status; | 160 return status; |
251 | 236 |
252 #if defined (HAVE_PIPE) | 237 #if defined (HAVE_PIPE) |
253 status = ::pipe (fildes); | 238 status = ::pipe (fildes); |
254 | 239 |
255 if (status < 0) | 240 if (status < 0) |
256 { | 241 msg = gnulib::strerror (errno); |
257 using namespace std; | |
258 msg = ::strerror (errno); | |
259 } | |
260 #else | 242 #else |
261 msg = NOT_SUPPORTED ("pipe"); | 243 msg = NOT_SUPPORTED ("pipe"); |
262 #endif | 244 #endif |
263 | 245 |
264 return status; | 246 return status; |
280 | 262 |
281 #if defined (HAVE_WAITPID) | 263 #if defined (HAVE_WAITPID) |
282 retval = ::octave_waitpid (pid, status, options); | 264 retval = ::octave_waitpid (pid, status, options); |
283 | 265 |
284 if (retval < 0) | 266 if (retval < 0) |
285 { | 267 msg = gnulib::strerror (errno); |
286 using namespace std; | |
287 msg = ::strerror (errno); | |
288 } | |
289 #else | 268 #else |
290 msg = NOT_SUPPORTED ("waitpid"); | 269 msg = NOT_SUPPORTED ("waitpid"); |
291 #endif | 270 #endif |
292 | 271 |
293 return retval; | 272 return retval; |
309 | 288 |
310 #if defined (HAVE_KILL) | 289 #if defined (HAVE_KILL) |
311 status = ::kill (pid, sig); | 290 status = ::kill (pid, sig); |
312 | 291 |
313 if (status < 0) | 292 if (status < 0) |
314 { | 293 msg = gnulib::strerror (errno); |
315 using namespace std; | |
316 msg = ::strerror (errno); | |
317 } | |
318 #else | 294 #else |
319 msg = NOT_SUPPORTED ("kill"); | 295 msg = NOT_SUPPORTED ("kill"); |
320 #endif | 296 #endif |
321 | 297 |
322 return status; | 298 return status; |
361 std::string child_msg; | 337 std::string child_msg; |
362 | 338 |
363 interactive = false; | 339 interactive = false; |
364 | 340 |
365 // Child process | 341 // Child process |
366 ::close (child_stdin[1]); | 342 gnulib::close (child_stdin[1]); |
367 ::close (child_stdout[0]); | 343 gnulib::close (child_stdout[0]); |
368 | 344 |
369 if (dup2 (child_stdin[0], STDIN_FILENO) >= 0) | 345 if (dup2 (child_stdin[0], STDIN_FILENO) >= 0) |
370 { | 346 { |
371 ::close (child_stdin[0]); | 347 gnulib::close (child_stdin[0]); |
372 if (dup2 (child_stdout[1], STDOUT_FILENO) >= 0) | 348 if (dup2 (child_stdout[1], STDOUT_FILENO) >= 0) |
373 { | 349 { |
374 ::close (child_stdout[1]); | 350 gnulib::close (child_stdout[1]); |
375 if (execvp (cmd, args, child_msg) < 0) | 351 if (execvp (cmd, args, child_msg) < 0) |
376 child_msg = "popen2 (child): unable to start process -- " + child_msg; | 352 child_msg = "popen2 (child): unable to start process -- " + child_msg; |
377 } | 353 } |
378 else | 354 else |
379 child_msg = "popen2 (child): file handle duplication failed -- " + child_msg; | 355 child_msg = "popen2 (child): file handle duplication failed -- " + child_msg; |
386 exit(0); | 362 exit(0); |
387 } | 363 } |
388 else | 364 else |
389 { | 365 { |
390 // Parent process | 366 // Parent process |
391 ::close (child_stdin[0]); | 367 gnulib::close (child_stdin[0]); |
392 ::close (child_stdout[1]); | 368 gnulib::close (child_stdout[1]); |
369 | |
393 #if defined (F_SETFL) && defined (O_NONBLOCK) | 370 #if defined (F_SETFL) && defined (O_NONBLOCK) |
394 if (! sync_mode && octave_fcntl (child_stdout[0], F_SETFL, O_NONBLOCK, msg) < 0) | 371 if (! sync_mode && octave_fcntl (child_stdout[0], F_SETFL, O_NONBLOCK, msg) < 0) |
395 msg = "popen2: error setting file mode -- " + msg; | 372 msg = "popen2: error setting file mode -- " + msg; |
396 else | 373 else |
397 #endif | 374 #endif |
399 fildes[0] = child_stdin [1]; | 376 fildes[0] = child_stdin [1]; |
400 fildes[1] = child_stdout [0]; | 377 fildes[1] = child_stdout [0]; |
401 return pid; | 378 return pid; |
402 } | 379 } |
403 } | 380 } |
404 ::close (child_stdout[0]); | 381 gnulib::close (child_stdout[0]); |
405 ::close (child_stdout[1]); | 382 gnulib::close (child_stdout[1]); |
406 } | 383 } |
407 else | 384 else |
408 msg = "popen2: pipe creation failed -- " + msg; | 385 msg = "popen2: pipe creation failed -- " + msg; |
409 ::close (child_stdin[0]); | 386 |
410 ::close (child_stdin[1]); | 387 gnulib::close (child_stdin[0]); |
388 gnulib::close (child_stdin[1]); | |
411 } | 389 } |
412 else | 390 else |
413 msg = "popen2: pipe creation failed -- " + msg; | 391 msg = "popen2: pipe creation failed -- " + msg; |
414 | 392 |
415 return -1; | 393 return -1; |
428 { | 406 { |
429 msg = std::string (); | 407 msg = std::string (); |
430 | 408 |
431 int status = -1; | 409 int status = -1; |
432 | 410 |
433 status = ::fcntl (fd, cmd, arg); | 411 status = gnulib::fcntl (fd, cmd, arg); |
434 | 412 |
435 if (status < 0) | 413 if (status < 0) |
436 { | 414 msg = gnulib::strerror (errno); |
437 using namespace std; | 415 |
438 msg = ::strerror (errno); | 416 return status; |
439 } | 417 } |
440 | |
441 return status; | |
442 } |