Changeset 91e52be


Ignore:
Timestamp:
Jun 18, 2020, 7:03:55 PM (15 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast, new-ast-unique-expr
Children:
6026628
Parents:
030653a
Message:

raise exception IO_OPEN_FAILURE for open failure with input/output fstreams, ignore attempt to close unopen file

Location:
libcfa/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/fstream.cfa

    r030653a r91e52be  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb  7 19:01:01 2020
    13 // Update Count     : 363
     12// Last Modified On : Thu Jun 18 15:37:21 2020
     13// Update Count     : 380
    1414//
    1515
     
    123123        #ifdef __CFA_DEBUG__
    124124        if ( file == 0p ) {
     125                throw (IO_OPEN_FAILURE){ os };
    125126                abort | IO_MSG "open output file \"" | name | "\"" | nl | strerror( errno );
    126127        } // if
     
    134135
    135136void close( ofstream & os ) {
    136         if ( (FILE *)(os.$file) == stdout || (FILE *)(os.$file) == stderr ) return;
     137  if ( (FILE *)(os.$file) == 0p ) return;
     138  if ( (FILE *)(os.$file) == (FILE *)stdout || (FILE *)(os.$file) == (FILE *)stderr ) return;
    137139
    138140        if ( fclose( (FILE *)(os.$file) ) == EOF ) {
    139141                abort | IO_MSG "close output" | nl | strerror( errno );
    140142        } // if
     143        os.$file = 0p;
    141144} // close
    142145
     
    219222        #ifdef __CFA_DEBUG__
    220223        if ( file == 0p ) {
     224                throw (IO_OPEN_FAILURE){ is };
    221225                abort | IO_MSG "open input file \"" | name | "\"" | nl | strerror( errno );
    222226        } // if
     
    230234
    231235void close( ifstream & is ) {
    232         if ( (FILE *)(is.$file) == stdin ) return;
     236  if ( (FILE *)(is.$file) == 0p ) return;
     237  if ( (FILE *)(is.$file) == (FILE *)stdin ) return;
    233238
    234239        if ( fclose( (FILE *)(is.$file) ) == EOF ) {
    235240                abort | IO_MSG "close input" | nl | strerror( errno );
    236241        } // if
     242        is.$file = 0p;
    237243} // close
    238244
     
    276282ifstream & sin = sinFile, & stdin = sinFile;
    277283
     284
     285//*********************************** exceptions ***********************************
     286
     287
     288void ?{}( IO_OPEN_FAILURE & this, ofstream & ostream ) {
     289        VTABLE_INIT(this, IO_OPEN_FAILURE);
     290        this.ostream = &ostream;
     291}
     292void ?{}( IO_OPEN_FAILURE & this, ifstream & istream ) {
     293        VTABLE_INIT(this, IO_OPEN_FAILURE);
     294        this.istream = &istream;
     295}
     296const char * IO_OPEN_FAILURE_msg(IO_OPEN_FAILURE * this) {
     297        return "IO_OPEN_FAILURE";
     298}
     299VTABLE_INSTANCE(IO_OPEN_FAILURE)(IO_OPEN_FAILURE_msg);
     300void throwIO_OPEN_FAILURE( ofstream & ostream ) {
     301        IO_OPEN_FAILURE exc = { ostream };
     302}
     303void throwIO_OPEN_FAILURE( ifstream & istream ) {
     304        IO_OPEN_FAILURE exc = { istream };
     305}
     306
    278307// Local Variables: //
    279308// tab-width: 4 //
  • libcfa/src/fstream.hfa

    r030653a r91e52be  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Feb 17 08:29:23 2020
    13 // Update Count     : 175
     12// Last Modified On : Tue Jun 16 20:41:21 2020
     13// Update Count     : 184
    1414//
    1515
     
    1717
    1818#include "iostream.hfa"
     19#include <exception.hfa>
    1920
    2021
     
    106107extern ifstream & sin, & stdin;                                                 // aliases
    107108
     109
     110//*********************************** exceptions ***********************************
     111
     112
     113DATA_EXCEPTION(IO_OPEN_FAILURE)(
     114        union {
     115                ofstream * ostream;
     116                ifstream * istream;
     117        };
     118);
     119
     120void ?{}( IO_OPEN_FAILURE & this, ofstream & ostream );
     121void ?{}( IO_OPEN_FAILURE & this, ifstream & istream );
     122
    108123// Local Variables: //
    109124// mode: c //
Note: See TracChangeset for help on using the changeset viewer.