Fix building on newer Linux systems (particularly Fedora 13)
[reactos.git] / reactos / tools / cabman / cabinet.cxx
index 3eaecad..5d834a9 100755 (executable)
 #include <string.h>
 #if !defined(WIN32)
 # include <dirent.h>
-#endif
-#if defined(__FreeBSD__) || defined(__APPLE__)
 # include <sys/stat.h>
-#endif // __FreeBSD__
+# include <sys/types.h>
+#endif
 #include "cabinet.h"
 #include "raw.h"
 #include "mszip.h"
@@ -64,7 +63,7 @@ static bool _ReadFileData(FILEHANDLE handle, void* buffer, ULONG size, PULONG by
 #ifndef CAB_READ_ONLY
 
 #if 0
-#ifdef DBG
+#if DBG
 
 void DumpBuffer(void* Buffer, ULONG Size)
 {
@@ -1477,7 +1476,6 @@ ULONG CCabinet::NewCabinet()
  */
 {
     ULONG Status;
-       CHAR const TempName[9] = { '~', 'C', 'A', 'B', '.', 't', 'm', 'p', '0' };
 
     CurrentDiskNumber = 0;
 
@@ -1529,7 +1527,7 @@ ULONG CCabinet::NewCabinet()
         return CAB_STATUS_NOMEMORY;
     }
 
-    Status = ScratchFile->Create(TempName);
+    Status = ScratchFile->Create("~CAB.tmp");
 
     CreateNewFolder = false;
 
@@ -1695,8 +1693,7 @@ ULONG CCabinet::WriteFileToScratchStorage(PCFFILE_NODE FileNode)
                 return CAB_STATUS_INVALID_CAB;
             }
 
-            *(unsigned char**)&CurrentIBuffer += BytesRead;
-
+            CurrentIBuffer = (unsigned char*)CurrentIBuffer + BytesRead;
             CurrentIBufferSize += (USHORT)BytesRead;
 
             if (CurrentIBufferSize == CAB_BLOCKSIZE)
@@ -2057,9 +2054,19 @@ ULONG CCabinet::AddFile(char* FileName)
         return CAB_STATUS_CANNOT_READ;
     }
 
-    GetFileTimes(SrcFile, FileNode);
+    if (GetFileTimes(SrcFile, FileNode) != CAB_STATUS_SUCCESS)
+    {
+        DPRINT(MIN_TRACE, ("Cannot read file times.\n"));
+        FreeMemory(NewFileName);
+        return CAB_STATUS_CANNOT_READ;
+    }
 
-    GetAttributesOnFile(FileNode);
+    if (GetAttributesOnFile(FileNode) != CAB_STATUS_SUCCESS)
+    {
+        DPRINT(MIN_TRACE, ("Cannot read file attributes.\n"));
+        FreeMemory(NewFileName);
+        return CAB_STATUS_CANNOT_READ;
+    }
 
     CloseFile(SrcFile);
 
@@ -3574,8 +3581,8 @@ ULONG CCabinet::WriteDataBlock()
     CurrentFolderNode->TotalFolderSize += (BytesWritten + sizeof(CFDATA));
     CurrentFolderNode->Folder.DataBlockCount++;
 
-    *(unsigned char**)&CurrentOBuffer += DataNode->Data.CompSize;
-    CurrentOBufferSize     -= DataNode->Data.CompSize;
+    CurrentOBuffer = (unsigned char*)CurrentOBuffer + DataNode->Data.CompSize;
+    CurrentOBufferSize -= DataNode->Data.CompSize;
 
     LastBlockStart += DataNode->Data.UncompSize;
 
@@ -3648,7 +3655,8 @@ ULONG CCabinet::GetFileTimes(FILEHANDLE FileHandle, PCFFILE_NODE File)
         strcpy(buf, File->FileName);
     else
     {
-        getcwd(buf, sizeof(buf));
+        if (!getcwd(buf, sizeof(buf)))
+            return CAB_STATUS_CANNOT_READ;
         strcat(buf, DIR_SEPARATOR_STRING);
         strcat(buf, File->FileName);
     }
@@ -3691,7 +3699,8 @@ ULONG CCabinet::GetAttributesOnFile(PCFFILE_NODE File)
         strcpy(buf, File->FileName);
     else
     {
-        getcwd(buf, sizeof(buf));
+        if (!getcwd(buf, sizeof(buf)))
+            return CAB_STATUS_CANNOT_READ;
         strcat(buf, DIR_SEPARATOR_STRING);
         strcat(buf, File->FileName);
     }