Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/fstream.cfa

    r0efb269 r9d362a0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Apr 20 12:03:43 2019
    13 // Update Count     : 311
     12// Last Modified On : Mon Dec 24 18:33:38 2018
     13// Update Count     : 304
    1414//
    1515
     
    2323#include <complex.h>                                                                    // creal, cimag
    2424#include <assert.h>
    25 #include <errno.h>                                                                              // errno
    2625
    2726#define IO_MSG "I/O error: "
     
    3332        os.nlOnOff = nlOnOff;
    3433        os.prt = prt;
    35         os.sawNL = false;
    3634        sepSet( os, separator );
    3735        sepSetCur( os, sepGet( os ) );
     
    107105        #ifdef __CFA_DEBUG__
    108106        if ( file == 0 ) {
    109                 abort( IO_MSG "open output file \"%s\", %s", name, strerror( errno ) );
     107                fprintf( stderr, IO_MSG "open output file \"%s\", ", name );
     108                perror( 0 );
     109                exit( EXIT_FAILURE );
    110110        } // if
    111111        #endif // __CFA_DEBUG__
     
    121121
    122122        if ( fclose( (FILE *)(os.file) ) == EOF ) {
    123                 abort( IO_MSG "close output %s", strerror( errno ) );
     123                perror( IO_MSG "close output" );
    124124        } // if
    125125} // close
     
    127127ofstream & write( ofstream & os, const char * data, size_t size ) {
    128128        if ( fail( os ) ) {
    129                 abort( "attempt write I/O on failed stream\n" );
     129                fprintf( stderr, "attempt write I/O on failed stream\n" );
     130                exit( EXIT_FAILURE );
    130131        } // if
    131132
    132133        if ( fwrite( data, 1, size, (FILE *)(os.file) ) != size ) {
    133                 abort( IO_MSG "write %s", strerror( errno ) );
     134                perror( IO_MSG "write" );
     135                exit( EXIT_FAILURE );
    134136        } // if
    135137        return os;
     
    142144        if ( len == EOF ) {
    143145                if ( ferror( (FILE *)(os.file) ) ) {
    144                         abort( "invalid write\n" );
     146                        fprintf( stderr, "invalid write\n" );
     147                        exit( EXIT_FAILURE );
    145148                } // if
    146149        } // if
     
    163166void ?{}( ifstream & is, void * file ) {
    164167        is.file = file;
    165         is.nlOnOff = false;
    166168}
    167169
     
    175177        open( is, name, "r" );
    176178}
    177 
    178 void nlOn( ifstream & os ) { os.nlOnOff = true; }
    179 void nlOff( ifstream & os ) { os.nlOnOff = false; }
    180 bool getANL( ifstream & os ) { return os.nlOnOff; }
    181179
    182180int fail( ifstream & is ) {
     
    189187
    190188void open( ifstream & is, const char * name, const char * mode ) {
    191         FILE * file = fopen( name, mode );
     189        FILE *file = fopen( name, mode );
    192190        #ifdef __CFA_DEBUG__
    193191        if ( file == 0 ) {
    194                 abort( IO_MSG "open input file \"%s\", %s\n", name, strerror( errno ) );
     192                fprintf( stderr, IO_MSG "open input file \"%s\", ", name );
     193                perror( 0 );
     194                exit( EXIT_FAILURE );
    195195        } // if
    196196        #endif // __CFA_DEBUG__
     
    206206
    207207        if ( fclose( (FILE *)(is.file) ) == EOF ) {
    208                 abort( IO_MSG "close input %s", strerror( errno ) );
     208                perror( IO_MSG "close input" );
    209209        } // if
    210210} // close
     
    212212ifstream & read( ifstream & is, char * data, size_t size ) {
    213213        if ( fail( is ) ) {
    214                 abort( "attempt read I/O on failed stream\n" );
     214                fprintf( stderr, "attempt read I/O on failed stream\n" );
     215                exit( EXIT_FAILURE );
    215216        } // if
    216217
    217218        if ( fread( data, size, 1, (FILE *)(is.file) ) == 0 ) {
    218                 abort( IO_MSG "read %s", strerror( errno ) );
     219                perror( IO_MSG "read" );
     220                exit( EXIT_FAILURE );
    219221        } // if
    220222        return is;
     
    223225ifstream &ungetc( ifstream & is, char c ) {
    224226        if ( fail( is ) ) {
    225                 abort( "attempt ungetc I/O on failed stream\n" );
     227                fprintf( stderr, "attempt ungetc I/O on failed stream\n" );
     228                exit( EXIT_FAILURE );
    226229        } // if
    227230
    228231        if ( ungetc( c, (FILE *)(is.file) ) == EOF ) {
    229                 abort( IO_MSG "ungetc %s", strerror( errno ) );
     232                perror( IO_MSG "ungetc" );
     233                exit( EXIT_FAILURE );
    230234        } // if
    231235        return is;
     
    239243        if ( len == EOF ) {
    240244                if ( ferror( (FILE *)(is.file) ) ) {
    241                         abort( "invalid read\n" );
     245                        fprintf( stderr, "invalid read\n" );
     246                        exit( EXIT_FAILURE );
    242247                } // if
    243248        } // if
Note: See TracChangeset for help on using the changeset viewer.