-
Notifications
You must be signed in to change notification settings - Fork 0
/
file-util.cc
40 lines (29 loc) · 1000 Bytes
/
file-util.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// file-util.cc
// Code for file-util.h.
#include "file-util.h" // this module
// this dir
#include "pca-util.h" // stringb
// smbase
#include "smbase/string-util.h" // doubleQuote
#include "smbase/stringb.h" // stringb
// libc++
#include <cstring> // std::strerror
#include <fstream> // std::ifstream
#include <sstream> // std::ostringstream
// libc
#include <errno.h> // errno
std::string readFile(std::string /*OUT*/ &contents,
std::string const &fname)
{
std::ifstream inFile(fname.c_str(), std::ios::binary);
if (!inFile) {
return stringb(doubleQuote(fname) << ": " <<
std::strerror(errno));
}
// This is not very efficient...
std::ostringstream os;
os << inFile.rdbuf();
contents = os.str();
return "";
}
// EOF