Avoid using SEEK_END when possible
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6917 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
1ae118af99
commit
5f1651ab91
4 changed files with 44 additions and 53 deletions
|
@ -3974,34 +3974,16 @@ int CEXEBuild::load_stub()
|
|||
}
|
||||
|
||||
int CEXEBuild::update_exehead(const tstring& file, size_t *size/*=NULL*/) {
|
||||
FILE *tmpfile = FOPEN(file.c_str(), ("rb"));
|
||||
if (!tmpfile)
|
||||
{
|
||||
ERROR_MSG(_T("Error: opening stub \"%") NPRIs _T("\"\n"), file.c_str());
|
||||
return PS_ERROR;
|
||||
}
|
||||
|
||||
fseek(tmpfile, 0, SEEK_END);
|
||||
size_t exehead_size = ftell(tmpfile);
|
||||
|
||||
unsigned char *exehead = new unsigned char[exehead_size];
|
||||
fseek(tmpfile, 0, SEEK_SET);
|
||||
if (fread(exehead, 1, exehead_size, tmpfile) != exehead_size)
|
||||
unsigned long exehead_size;
|
||||
unsigned char *exehead = alloc_and_read_file(file.c_str(), exehead_size);
|
||||
if (!exehead)
|
||||
{
|
||||
ERROR_MSG(_T("Error: reading stub \"%") NPRIs _T("\"\n"), file.c_str());
|
||||
fclose(tmpfile);
|
||||
delete [] exehead;
|
||||
return PS_ERROR;
|
||||
}
|
||||
fclose(tmpfile);
|
||||
|
||||
update_exehead(exehead, exehead_size);
|
||||
|
||||
if (size)
|
||||
*size = exehead_size;
|
||||
|
||||
delete [] exehead;
|
||||
|
||||
if (size) *size = exehead_size;
|
||||
free(exehead);
|
||||
return PS_OK;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue