Ignore:
Timestamp:
Dec 11, 2017, 4:42:15 PM (4 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
326cd2b, 90449e4
Parents:
7faab5e (diff), 4160c07 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/fstream.c

    r7faab5e rebf0820  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Dec  7 08:35:01 2017
    13 // Update Count     : 270
     12// Last Modified On : Sat Dec  9 09:31:23 2017
     13// Update Count     : 275
    1414//
    1515
     
    4646
    4747// public
    48 void ?{}( ofstream & os ) {}
     48void ?{}( ofstream & os ) { os.file = 0; }
    4949
    5050void ?{}( ofstream & os, const char * name, const char * mode ) {
    5151        open( os, name, mode );
     52}
     53void ?{}( ofstream & os, const char * name ) {
     54        open( os, name, "w" );
    5255}
    5356
     
    8487
    8588int fail( ofstream & os ) {
    86         return ferror( (FILE *)(os.file) );
     89        return os.file == 0 || ferror( (FILE *)(os.file) );
    8790} // fail
    8891
     
    9396void open( ofstream & os, const char * name, const char * mode ) {
    9497        FILE *file = fopen( name, mode );
    95         if ( file == 0 ) {                                                                      // do not change unless successful
    96                 fprintf( stderr, IO_MSG "open output file \"%s\", ", name );
    97                 perror( 0 );
    98                 exit( EXIT_FAILURE );
    99         } // if
     98        // if ( file == 0 ) {                                                                   // do not change unless successful
     99        //      fprintf( stderr, IO_MSG "open output file \"%s\", ", name );
     100        //      perror( 0 );
     101        //      exit( EXIT_FAILURE );
     102        // } // if
    100103        (os){ file, true, false, " ", ", " };
     104} // open
     105
     106void open( ofstream & os, const char * name ) {
     107        open( os, name, "w" );
    101108} // open
    102109
     
    152159
    153160// public
    154 void ?{}( ifstream & is ) {}
    155 
     161void ?{}( ifstream & is ) {     is.file = 0; }
     162
     163void ?{}( ifstream & is, const char * name, const char * mode ) {
     164        open( is, name, mode );
     165}
    156166void ?{}( ifstream & is, const char * name ) {
    157         open( is, name );
     167        open( is, name, "r" );
    158168}
    159169
    160170int fail( ifstream & is ) {
    161         return ferror( (FILE *)(is.file) );
     171        return is.file == 0 || ferror( (FILE *)(is.file) );
    162172} // fail
    163173
     
    166176} // eof
    167177
     178void open( ifstream & is, const char * name, const char * mode ) {
     179        FILE *file = fopen( name, mode );
     180        // if ( file == 0 ) {                                                                   // do not change unless successful
     181        //      fprintf( stderr, IO_MSG "open input file \"%s\", ", name );
     182        //      perror( 0 );
     183        //      exit( EXIT_FAILURE );
     184        // } // if
     185        is.file = file;
     186} // open
     187
    168188void open( ifstream & is, const char * name ) {
    169         FILE *file = fopen( name, "r" );
    170         if ( file == 0 ) {                                                                      // do not change unless successful
    171                 fprintf( stderr, IO_MSG "open input file \"%s\", ", name );
    172                 perror( 0 );
    173                 exit( EXIT_FAILURE );
    174         } // if
    175         is.file = file;
     189        open( is, name, "r" );
    176190} // open
    177191
Note: See TracChangeset for help on using the changeset viewer.