commit
dad7911214
|
@ -322,8 +322,9 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
|
||||||
char buffer[BSIZE];
|
char buffer[BSIZE];
|
||||||
|
|
||||||
// Open input file
|
// Open input file
|
||||||
FILE *input = fopen(srcFilename.c_str(), "rb");
|
std::ifstream input;
|
||||||
if (!input)
|
OpenFStream(input, srcFilename, std::ifstream::in | std::ifstream::binary);
|
||||||
|
if (!input.is_open())
|
||||||
{
|
{
|
||||||
ERROR_LOG(COMMON, "Copy: input failed %s --> %s: %s",
|
ERROR_LOG(COMMON, "Copy: input failed %s --> %s: %s",
|
||||||
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
||||||
|
@ -331,51 +332,39 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// open output file
|
// open output file
|
||||||
FILE *output = fopen(destFilename.c_str(), "wb");
|
File::IOFile output(destFilename, "wb");
|
||||||
if (!output)
|
|
||||||
|
if (!output.IsOpen())
|
||||||
{
|
{
|
||||||
fclose(input);
|
|
||||||
ERROR_LOG(COMMON, "Copy: output failed %s --> %s: %s",
|
ERROR_LOG(COMMON, "Copy: output failed %s --> %s: %s",
|
||||||
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy loop
|
// copy loop
|
||||||
while (!feof(input))
|
while (!input.eof())
|
||||||
{
|
{
|
||||||
// read input
|
// read input
|
||||||
int rnum = fread(buffer, sizeof(char), BSIZE, input);
|
input.read(buffer, BSIZE);
|
||||||
if (rnum != BSIZE)
|
if (!input)
|
||||||
{
|
{
|
||||||
if (ferror(input) != 0)
|
ERROR_LOG(COMMON,
|
||||||
{
|
"Copy: failed reading from source, %s --> %s: %s",
|
||||||
ERROR_LOG(COMMON,
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
||||||
"Copy: failed reading from source, %s --> %s: %s",
|
return false;
|
||||||
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
|
||||||
goto bail;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// write output
|
// write output
|
||||||
int wnum = fwrite(buffer, sizeof(char), rnum, output);
|
if (!output.WriteBytes(buffer, BSIZE))
|
||||||
if (wnum != rnum)
|
|
||||||
{
|
{
|
||||||
ERROR_LOG(COMMON,
|
ERROR_LOG(COMMON,
|
||||||
"Copy: failed writing to output, %s --> %s: %s",
|
"Copy: failed writing to output, %s --> %s: %s",
|
||||||
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
||||||
goto bail;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// close files
|
|
||||||
fclose(input);
|
|
||||||
fclose(output);
|
|
||||||
return true;
|
return true;
|
||||||
bail:
|
|
||||||
if (input)
|
|
||||||
fclose(input);
|
|
||||||
if (output)
|
|
||||||
fclose(output);
|
|
||||||
return false;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -208,18 +208,17 @@ static bool Memory_TryBase(u8 *base, MemoryView *views, int num_views, u32 flags
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!view->view_ptr)
|
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)
|
if (view->out_ptr)
|
||||||
*(view->out_ptr) = (u8*) view->view_ptr;
|
*(view->out_ptr) = (u8*) view->view_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
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)
|
static u32 MemoryMap_InitializeViews(MemoryView *views, int num_views, u32 flags)
|
||||||
|
|
Loading…
Reference in New Issue