v05i028: /etc/magic lines for compress

Alexander Dupuy dupuy at douglass.columbia.edu
Thu Nov 17 07:46:50 AEST 1988


In article <454 at auspex.UUCP> guy at auspex.UUCP (Guy Harris) writes:
> Unfortunately, "strings" in "/etc/magic" cannot, in the standard S5
> version, contain C-language escapes, so you can't do this:
> 
> 	0	string		\037\235	compressed data
> 
> which the SunOS version of the S5 'file" supports; this obviates the need
> for byte-order-dependent versions of "/etc/magic".

In article <7714 at boring.cwi.nl> dik at cwi.nl (Dik T. Winter) replies:
> Wouldn't it be better to allow specification like AR16W, AR32W and
> AR32WR as happens in so many places in SysV (COFF comes to mind)?
> Then each system can specify in its favourite order its own /etc/magic
> part.

Not only is this better, but the "strings" in even the SunOS version of magic
can't contain null bytes (well actually, they can, but it doesn't do what you
want), and can't be masked in the way which SunOS allows you to mask numbers.

While I find AR32WR pretty incomprehensible (is it network order, or reversed?)
it should be possible to write a file which converts the numbers and masks
specified in /etc/magic into network order before doing any comparisons, and
converts values read from the file into local byte order before performing %d
substitutions on the descriptions in the /etc/magic file.  If needed, special
printf macros could be used to indicate substitutions for which the bytes
needed to be swapped before the ntohl conversion was done.  This should provide
a portable file(1).

@alex
-- 
inet: dupuy at columbia.edu
uucp: ...!rutgers!columbia!dupuy



More information about the Comp.sources.bugs mailing list