Teuchos_FileInputStream.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "Teuchos_FileInputStream.hpp"
00030 #include "Teuchos_TestForException.hpp"
00031
00032 using namespace Teuchos;
00033
00034 FileInputStream::FileInputStream(const std::string& filename)
00035 : XMLInputStream(), file_(std::fopen(filename.c_str(), "rb"))
00036 {
00037 TEST_FOR_EXCEPTION(file_ == NULL,
00038 std::runtime_error,
00039 "FileInputStream ctor failed to open file: "
00040 << filename);
00041 }
00042
00043 unsigned int FileInputStream::readBytes(unsigned char* const toFill,
00044 const unsigned int maxToRead)
00045 {
00046 if (
00047 #if defined(ICL) || defined(__sgi)
00048 feof(file_)
00049 #else
00050 std::feof(file_)
00051 #endif
00052 )
00053 return (size_t)0;
00054 int n = std::fread((void*) toFill, sizeof(char), maxToRead, file_);
00055 if (n==0) return (size_t)0;
00056
00057 const bool
00058 is_eof
00059 #if defined(ICL) || defined(__sgi)
00060 = feof(file_)
00061 #else
00062 = std::feof(file_)
00063 #endif
00064 ;
00065
00066 TEST_FOR_EXCEPTION(
00067 n < 0 || (n<(int) maxToRead && !is_eof),
00068 std::runtime_error,
00069 "FileInputStream::readBytes error"
00070 );
00071
00072 return (size_t) n;
00073 }
00074
00075
00076
00077
00078