diff options
| author | Pierre Bourdon <delroth@gmail.com> | 2014-12-20 16:47:55 +0100 |
|---|---|---|
| committer | Pierre Bourdon <delroth@gmail.com> | 2014-12-20 16:47:55 +0100 |
| commit | dad791121427f2d3f076756d1b3c10130740dc63 (patch) | |
| tree | 8a74b385f3b9c913b5f20d747e72e36d76cf19df /Source/Core/Common/FileUtil.cpp | |
| parent | cee4a85a12205ba801659854b66126e74fe9c10d (diff) | |
| parent | a53c5217bb8e5f724821efc764eec78b97926361 (diff) | |
Merge pull request #1486 from rohit-n/goto
Remove some gotos.
Diffstat (limited to 'Source/Core/Common/FileUtil.cpp')
| -rw-r--r-- | Source/Core/Common/FileUtil.cpp | 43 |
1 files changed, 16 insertions, 27 deletions
diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 0377afb7ce..ad5370958d 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -322,8 +322,9 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename) char buffer[BSIZE]; // Open input file - FILE *input = fopen(srcFilename.c_str(), "rb"); - if (!input) + std::ifstream input; + OpenFStream(input, srcFilename, std::ifstream::in | std::ifstream::binary); + if (!input.is_open()) { ERROR_LOG(COMMON, "Copy: input failed %s --> %s: %s", srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); @@ -331,51 +332,39 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename) } // open output file - FILE *output = fopen(destFilename.c_str(), "wb"); - if (!output) + File::IOFile output(destFilename, "wb"); + + if (!output.IsOpen()) { - fclose(input); ERROR_LOG(COMMON, "Copy: output failed %s --> %s: %s", srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); return false; } // copy loop - while (!feof(input)) + while (!input.eof()) { // read input - int rnum = fread(buffer, sizeof(char), BSIZE, input); - if (rnum != BSIZE) + input.read(buffer, BSIZE); + if (!input) { - if (ferror(input) != 0) - { - ERROR_LOG(COMMON, - "Copy: failed reading from source, %s --> %s: %s", - srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); - goto bail; - } + ERROR_LOG(COMMON, + "Copy: failed reading from source, %s --> %s: %s", + srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); + return false; } // write output - int wnum = fwrite(buffer, sizeof(char), rnum, output); - if (wnum != rnum) + if (!output.WriteBytes(buffer, BSIZE)) { ERROR_LOG(COMMON, "Copy: failed writing to output, %s --> %s: %s", srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); - goto bail; + return false; } } - // close files - fclose(input); - fclose(output); + return true; -bail: - if (input) - fclose(input); - if (output) - fclose(output); - return false; #endif } |
