|
From: Giovanni C. <val...@li...> - 2000-12-20 13:00:11
|
Hi! I'm sending a new version of tarlib that can be put in CVS tree. Now the source code is cleaner and safer. The only high level function which is present is tl_getfilelist(). It does support only regular files (no long names yet) and directories. The only info you can get from archive is the name of each file, its type and its size. .tar.gz and .tar.bz2 files are not supported yet. It is not much, but with this Gnomezip should be able to display .tar files' content. Bye Giovanni PS. Hongli, you can add my name to the website now (Thanks!). BTW, can I have a CVS account, please? |
|
From: Hongli L. <ho...@te...> - 2000-12-20 14:16:15
|
On Wed, 20 Dec 2000 13:24:24 Giovanni Corriga wrote: > Hi! > > I'm sending a new version of tarlib that can be put in CVS tree. Now the > source code is cleaner and safer. Committed. > .tar.gz and .tar.bz2 files are not supported yet. You shouldn't. It's better to create separated classes for them. > PS. Hongli, you can add my name to the website now (Thanks!). BTW, can I > have a CVS account, please? I want to, but I'm trying to upload the updated HTML files for days now, without any success. I did update the AUTHORS file. |
|
From: Simo S. <sim...@ti...> - 2000-12-23 12:59:46
|
Some comments on the code:
Giovanni Corriga wrote:
>
> Hi!
>
> I'm sending a new version of tarlib that can be put in CVS tree. Now the
> source code is cleaner and safer.
>
> The only high level function which is present is tl_getfilelist(). It
> does support only regular files (no long names yet) and directories. The
> only info you can get from archive is the name of each file, its type
> and its size.
> .tar.gz and .tar.bz2 files are not supported yet.
>
> It is not much, but with this Gnomezip should be able to display .tar
> files' content.
>
> Bye
> Giovanni
>
> PS. Hongli, you can add my name to the website now (Thanks!). BTW, can I
> have a CVS account, please?
>
...snip...
> ------------------------------------------------------------------------
> /*
> * tarlib.c
> *
> * Tarlib: a library to handle .tar files
> * Copyright (C) 2000 Giovanni Corriga (Valkadesh)
> *
> * Based upon the GNU tar program source code
> * GNU tar is copyright (C) 1999 Free Software Foundation
> */
>
> /*
...snip...
> /* support functions */
> int check_file (char* file)
> {
> union block block;
> char* magic;
> int retval = 0;
> FILE* fp = fopen(file, "rb");
I think you should use standard file descriptors (open, write, read,
seek) and not file streams as it is more portable across systems.
>
> if (!fp)
> return -1;
>
> if (fread(&block, sizeof(union block), 1, fp) != 1)
> {
> fclose(fp);
> return -1;
> }
>
> magic = block.header.magic;
>
> if (memcmp(magic, TMAGIC, sizeof(char)*TMAGLEN))
> retval = 1; /* posix archive */
> if (memcmp(magic, OLDGNU_MAGIC, sizeof(char)* 8))
> retval = 2; /* GNU archive */
Using sizeof(char) in this contest is a bug, file format declares magic
beeing long 8 bytes!
This is indipendent from how many bytes a char use on the platform.
On platforms with chars of greater than 8bit size this would break as
they will copy more bytes causing possible memory leaks.
>
> fclose(fp);
>
> return retval;
> }
>
...snip...
--
sim...@ti...
http://www.geocities.com/SiliconValley/9757
|
|
From: Hongli L. <ho...@te...> - 2000-12-23 15:04:51
|
On Sat, 23 Dec 2000 13:58:23 Simo Sorce wrote:
> > /* support functions */
> > int check_file (char* file)
> > {
> > union block block;
> > char* magic;
> > int retval = 0;
> > FILE* fp = fopen(file, "rb");
>
> I think you should use standard file descriptors (open, write, read,
> seek) and not file streams as it is more portable across systems.
???????????????
Which OS doesn't support file streams?
Isn't file streams part of ANSI C?
And are you suggesting fdopen() instead of fopen() ?
> > if (memcmp(magic, TMAGIC, sizeof(char)*TMAGLEN))
> > retval = 1; /* posix archive */
> > if (memcmp(magic, OLDGNU_MAGIC, sizeof(char)* 8))
> > retval = 2; /* GNU archive */
>
> Using sizeof(char) in this contest is a bug, file format declares magic
> beeing long 8 bytes!
> This is indipendent from how many bytes a char use on the platform.
> On platforms with chars of greater than 8bit size this would break as
> they will copy more bytes causing possible memory leaks.
So should I change "sizeof(char) * 8" to 8
and "sizeof(char)*TMAGLEN" to TMAGLEN?
|
|
From: Giovanni C. <val...@li...> - 2000-12-23 16:50:35
|
Simo Sorce wrote:
>
> > /* support functions */
> > int check_file (char* file)
> > {
> > union block block;
> > char* magic;
> > int retval = 0;
> > FILE* fp = fopen(file, "rb");
>
> I think you should use standard file descriptors (open, write, read,
> seek) and not file streams as it is more portable across systems.
I prefer open() calls too, but I found that POSIX-style calls have
nothing like ftell() which I think may be useful, esp. in extracting or
deleting files.
Should my guess happen to be wrong, I'd happily switch to open() calls.
>
> >
> > if (!fp)
> > return -1;
> >
> > if (fread(&block, sizeof(union block), 1, fp) != 1)
> > {
> > fclose(fp);
> > return -1;
> > }
> >
> > magic = block.header.magic;
> >
> > if (memcmp(magic, TMAGIC, sizeof(char)*TMAGLEN))
> > retval = 1; /* posix archive */
> > if (memcmp(magic, OLDGNU_MAGIC, sizeof(char)* 8))
> > retval = 2; /* GNU archive */
>
> Using sizeof(char) in this contest is a bug, file format declares magic
> beeing long 8 bytes!
> This is indipendent from how many bytes a char use on the platform.
> On platforms with chars of greater than 8bit size this would break as
> they will copy more bytes causing possible memory leaks.
I could have used strcmp() as well, but AFAIK memcmp() is more efficient
than strcmp(), even when comparing strings. So I prefered to force a
string comparison by use of memcmp(), but I had to be sure that it would
have compared 8 chars, not 8 bytes.
Do you think I should use strcmp(), instead of this hack?
|