diff options
author | Shaun Verch <shaun.verch@10gen.com> | 2013-08-14 13:17:37 -0400 |
---|---|---|
committer | Shaun Verch <shaun.verch@10gen.com> | 2013-08-14 13:39:01 -0400 |
commit | 8f8ab9162c78f49b0ada3a0b8073c53755f0fc87 (patch) | |
tree | 4171b96e53e2ee4b2845ef8b1322e1498d3bb2bb /src/mongo/util/options_parser/options_parser.cpp | |
parent | d42628ece83ebf3a6b340ae8c894e45a2c2ec9b9 (diff) | |
download | mongo-8f8ab9162c78f49b0ada3a0b8073c53755f0fc87.tar.gz |
SERVER-8510 Use ferror to check error instead of checking for num bytes read
Diffstat (limited to 'src/mongo/util/options_parser/options_parser.cpp')
-rw-r--r-- | src/mongo/util/options_parser/options_parser.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/mongo/util/options_parser/options_parser.cpp b/src/mongo/util/options_parser/options_parser.cpp index bc9f11c7b02..eab8ea632ff 100644 --- a/src/mongo/util/options_parser/options_parser.cpp +++ b/src/mongo/util/options_parser/options_parser.cpp @@ -488,23 +488,23 @@ namespace optionenvironment { // Read into a vector first since it's guaranteed to have contiguous storage std::vector<char> configVector; + configVector.resize(configSize); - // We need to allocate an extra byte for our vector because fread on windows accesses memory - // one byte past the size that we pass in. - configVector.resize(configSize + 1); - long nread = fread(&configVector[0], sizeof(char), configSize, config); - if (nread != configSize) { - const int current_errno = errno; - // TODO: Make sure errno is the correct way to do this - StringBuilder sb; - sb << "Error reading in config file: " << strerror(current_errno); - return Status(ErrorCodes::InternalError, sb.str()); + if (configSize > 0) { + long nread = 0; + while (!feof(config) && nread < configSize) { + nread = nread + fread(&configVector[nread], sizeof(char), + configSize - nread, config); + if (ferror(config)) { + const int current_errno = errno; + // TODO: Make sure errno is the correct way to do this + StringBuilder sb; + sb << "Error reading in config file: " << strerror(current_errno); + return Status(ErrorCodes::InternalError, sb.str()); + } + } } - // We had to allocate an extra byte for our vector because fread on windows accesses memory - // one byte past the size that we pass in. Resize back to the actual size of the file. - configVector.resize(configSize); - // Copy the vector contents into our result string *contents = std::string(configVector.begin(), configVector.end()); fclose(config); |