The patch below is for compiling libclamav on Interix using either gcc or
the cc/c89 MS C compilers. There are two primary issues, the memcmp
intrinsic function cannot be redefined with MSC and __attribute__ ((packed))
is not understood by MSC. Another issue is the MSC will not allow an array
to be declared with a const int, it requires an actual constant.


diff -ru clamav-devel/libclamav/mspack/system.h
clamav-devel-interix/libclamav/mspack/system.h
--- clamav-devel/libclamav/mspack/system.h      Tue Jul 19 21:55:58 2005
+++ clamav-devel-interix/libclamav/mspack/system.h      Wed Jun  7 13:27:03
2006
@@ -39,6 +39,8 @@
 /* validates a system structure */
 extern int mspack_valid_system(struct mspack_system *sys);
 
+/* can't redefine intrinsic memcmp and strlen with the MS C compiler on
Interix*/
+#if (defined __GNUC__ && defined __INTERIX) || !defined __INTERIX
 /* inline memcmp() */
 static inline int memcmp(const void *s1, const void *s2, size_t n) {
   unsigned char *c1 = (unsigned char *) s1;
@@ -55,4 +57,5 @@
   return e - s;
 }
 
+#endif /*interix*/
 #endif
diff -ru clamav-devel/libclamav/unrar/unrar.h
clamav-devel-interix/libclamav/unrar/unrar.h
--- clamav-devel/libclamav/unrar/unrar.h        Sun Apr  9 15:59:28 2006
+++ clamav-devel-interix/libclamav/unrar/unrar.h        Wed Jun  7 14:14:04
2006
@@ -107,18 +107,34 @@
        unsigned char mark[SIZEOF_MARKHEAD];
 } mark_header_t;
 
+#ifdef _MSC_VER
+#pragma pack(1)
+#endif
 typedef struct main_header_tag
 {
+#if (__GNUC__ >= 3)
        uint16_t head_crc __attribute__ ((packed));
        uint8_t head_type __attribute__ ((packed));
        uint16_t flags __attribute__ ((packed));
        uint16_t head_size __attribute__ ((packed));
        uint16_t reserved __attribute__ ((packed));
        uint32_t reserved1 __attribute__ ((packed));
+#else
+       uint16_t head_crc;
+       uint8_t head_type;
+       uint16_t flags;
+       uint16_t head_size;
+       uint16_t reserved;
+       uint32_t reserved1;
+#endif
 } main_header_t;
 
+#ifdef _MSC_VER
+#pragma pack(1)
+#endif
 typedef struct file_header_tag
 {
+#if (__GNUC__ >= 3)
        uint16_t head_crc __attribute__ ((packed));
        uint8_t head_type __attribute__ ((packed));
        uint16_t flags __attribute__ ((packed));
@@ -134,6 +150,23 @@
        uint32_t file_attr __attribute__ ((packed));
        unsigned char *filename __attribute__ ((packed));
        off_t next_offset __attribute__ ((packed));
+#else
+       uint16_t head_crc;
+       uint8_t head_type;
+       uint16_t flags;
+       uint16_t head_size;
+       uint32_t pack_size;
+       uint32_t unpack_size;
+       uint8_t host_os;
+       uint32_t file_crc;
+       uint32_t file_time;
+       uint8_t unpack_ver;
+       uint8_t method;
+       uint16_t name_size;
+       uint32_t file_attr;
+       unsigned char *filename;
+       off_t next_offset;
+#endif
 } file_header_t;
 
 struct Decode
diff -ru clamav-devel/libclamav/unrar/unrarppm.c
clamav-devel-interix/libclamav/unrar/unrarppm.c
--- clamav-devel/libclamav/unrar/unrarppm.c     Sun Apr  9 15:59:28 2006
+++ clamav-devel-interix/libclamav/unrar/unrarppm.c     Wed Jun  7 14:16:43
2006
@@ -41,7 +41,13 @@
 
 const unsigned int UNIT_SIZE=sizeof(struct ppm_context);
 const unsigned int FIXED_UNIT_SIZE=12;
+/* Microsoft C compiler does not accept const int in array declarations;
needs an actual constant. */
+#ifdef _MSC_VER
+const int INT_BITS=7, PERIOD_BITS=7, TOT_BITS=14;
+#define MAX_O 64
+#else
 const int INT_BITS=7, PERIOD_BITS=7, TOT_BITS=14, MAX_O=64;
+#endif
 const int INTERVAL=1 << 7, BIN_SCALE=1 << 14, MAX_FREQ=124;
 const unsigned int TOP=1 << 24, BOT=1 << 15;
 
diff -ru clamav-devel/libclamav/unzip.h
clamav-devel-interix/libclamav/unzip.h
--- clamav-devel/libclamav/unzip.h      Tue May 30 09:00:04 2006
+++ clamav-devel-interix/libclamav/unzip.h      Wed Jun  7 14:13:53 2006
@@ -38,6 +38,9 @@
 /******** Zip format structures *********/
 
 /* Local file header */
+#ifdef _MSC_VER
+#pragma pack(1)
+#endif
 struct zip_file_header
 {
 #   define ZIP_FILE_HEADER_MAGIC 0x04034b50
@@ -55,9 +58,17 @@
 
     /* followed by filename (of variable size) */
     /* followed by extra field (of variable size) */
-} __attribute__((packed));
+} 
+#if (__GNUC__ >= 3)
+       __attribute__((packed));
+#else
+       ;
+#endif
 
 /* Data descriptor (only if bit 3 of z_flags is set) */
+#ifdef _MSC_VER
+#pragma pack(1)
+#endif
 struct zip_file_trailer
 {
 #   define ZIP_FILE_TRAILER_MAGIC 0x08074B50
@@ -65,9 +76,17 @@
     uint32_t z_crc32; /* crc-32 */
     uint32_t z_csize; /* compressed size */
     uint32_t z_usize; /* uncompressed size */
-} __attribute__((packed));
+} 
+#if (__GNUC__ >= 3)
+       __attribute__((packed));
+#else
+       ;
+#endif
 
 /* Central file header */
+#ifdef _MSC_VER
+#pragma pack(1)
+#endif
 struct zip_root_dirent
 {
 #   define ZIP_ROOT_DIRENT_MAGIC 0x02014b50
@@ -92,9 +111,17 @@
     /* followed by filename (of variable size) */
     /* followed by extra field (of variable size) */
     /* followed by file comment (of variable size) */
-} __attribute__((packed));
+} 
+#if (__GNUC__ >= 3)
+       __attribute__((packed));
+#else
+       ;
+#endif
 
 /* End of central directory record */
+#ifdef _MSC_VER
+#pragma pack(1)
+#endif
 struct zip_disk_trailer
 {
 #   define         ZIP_DISK_TRAILER_MAGIC 0x06054b50
@@ -117,7 +144,12 @@
     uint16_t       z_comment;          /* zipfile comment length */
 
     /* followed by zipfile comment (of variable size) */
-} __attribute__((packed));
+} 
+#if (__GNUC__ >= 3)
+       __attribute__((packed));
+#else
+       ;
+#endif
 
 #define ZIP_METHOD_STORED          0
 #define ZIP_METHOD_SHRUNK          1

Brian A. Reiter
WolfeReiter, LLC : Thoughtful Computing
[http://www.thoughtfulcomputing.com]

_______________________________________________
http://lurker.clamav.net/list/clamav-devel.html

Reply via email to