Changes in libcfa/src/fstream.cfa [a87d40b:5cb2b8c]
- File:
-
- 1 edited
-
libcfa/src/fstream.cfa (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/fstream.cfa
ra87d40b r5cb2b8c 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jul 15 18:11:26201913 // Update Count : 3 4912 // Last Modified On : Thu May 16 08:33:28 2019 13 // Update Count : 328 14 14 // 15 15 … … 24 24 #include <assert.h> 25 25 #include <errno.h> // errno 26 27 28 //*********************************** ofstream ***********************************29 30 26 31 27 #define IO_MSG "I/O error: " … … 41 37 sepSetCur( os, sepGet( os ) ); 42 38 sepSetTuple( os, ", " ); 43 } // ?{}39 } 44 40 45 41 // private … … 60 56 void ?{}( ofstream & os, const char * name, const char * mode ) { 61 57 open( os, name, mode ); 62 } // ?{} 63 58 } 64 59 void ?{}( ofstream & os, const char * name ) { 65 60 open( os, name, "w" ); 66 } // ?{}61 } 67 62 68 63 void sepOn( ofstream & os ) { os.sepOnOff = ! getNL( os ); } … … 100 95 } // sepSet 101 96 102 void ends( ofstream & os ) {103 if ( getANL( os ) ) nl( os );104 else setPrt( os, false ); // turn off105 if ( &os == &exit ) exit( EXIT_FAILURE );106 if ( &os == &abort ) abort();107 } // ends108 109 97 int fail( ofstream & os ) { 110 98 return os.file == 0 || ferror( (FILE *)(os.file) ); … … 119 107 #ifdef __CFA_DEBUG__ 120 108 if ( file == 0 ) { 121 abort | IO_MSG "open output file \"" | name | "\"" | nl | strerror( errno);109 abort( IO_MSG "open output file \"%s\", %s", name, strerror( errno ) ); 122 110 } // if 123 111 #endif // __CFA_DEBUG__ … … 133 121 134 122 if ( fclose( (FILE *)(os.file) ) == EOF ) { 135 abort | IO_MSG "close output" | nl | strerror( errno);123 abort( IO_MSG "close output %s", strerror( errno ) ); 136 124 } // if 137 125 } // close … … 139 127 ofstream & write( ofstream & os, const char * data, size_t size ) { 140 128 if ( fail( os ) ) { 141 abort | IO_MSG "attempt write I/O on failed stream";129 abort( "attempt write I/O on failed stream\n" ); 142 130 } // if 143 131 144 132 if ( fwrite( data, 1, size, (FILE *)(os.file) ) != size ) { 145 abort | IO_MSG "write" | nl | strerror( errno);133 abort( IO_MSG "write %s", strerror( errno ) ); 146 134 } // if 147 135 return os; … … 154 142 if ( len == EOF ) { 155 143 if ( ferror( (FILE *)(os.file) ) ) { 156 abort | IO_MSG "invalid write";144 abort( "invalid write\n" ); 157 145 } // if 158 146 } // if … … 165 153 166 154 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_) }; 167 ofstream & sout = soutFile , & stdout = soutFile;155 ofstream & sout = soutFile; 168 156 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_) }; 169 ofstream & serr = serrFile, & stderr = serrFile; 170 171 static ofstream exitFile = { (FILE *)(&_IO_2_1_stdout_) }; 172 ofstream & exit = exitFile; 173 static ofstream abortFile = { (FILE *)(&_IO_2_1_stderr_) }; 174 ofstream & abort = abortFile; 175 176 177 //*********************************** ifstream *********************************** 178 157 ofstream & serr = serrFile; 158 159 // static ofstream sexitFile = { (FILE *)(&_IO_2_1_stdout_) }; 160 // ofstream & sexit = sexitFile; 161 // static ofstream sabortFile = { (FILE *)(&_IO_2_1_stderr_) }; 162 // ofstream & sabort = sabortFile; 163 164 void nl( ofstream & os ) { 165 if ( getANL( os ) ) (ofstream &)(nl( os )); // implementation only 166 else setPrt( os, false ); // turn off 167 } 168 169 //--------------------------------------- 179 170 180 171 // private … … 182 173 is.file = file; 183 174 is.nlOnOff = false; 184 } // ?{}175 } 185 176 186 177 // public … … 189 180 void ?{}( ifstream & is, const char * name, const char * mode ) { 190 181 open( is, name, mode ); 191 } // ?{} 192 182 } 193 183 void ?{}( ifstream & is, const char * name ) { 194 184 open( is, name, "r" ); 195 } // ?{}185 } 196 186 197 187 void nlOn( ifstream & os ) { os.nlOnOff = true; } … … 211 201 #ifdef __CFA_DEBUG__ 212 202 if ( file == 0 ) { 213 abort | IO_MSG "open input file \"" | name | "\"" | nl | strerror( errno);203 abort( IO_MSG "open input file \"%s\", %s\n", name, strerror( errno ) ); 214 204 } // if 215 205 #endif // __CFA_DEBUG__ … … 225 215 226 216 if ( fclose( (FILE *)(is.file) ) == EOF ) { 227 abort | IO_MSG "close input" | nl | strerror( errno);217 abort( IO_MSG "close input %s", strerror( errno ) ); 228 218 } // if 229 219 } // close … … 231 221 ifstream & read( ifstream & is, char * data, size_t size ) { 232 222 if ( fail( is ) ) { 233 abort | IO_MSG "attempt read I/O on failed stream";223 abort( "attempt read I/O on failed stream\n" ); 234 224 } // if 235 225 236 226 if ( fread( data, size, 1, (FILE *)(is.file) ) == 0 ) { 237 abort | IO_MSG "read" | nl | strerror( errno);227 abort( IO_MSG "read %s", strerror( errno ) ); 238 228 } // if 239 229 return is; … … 242 232 ifstream &ungetc( ifstream & is, char c ) { 243 233 if ( fail( is ) ) { 244 abort | IO_MSG "attempt ungetc I/O on failed stream";234 abort( "attempt ungetc I/O on failed stream\n" ); 245 235 } // if 246 236 247 237 if ( ungetc( c, (FILE *)(is.file) ) == EOF ) { 248 abort | IO_MSG "ungetc" | nl | strerror( errno);238 abort( IO_MSG "ungetc %s", strerror( errno ) ); 249 239 } // if 250 240 return is; … … 258 248 if ( len == EOF ) { 259 249 if ( ferror( (FILE *)(is.file) ) ) { 260 abort | IO_MSG "invalid read";250 abort( "invalid read\n" ); 261 251 } // if 262 252 } // if … … 267 257 268 258 static ifstream sinFile = { (FILE *)(&_IO_2_1_stdin_) }; 269 ifstream & sin = sinFile , & stdin = sinFile;259 ifstream & sin = sinFile; 270 260 271 261 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.