Skip to content

Commit

Permalink
Merge pull request #1486 from rohit-n/goto
Browse files Browse the repository at this point in the history
Remove some gotos.
  • Loading branch information
delroth committed Dec 20, 2014
2 parents cee4a85 + a53c521 commit dad7911
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
43 changes: 16 additions & 27 deletions Source/Core/Common/FileUtil.cpp
Expand Up @@ -322,60 +322,49 @@ 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());
return false;
}

// 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
}

Expand Down
11 changes: 5 additions & 6 deletions Source/Core/Common/MemArena.cpp
Expand Up @@ -208,18 +208,17 @@ static bool Memory_TryBase(u8 *base, MemoryView *views, int num_views, u32 flags
}

if (!view->view_ptr)
goto bail;
{
// Argh! ERROR! Free what we grabbed so far so we can try again.
MemoryMap_Shutdown(views, i+1, flags, arena);
return false;
}

if (view->out_ptr)
*(view->out_ptr) = (u8*) view->view_ptr;
}

return true;

bail:
// Argh! ERROR! Free what we grabbed so far so we can try again.
MemoryMap_Shutdown(views, i+1, flags, arena);
return false;
}

static u32 MemoryMap_InitializeViews(MemoryView *views, int num_views, u32 flags)
Expand Down

0 comments on commit dad7911

Please sign in to comment.