Mercurial > hg > octave-terminal
changeset 3644:9add655e8b8c
[project @ 2000-03-24 11:58:50 by jwe]
author | jwe |
---|---|
date | Fri, 24 Mar 2000 11:58:50 +0000 |
parents | 3af6d00b82ed |
children | 71b4ccd27162 |
files | src/ChangeLog src/c-file-ptr-stream.cc src/c-file-ptr-stream.h src/oct-procbuf.cc src/sighandlers.cc |
diffstat | 5 files changed, 92 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,8 @@ 2000-03-24 John W. Eaton <jwe@bevo.che.wisc.edu> + * sighandlers.cc (my_friendly_exit): Prefix failure messages with + panic instead of error. + * c-file-ptr-stream.cc (c_file_ptr_buf::~c_file_ptr_buf): Avoid dereferencing NULL pointer.
--- a/src/c-file-ptr-stream.cc +++ b/src/c-file-ptr-stream.cc @@ -53,13 +53,19 @@ int c_file_ptr_buf::overflow (int c) { - return (c != EOF) ? fputc (c, f) : fflush (f); + if (f) + return (c != EOF) ? fputc (c, f) : fflush (f); + else + return EOF; } int c_file_ptr_buf::underflow (void) { - return fgetc (f); + if (f) + return fgetc (f); + else + return EOF; } int @@ -71,19 +77,25 @@ int c_file_ptr_buf::pbackfail (int c) { - return (c != EOF) ? ungetc (c, f) : EOF; + return (c != EOF && f) ? ungetc (c, f) : EOF; } std::streamsize c_file_ptr_buf::xsputn (const char* s, std::streamsize n) { - return fwrite (s, 1, n, f); + if (f) + return fwrite (s, 1, n, f); + else + return 0; } std::streamsize c_file_ptr_buf::xsgetn (char *s, std::streamsize n) { - return fread (s, 1, n, f); + if (f) + return fread (s, 1, n, f); + else + return 0; } static inline int @@ -101,9 +113,14 @@ { // XXX FIXME XXX -- is this the right thing to do? - fseek (f, offset, seekdir_to_whence (dir)); + if (f) + { + fseek (f, offset, seekdir_to_whence (dir)); - return ftell (f); + return ftell (f); + } + else + return 0; } std::streampos @@ -111,9 +128,14 @@ { // XXX FIXME XXX -- is this the right thing to do? - fseek (f, offset, SEEK_SET); + if (f) + { + fseek (f, offset, SEEK_SET); - return ftell (f); + return ftell (f); + } + else + return 0; } int
--- a/src/c-file-ptr-stream.h +++ b/src/c-file-ptr-stream.h @@ -33,10 +33,6 @@ class c_file_ptr_buf : public std::streambuf { -protected: - - FILE *f; - public: FILE* stdiofile (void) const { return f; } @@ -64,36 +60,44 @@ std::ios::openmode = std::ios::in | std::ios::out); int sync (void); + +protected: + + FILE *f; }; class i_c_file_ptr_stream : public std::istream { +public: + + i_c_file_ptr_stream (FILE* f) + : std::istream (), buf (new c_file_ptr_buf (f)) { init (buf); } + + ~i_c_file_ptr_stream (void) { delete buf; buf = 0; } + + c_file_ptr_buf *rdbuf (void) { return buf; } + private: - c_file_ptr_buf f; - -public: - - i_c_file_ptr_stream (FILE* f_arg) - : std::istream (), f (f_arg) { init (&f); } - - c_file_ptr_buf *rdbuf (void) { return &f; } + c_file_ptr_buf *buf; }; class o_c_file_ptr_stream : public std::ostream { +public: + + o_c_file_ptr_stream (FILE* f) + : std::ostream (), buf (new c_file_ptr_buf (f)) { init (buf); } + + ~o_c_file_ptr_stream (void) { delete buf; buf = 0; } + + c_file_ptr_buf *rdbuf (void) { return buf; } + private: - c_file_ptr_buf f; - -public: - - o_c_file_ptr_stream (FILE* f_arg) - : std::ostream (), f (f_arg) { init (&f); } - - c_file_ptr_buf *rdbuf (void) { return &f; } + c_file_ptr_buf *buf; }; #endif
--- a/src/oct-procbuf.cc +++ b/src/oct-procbuf.cc @@ -99,7 +99,14 @@ while (octave_procbuf_list) { - ::fclose (octave_procbuf_list->f); + FILE *fp = octave_procbuf_list->f; + + if (fp) + { + ::fclose (fp); + fp = 0; + } + octave_procbuf_list = octave_procbuf_list->next; } @@ -140,31 +147,36 @@ { #if defined (HAVE_SYS_WAIT_H) - pid_t wait_pid; - - int status = -1; + if (f) + { + pid_t wait_pid; - for (octave_procbuf **ptr = &octave_procbuf_list; - *ptr != 0; - ptr = &(*ptr)->next) - { - if (*ptr == this) + int status = -1; + + for (octave_procbuf **ptr = &octave_procbuf_list; + *ptr != 0; + ptr = &(*ptr)->next) { - *ptr = (*ptr)->next; - status = 0; - break; + if (*ptr == this) + { + *ptr = (*ptr)->next; + status = 0; + break; + } } - } - if (status == 0 && ::fclose (f) == 0) - { - using namespace std; + if (status == 0 && ::fclose (f) == 0) + { + using namespace std; - do - { - wait_pid = ::waitpid (proc_pid, &wstatus, 0); + do + { + wait_pid = ::waitpid (proc_pid, &wstatus, 0); + } + while (wait_pid == -1 && errno == EINTR); } - while (wait_pid == -1 && errno == EINTR); + + f = 0; } open_p = false;
--- a/src/sighandlers.cc +++ b/src/sighandlers.cc @@ -122,15 +122,14 @@ octave_set_signal_handler (SIGABRT, SIG_DFL); #endif - std::cerr << "error: attempted clean up apparently failed -- aborting...\n"; - + std::cerr << "panic: attempted clean up apparently failed -- aborting...\n"; abort (); } else { been_there_done_that = true; - std::cerr << "error: " << sig_name << " -- stopping myself...\n"; + std::cerr << "panic: " << sig_name << " -- stopping myself...\n"; save_user_variables ();