Mercurial > octave-nkf
comparison libinterp/corefcn/syscalls.cc @ 20592:56fee8f84fe7
eliminate more simple uses of error_state
* cellfun.cc, syscalls.cc, urlwrite.cc, ov.cc, pt-eval.cc:
Eliminate uses of error_state.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 05 Oct 2015 22:47:42 -0400 |
parents | 7ac907da9fba |
children | fd0efcdb3718 |
comparison
equal
deleted
inserted
replaced
20591:0650b8431037 | 20592:56fee8f84fe7 |
---|---|
135 if (! error_state) | 135 if (! error_state) |
136 { | 136 { |
137 octave_stream new_stream | 137 octave_stream new_stream |
138 = octave_stream_list::lookup (args(1), "dup2"); | 138 = octave_stream_list::lookup (args(1), "dup2"); |
139 | 139 |
140 if (! error_state) | 140 int i_old = old_stream.file_number (); |
141 int i_new = new_stream.file_number (); | |
142 | |
143 if (i_old >= 0 && i_new >= 0) | |
141 { | 144 { |
142 int i_old = old_stream.file_number (); | 145 std::string msg; |
143 int i_new = new_stream.file_number (); | 146 |
144 | 147 int status = octave_syscalls::dup2 (i_old, i_new, msg); |
145 if (i_old >= 0 && i_new >= 0) | 148 |
146 { | 149 retval(1) = msg; |
147 std::string msg; | 150 retval(0) = status; |
148 | |
149 int status = octave_syscalls::dup2 (i_old, i_new, msg); | |
150 | |
151 retval(1) = msg; | |
152 retval(0) = status; | |
153 } | |
154 } | 151 } |
155 } | 152 } |
156 else | 153 else |
157 error ("dup2: invalid stream"); | 154 error ("dup2: invalid stream"); |
158 } | 155 } |
221 exec_args.resize (1); | 218 exec_args.resize (1); |
222 | 219 |
223 exec_args[0] = exec_file; | 220 exec_args[0] = exec_file; |
224 } | 221 } |
225 | 222 |
226 if (! error_state) | 223 octave_history_write_timestamp (); |
227 { | 224 |
228 octave_history_write_timestamp (); | 225 if (! command_history::ignoring_entries ()) |
229 | 226 command_history::clean_up_and_save (); |
230 if (! command_history::ignoring_entries ()) | 227 |
231 command_history::clean_up_and_save (); | 228 std::string msg; |
232 | 229 |
233 std::string msg; | 230 int status = octave_syscalls::execvp (exec_file, exec_args, msg); |
234 | 231 |
235 int status = octave_syscalls::execvp (exec_file, exec_args, msg); | 232 retval(1) = msg; |
236 | 233 retval(0) = status; |
237 retval(1) = msg; | |
238 retval(0) = status; | |
239 } | |
240 } | 234 } |
241 else | 235 else |
242 error ("exec: FILE must be a string"); | 236 error ("exec: FILE must be a string"); |
243 } | 237 } |
244 else | 238 else |
337 | 331 |
338 if (! error_state) | 332 if (! error_state) |
339 { | 333 { |
340 bool sync_mode = (nargin == 3 ? args(2).bool_value () : false); | 334 bool sync_mode = (nargin == 3 ? args(2).bool_value () : false); |
341 | 335 |
342 if (! error_state) | 336 int fildes[2]; |
337 std::string msg; | |
338 pid_t pid; | |
339 | |
340 pid = octave_syscalls::popen2 (exec_file, arg_list, sync_mode, | |
341 fildes, msg, interactive); | |
342 if (pid >= 0) | |
343 { | 343 { |
344 int fildes[2]; | 344 FILE *ifile = fdopen (fildes[1], "r"); |
345 std::string msg; | 345 FILE *ofile = fdopen (fildes[0], "w"); |
346 pid_t pid; | 346 |
347 | 347 std::string nm; |
348 pid = octave_syscalls::popen2 (exec_file, arg_list, sync_mode, | 348 |
349 fildes, msg, interactive); | 349 octave_stream is = octave_stdiostream::create (nm, ifile, |
350 if (pid >= 0) | 350 std::ios::in); |
351 { | 351 |
352 FILE *ifile = fdopen (fildes[1], "r"); | 352 octave_stream os = octave_stdiostream::create (nm, ofile, |
353 FILE *ofile = fdopen (fildes[0], "w"); | |
354 | |
355 std::string nm; | |
356 | |
357 octave_stream is = octave_stdiostream::create (nm, ifile, | |
358 std::ios::in); | |
359 | |
360 octave_stream os = octave_stdiostream::create (nm, ofile, | |
361 std::ios::out); | 353 std::ios::out); |
362 | 354 |
363 Cell file_ids (1, 2); | 355 Cell file_ids (1, 2); |
364 | 356 |
365 retval(2) = pid; | 357 retval(2) = pid; |
366 retval(1) = octave_stream_list::insert (is); | 358 retval(1) = octave_stream_list::insert (is); |
367 retval(0) = octave_stream_list::insert (os); | 359 retval(0) = octave_stream_list::insert (os); |
368 } | |
369 else | |
370 error (msg.c_str ()); | |
371 } | 360 } |
361 else | |
362 error (msg.c_str ()); | |
372 } | 363 } |
373 else | 364 else |
374 error ("popen2: all arguments must be strings"); | 365 error ("popen2: all arguments must be strings"); |
375 } | 366 } |
376 else | 367 else |
525 int fid = strm.file_number (); | 516 int fid = strm.file_number (); |
526 | 517 |
527 int req = args(1).int_value (true); | 518 int req = args(1).int_value (true); |
528 int arg = args(2).int_value (true); | 519 int arg = args(2).int_value (true); |
529 | 520 |
530 if (! error_state) | 521 // FIXME: Need better checking here? |
522 if (fid < 0) | |
523 error ("fcntl: invalid file id"); | |
524 else | |
531 { | 525 { |
532 // FIXME: Need better checking here? | 526 std::string msg; |
533 if (fid < 0) | 527 |
534 error ("fcntl: invalid file id"); | 528 int status = octave_fcntl (fid, req, arg, msg); |
535 else | 529 |
536 { | 530 retval(1) = msg; |
537 std::string msg; | 531 retval(0) = status; |
538 | |
539 int status = octave_fcntl (fid, req, arg, msg); | |
540 | |
541 retval(1) = msg; | |
542 retval(0) = status; | |
543 } | |
544 } | 532 } |
545 } | 533 } |
546 else | 534 else |
547 error ("fcntl: FID, REQUEST, and ARG must be integers"); | 535 error ("fcntl: FID, REQUEST, and ARG must be integers"); |
548 } | 536 } |
766 | 754 |
767 if (args.length () == 2) | 755 if (args.length () == 2) |
768 { | 756 { |
769 pid_t pid = args(0).int_value (true); | 757 pid_t pid = args(0).int_value (true); |
770 | 758 |
771 if (! error_state) | 759 int sig = args(1).int_value (true); |
772 { | 760 |
773 int sig = args(1).int_value (true); | 761 std::string msg; |
774 | 762 |
775 if (! error_state) | 763 int status = octave_syscalls::kill (pid, sig, msg); |
776 { | 764 |
777 std::string msg; | 765 retval(1) = msg; |
778 | 766 retval(0) = status; |
779 int status = octave_syscalls::kill (pid, sig, msg); | |
780 | |
781 retval(1) = msg; | |
782 retval(0) = status; | |
783 } | |
784 } | |
785 } | 767 } |
786 else | 768 else |
787 print_usage (); | 769 print_usage (); |
788 | 770 |
789 return retval; | 771 return retval; |
804 | 786 |
805 if (args.length () == 1) | 787 if (args.length () == 1) |
806 { | 788 { |
807 std::string fname = args(0).string_value (); | 789 std::string fname = args(0).string_value (); |
808 | 790 |
809 if (! error_state) | 791 file_stat fs (fname, false); |
810 { | 792 |
811 file_stat fs (fname, false); | 793 retval = mk_stat_result (fs); |
812 | |
813 retval = mk_stat_result (fs); | |
814 } | |
815 } | 794 } |
816 else | 795 else |
817 print_usage (); | 796 print_usage (); |
818 | 797 |
819 return retval; | 798 return retval; |
886 error ("mkfifo: MODE must be a positive integer value"); | 865 error ("mkfifo: MODE must be a positive integer value"); |
887 else | 866 else |
888 { | 867 { |
889 int mode = convert (octal_mode, 8, 10); | 868 int mode = convert (octal_mode, 8, 10); |
890 | 869 |
891 if (! error_state) | 870 std::string msg; |
892 { | 871 |
893 std::string msg; | 872 int status = octave_mkfifo (name, mode, msg); |
894 | 873 |
895 int status = octave_mkfifo (name, mode, msg); | 874 retval(0) = status; |
896 | 875 |
897 retval(0) = status; | 876 if (status < 0) |
898 | 877 retval(1) = msg; |
899 if (status < 0) | |
900 retval(1) = msg; | |
901 } | |
902 } | 878 } |
903 } | 879 } |
904 else | 880 else |
905 error ("mkfifo: MODE must be an integer"); | 881 error ("mkfifo: MODE must be an integer"); |
906 } | 882 } |
1083 { | 1059 { |
1084 if (args(0).is_scalar_type ()) | 1060 if (args(0).is_scalar_type ()) |
1085 { | 1061 { |
1086 int fid = octave_stream_list::get_file_number (args(0)); | 1062 int fid = octave_stream_list::get_file_number (args(0)); |
1087 | 1063 |
1088 if (! error_state) | 1064 file_fstat fs (fid); |
1089 { | 1065 |
1090 file_fstat fs (fid); | 1066 retval = mk_stat_result (fs); |
1091 | |
1092 retval = mk_stat_result (fs); | |
1093 } | |
1094 } | 1067 } |
1095 else | 1068 else |
1096 { | 1069 { |
1097 std::string fname = args(0).string_value (); | 1070 std::string fname = args(0).string_value (); |
1098 | 1071 |
1099 if (! error_state) | 1072 file_stat fs (fname); |
1100 { | 1073 |
1101 file_stat fs (fname); | 1074 retval = mk_stat_result (fs); |
1102 | |
1103 retval = mk_stat_result (fs); | |
1104 } | |
1105 } | 1075 } |
1106 } | 1076 } |
1107 else | 1077 else |
1108 print_usage (); | 1078 print_usage (); |
1109 | 1079 |