|
19 | 19 | #include "Support/StringExtras.h"
|
20 | 20 | #include "Config/fcntl.h"
|
21 | 21 | #include <sys/stat.h>
|
| 22 | +#include <cerrno> |
22 | 23 | #include "Config/unistd.h"
|
23 | 24 | #include "Config/sys/mman.h"
|
24 | 25 | using namespace llvm;
|
@@ -57,22 +58,26 @@ namespace {
|
57 | 58 | };
|
58 | 59 | }
|
59 | 60 |
|
| 61 | +static std::string ErrnoMessage (int savedErrNum, std::string descr) { |
| 62 | + return ::strerror(savedErrNum) + std::string(", while trying to ") + descr; |
| 63 | +} |
| 64 | + |
60 | 65 | BytecodeFileReader::BytecodeFileReader(const std::string &Filename) {
|
61 | 66 | FDHandle FD = open(Filename.c_str(), O_RDONLY);
|
62 | 67 | if (FD == -1)
|
63 |
| - throw std::string("Error opening file!"); |
| 68 | + throw ErrnoMessage(errno, "open '" + Filename + "'"); |
64 | 69 |
|
65 | 70 | // Stat the file to get its length...
|
66 | 71 | struct stat StatBuf;
|
67 | 72 | if (fstat(FD, &StatBuf) == -1 || StatBuf.st_size == 0)
|
68 |
| - throw std::string("Error stat'ing file!"); |
| 73 | + throw ErrnoMessage(errno, "stat '" + Filename + "'"); |
69 | 74 |
|
70 | 75 | // mmap in the file all at once...
|
71 | 76 | Length = StatBuf.st_size;
|
72 | 77 | Buffer = (unsigned char*)mmap(0, Length, PROT_READ, MAP_PRIVATE, FD, 0);
|
73 | 78 |
|
74 | 79 | if (Buffer == (unsigned char*)MAP_FAILED)
|
75 |
| - throw std::string("Error mmapping file!"); |
| 80 | + throw ErrnoMessage(errno, "map '" + Filename + "' into memory"); |
76 | 81 |
|
77 | 82 | try {
|
78 | 83 | // Parse the bytecode we mmapped in
|
@@ -167,7 +172,7 @@ BytecodeStdinReader::BytecodeStdinReader() {
|
167 | 172 | // Read in all of the data from stdin, we cannot mmap stdin...
|
168 | 173 | while ((BlockSize = ::read(0 /*stdin*/, Buffer, 4096*4))) {
|
169 | 174 | if (BlockSize == -1)
|
170 |
| - throw std::string("Error reading from stdin!"); |
| 175 | + throw ErrnoMessage(errno, "read from standard input"); |
171 | 176 |
|
172 | 177 | FileData.insert(FileData.end(), Buffer, Buffer+BlockSize);
|
173 | 178 | }
|
|
0 commit comments