- Timestamp:
- Jun 18, 2020, 7:03:55 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 6026628
- Parents:
- 030653a
- Location:
- libcfa/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/fstream.cfa
r030653a r91e52be 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Feb 7 19:01:01 202013 // Update Count : 3 6312 // Last Modified On : Thu Jun 18 15:37:21 2020 13 // Update Count : 380 14 14 // 15 15 … … 123 123 #ifdef __CFA_DEBUG__ 124 124 if ( file == 0p ) { 125 throw (IO_OPEN_FAILURE){ os }; 125 126 abort | IO_MSG "open output file \"" | name | "\"" | nl | strerror( errno ); 126 127 } // if … … 134 135 135 136 void 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; 137 139 138 140 if ( fclose( (FILE *)(os.$file) ) == EOF ) { 139 141 abort | IO_MSG "close output" | nl | strerror( errno ); 140 142 } // if 143 os.$file = 0p; 141 144 } // close 142 145 … … 219 222 #ifdef __CFA_DEBUG__ 220 223 if ( file == 0p ) { 224 throw (IO_OPEN_FAILURE){ is }; 221 225 abort | IO_MSG "open input file \"" | name | "\"" | nl | strerror( errno ); 222 226 } // if … … 230 234 231 235 void 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; 233 238 234 239 if ( fclose( (FILE *)(is.$file) ) == EOF ) { 235 240 abort | IO_MSG "close input" | nl | strerror( errno ); 236 241 } // if 242 is.$file = 0p; 237 243 } // close 238 244 … … 276 282 ifstream & sin = sinFile, & stdin = sinFile; 277 283 284 285 //*********************************** exceptions *********************************** 286 287 288 void ?{}( IO_OPEN_FAILURE & this, ofstream & ostream ) { 289 VTABLE_INIT(this, IO_OPEN_FAILURE); 290 this.ostream = &ostream; 291 } 292 void ?{}( IO_OPEN_FAILURE & this, ifstream & istream ) { 293 VTABLE_INIT(this, IO_OPEN_FAILURE); 294 this.istream = &istream; 295 } 296 const char * IO_OPEN_FAILURE_msg(IO_OPEN_FAILURE * this) { 297 return "IO_OPEN_FAILURE"; 298 } 299 VTABLE_INSTANCE(IO_OPEN_FAILURE)(IO_OPEN_FAILURE_msg); 300 void throwIO_OPEN_FAILURE( ofstream & ostream ) { 301 IO_OPEN_FAILURE exc = { ostream }; 302 } 303 void throwIO_OPEN_FAILURE( ifstream & istream ) { 304 IO_OPEN_FAILURE exc = { istream }; 305 } 306 278 307 // Local Variables: // 279 308 // tab-width: 4 // -
libcfa/src/fstream.hfa
r030653a r91e52be 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Feb 17 08:29:23202013 // Update Count : 1 7512 // Last Modified On : Tue Jun 16 20:41:21 2020 13 // Update Count : 184 14 14 // 15 15 … … 17 17 18 18 #include "iostream.hfa" 19 #include <exception.hfa> 19 20 20 21 … … 106 107 extern ifstream & sin, & stdin; // aliases 107 108 109 110 //*********************************** exceptions *********************************** 111 112 113 DATA_EXCEPTION(IO_OPEN_FAILURE)( 114 union { 115 ofstream * ostream; 116 ifstream * istream; 117 }; 118 ); 119 120 void ?{}( IO_OPEN_FAILURE & this, ofstream & ostream ); 121 void ?{}( IO_OPEN_FAILURE & this, ifstream & istream ); 122 108 123 // Local Variables: // 109 124 // mode: c //
Note: See TracChangeset
for help on using the changeset viewer.