Changeset 8da74119


Ignore:
Timestamp:
Dec 9, 2017, 12:10:04 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
32a1d654
Parents:
5e1adb5
Message:

additional constructors and opens

Location:
src/libcfa
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/fstream

    r5e1adb5 r8da74119  
    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:06:11 2017
    13 // Update Count     : 129
     12// Last Modified On : Thu Dec  7 15:17:26 2017
     13// Update Count     : 130
    1414//
    1515
     
    5252int flush( ofstream & );
    5353void open( ofstream &, const char * name, const char * mode );
     54void open( ofstream &, const char * name );
    5455void close( ofstream & );
    5556ofstream & write( ofstream &, const char * data, unsigned long int size );
     
    5859void ?{}( ofstream & os );
    5960void ?{}( ofstream & os, const char * name, const char * mode );
     61void ?{}( ofstream & os, const char * name );
    6062
    6163extern ofstream & sout, & serr;
     
    6971int fail( ifstream & is );
    7072int eof( ifstream & is );
     73void open( ifstream & is, const char * name, const char * mode );
    7174void open( ifstream & is, const char * name );
    7275void close( ifstream & is );
     
    7679
    7780void ?{}( ifstream & is );
     81void ?{}( ifstream & is, const char * name, const char * mode );
    7882void ?{}( ifstream & is, const char * name );
    7983
  • src/libcfa/fstream.c

    r5e1adb5 r8da74119  
    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.