I'm tring to compile a very simple test program using libarchive (joined as attached file).
apparently I also need libgw32c which define correct header and structure required by libarchive while developing
I could download them both from there:
http://gnuwin32.sourceforge.net/packages/
==>
http://gnuwin32.sourceforge.net/packages/libarchive.htm
http://gnuwin32.sourceforge.net/packages/libgw32c.htm


I was not able to install correctly libgw32c, I mean whatever I do I had plenty of error message during the compilation (with some error in the system header introduced by libgw32c).
-- error like that ---
c:/GNUstep/Development/msys/1.0/mingw/include/winx/stdiox.h: In function `__flbf':
c:/GNUstep/Development/msys/1.0/mingw/include/winx/stdiox.h:64: structure has no member named `_flag'
c:/GNUstep/Development/msys/1.0/mingw/include/winx/stdiox.h: In function `__fpending':
c:/GNUstep/Development/msys/1.0/mingw/include/winx/stdiox.h:69: structure has no member named `_ptr'
.... continued ....
--------------------


If I try without libgw32c my program compile but fail. for some reason one archive_write_data fail with either:
Numeric group ID too large: Result too large
or
GZip compression failed


depending wether or not I use GZip compression or not.

As I'm thining the problem *might* comes from 'struct stat' I try define a custome one which fit the form I would expect.
but still got the same errors...


I'm quite at loss, could anyone provide some guidance? or link? or whatever?
#define __GW32__ 1

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>

#include <winx/stdiox.h>
#include <winx/stdlibx.h>
#include <winx/sys/statx.h>

//typedef long uid_t;
//typedef long gid_t;

#include <archive.h>
#include <archive_entry.h>

#include <basetsd.h>

#define DEBUG(x) printf("%s:%d(:%s)   %s =>%d\terr:%s\n", __FILE__, __LINE__, 
__FUNCTION__, #x, x, archive_error_string(a))

static void write_archive();

// gcc libarchive.c -o a.exe -L. -larchive1 -lgw32c  && a
// gcc libarchive.c -o a.exe -L. -larchive1          && a
main()
{
        write_archive();
}

/* Structure describing file characteristics.  */
struct stat2
 {
   /* These are the members that POSIX.1 requires.  */

   unsigned __int32 st_mode;            /* File mode.  */
        unsigned __int32 st_ino;                /* File serial number.  */
   unsigned __int64 st_dev;             /* Device containing the file.  */
   unsigned __int32 st_nlink;           /* Link count.  */
   unsigned __int32 st_uid;             /* User ID of the file's owner.  */
   unsigned __int32 st_gid;             /* Group ID of the file's group.  */
   unsigned __int32 st_size;            /* Size of file, in bytes.  */
   __int32 st_atime;            /* Time of last access.  */
   __int32 st_mtime;            /* Time of last modification.  */
   __int32 st_ctime;            /* Time of last status change.  */

   /* This should be defined if there is a `st_blksize' member.  */
#undef  _STATBUF_ST_BLKSIZE
 };

static void write_archive()
{
char data[] = "Lloyd is Great!";
int len = sizeof(data);

// create an archive
struct archive * a = archive_write_new();
DEBUG(archive_write_set_compression_gzip(a));
DEBUG(archive_write_set_format_ustar(a));
DEBUG(archive_write_open_file(a, "foo.tar.gz"));

struct stat2 st; // some stat for the entries
//stat("libarchive.c", &st);
st.st_mode = S_IFREG|0666;
st.st_uid = 0; //getuid();
st.st_gid = -1; //getgid();
//st.st_blocks = 32;
//st.st_blksize = 4096;
st.st_nlink = 1;

// create an entry
struct archive_entry * entry = archive_entry_new();
st.st_size = len;
archive_entry_copy_stat(entry, (struct stat *) &st);
archive_entry_set_pathname(entry, "grearg.txt");
archive_entry_set_size(entry, len);
DEBUG(archive_write_header(a, entry));

// put some data in the entrty
DEBUG(archive_write_data(a, data, len)); archive_entry_free(entry);

DEBUG(archive_write_close(a));
archive_write_finish(a); // done
}




Reply via email to