Pol  Revision:4b29d2b
filecont.cpp
Go to the documentation of this file.
1 
7 #include "filecont.h"
8 
9 #include <cstdio>
10 
11 #include "logfacility.h"
12 
13 namespace Pol
14 {
15 namespace Clib
16 {
23 FileContents::FileContents( const char* filename )
24 {
25  FILE* fp = fopen( filename, "rb" );
26  if ( fp == NULL )
27  {
28  ERROR_PRINT << "Unable to open '" << filename << "' for reading.\n";
29  throw std::runtime_error( "Error opening file" );
30  }
31 
32  char buf[1024];
33  while ( !ferror( fp ) && !feof( fp ) )
34  {
35  size_t nread = fread( buf, 1, sizeof buf, fp );
36  if ( nread )
37  contents_.append( buf, nread );
38  }
39 
40  fclose( fp );
41 }
42 
46 const char* FileContents::contents() const
47 {
48  return contents_.c_str();
49 }
50 
54 void FileContents::set_contents( const std::string& str )
55 {
56  contents_ = str;
57 }
58 }
59 }
const char * contents() const
Definition: filecont.cpp:46
std::string contents_
Definition: filecont.h:21
FileContents(const char *filname)
Definition: filecont.cpp:23
void set_contents(const std::string &str)
Definition: filecont.cpp:54
#define ERROR_PRINT
Definition: logfacility.h:230
Definition: berror.cpp:12