1

I am currently writing a parser for the libmagic database (used by the file command) and i don't found any information on the 'use' and 'clear' type (second column in the magic file).
Can someone explain to me what this types should do ?

1

Those are fairly new features, documented in magic(5):

use
Recursively call the named magic starting from the current offset. If the name of the referenced begins with a ^ then the endianness of the magic is switched; if the magic mentioned leshort for example, it is treated as beshort and vice versa. This is useful to avoid duplicating the rules for different endianness.

clear
This test is always true and clears the match flag for that continuation level. It is intended to be used with the default test.

By "fairly new":

2014-11-27 18:40 Christos Zoulas

    * Allow setting more parameters from the command line.
    * Split name/use and indirect magic recursion limits.

2013-04-22 11:20 Christos Zoulas

    * The way "default" was implemented was not very useful
      because the "if something was printed at that level"
      was not easily controlled by the user, and the format
      was bound to a string which is too restrictive. Add
      a "clear" for that level keyword and make "default"
      void. This way one can do:            

            >>13    clear   x
            >>13    lelong  1       foo
            >>13    lelong  2       bar
            >>13    default x
            >>>13   lelong  x       unknown %x 
  • I checked the source (was curious...), saw it was documented as quoted, and found an up-to-date copy. – Thomas Dickey Dec 12 '15 at 20:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.