[fpc-devel] Re: File Dates

Jeff Pohlmeyer yetanothergeek at yahoo.com
Sun Jan 30 05:34:41 CET 2005


> AFAIR Unix has some kind of registry for file types, based on file
> extensions and characteristic bytes at the begin of an file. Does
> somebody know more about that registry, so that it could be integrated
> into the intended registry for archive handlers?


=================================================

unit libmagic;
interface
{$PACKRECORDS C}
{$LINKLIB magic}
{$LINKLIB c}

const
  MAGIC_NONE           = $000;
  MAGIC_DEBUG          = $001;
  MAGIC_SYMLINK        = $002;
  MAGIC_COMPRESS       = $004;
  MAGIC_DEVICES        = $008;
  MAGIC_MIME           = $010;
  MAGIC_CONTINUE       = $020;
  MAGIC_CHK            = $040; // naming conflict ( was MAGIC_CHECK )
  MAGIC_PRESERVE_ATIME = $080;
  MAGIC_RAW            = $100;
  MAGIC_ERR            = $200; // naming conflict ( was MAGIC_ERROR )

type
  size_t = dword;

  magic_set = record
    {opaque structure}
  end;
  magic_t = ^magic_set;

function magic_open(flags:LongInt):magic_t;cdecl;external;
function magic_file(cookie:magic_t; filename:pChar):pChar;cdecl;external;
function magic_error(cookie:magic_t):pChar;cdecl;external;
function magic_setflags(cookie:magic_t; flags:LongInt):LongInt;cdecl;external;
function magic_load(cookie:magic_t; filename:pChar):LongInt;cdecl;external;
function magic_compile(cookie:magic_t; filename:pChar):LongInt;cdecl;external;
function magic_check(cookie:magic_t; filename:pChar):LongInt;cdecl;external;
function magic_errno(cookie:magic_t):LongInt;cdecl;external;
procedure magic_close(cookie:magic_t);cdecl;external;
function magic_buffer( cookie:magic_t; 
                       buffer:pointer; buflen:size_t):pChar;cdecl;external;


implementation
end.

=================================================

program testmagic;

uses strings, libmagic;

var 
  magic: magic_t;

begin
  if ( paramcount = 1 ) then begin
    magic:=magic_open( MAGIC_SYMLINK or MAGIC_MIME );
    magic_load(magic, nil);
    WriteLn(magic_file(magic, argv[1]));
    magic_close(magic);
  end else WriteLn(StdErr, 'Usage:  testmagic <filename>');
end.


=================================================


Requires "file" --version >= 4.0


See also:
  http://directory.fsf.org/file.html
  http://prdownloads.sourceforge.net/gnuwin32/file-4.12-lib.zip?download





.


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 




More information about the fpc-devel mailing list