|
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?
|