mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 16:36:33 +00:00
[CABMAN] Do not use tmpfile() because it does not work well on Windows XP
- Use tempnam() and fopen() instead. - Prevent the use of file names with a leading slash or backslash. - Also prevent the use of file names with a trailing dot. - Remove temporary files after use.
This commit is contained in:
parent
658d5a3ff5
commit
7afc888279
1 changed files with 24 additions and 2 deletions
|
@ -55,7 +55,27 @@ CCFDATAStorage::~CCFDATAStorage()
|
|||
*/
|
||||
ULONG CCFDATAStorage::Create()
|
||||
{
|
||||
if ((FileHandle = tmpfile()) == NULL)
|
||||
char TmpName[MAX_PATH];
|
||||
char *pName;
|
||||
int length;
|
||||
|
||||
if (tmpnam(TmpName) == NULL)
|
||||
return CAB_STATUS_CANNOT_CREATE;
|
||||
|
||||
/* Append 'tmp' if the file name ends with a dot */
|
||||
length = strlen(TmpName);
|
||||
if (length > 0 && TmpName[length - 1] == '.')
|
||||
strcat(TmpName, "tmp");
|
||||
|
||||
/* Skip a leading slash or backslash */
|
||||
pName = TmpName;
|
||||
if (*pName == '/' || *pName == '\\')
|
||||
pName++;
|
||||
|
||||
strcpy(FullName, pName);
|
||||
|
||||
FileHandle = fopen(FullName, "w+b");
|
||||
if (FileHandle == NULL)
|
||||
return CAB_STATUS_CANNOT_CREATE;
|
||||
|
||||
return CAB_STATUS_SUCCESS;
|
||||
|
@ -78,6 +98,8 @@ ULONG CCFDATAStorage::Destroy()
|
|||
|
||||
FileHandle = NULL;
|
||||
|
||||
remove(FullName);
|
||||
|
||||
return CAB_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -93,7 +115,7 @@ ULONG CCFDATAStorage::Destroy()
|
|||
ULONG CCFDATAStorage::Truncate()
|
||||
{
|
||||
fclose(FileHandle);
|
||||
FileHandle = tmpfile();
|
||||
FileHandle = fopen(FullName, "w+b");
|
||||
if (FileHandle == NULL)
|
||||
{
|
||||
DPRINT(MID_TRACE, ("ERROR '%i'.\n", errno));
|
||||
|
|
Loading…
Reference in a new issue