The magicffi Reference Manual

This is the magicffi Reference Manual, generated automatically by Declt version 4.0 beta 2 "William Riker" on Wed May 15 06:07:20 2024 GMT+0.

Table of Contents


1 Introduction


2 Systems

The main system appears first, followed by any subsystem dependency.


2.1 magicffi

cffi interface to libmagic(3)

Maintainer

Desmond O. Chang <>

Author

Desmond O. Chang <>

License

Simplified BSD License

Long Description

A file type determination library.

Defsystem Dependency

cffi-grovel (system).

Dependencies
  • cffi-grovel (system).
  • cffi (system).
  • cl-ppcre (system).
Source

magicffi.asd.

Child Components

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


3.1 Lisp


3.1.1 magicffi/magicffi.asd

Source

magicffi.asd.

Parent Component

magicffi (system).

ASDF Systems

magicffi.


3.1.2 magicffi/package.lisp

Source

magicffi.asd.

Parent Component

magicffi (system).

Packages

magicffi.


3.1.3 magicffi/grovel.lisp

Dependency

package.lisp (file).

Source

magicffi.asd.

Parent Component

magicffi (system).


3.1.4 magicffi/types.lisp

Dependency

grovel.lisp (file).

Source

magicffi.asd.

Parent Component

magicffi (system).

Public Interface
Internals

3.1.5 magicffi/api.lisp

Dependency

types.lisp (file).

Source

magicffi.asd.

Parent Component

magicffi (system).

Public Interface
Internals

3.1.6 magicffi/shortcuts.lisp

Dependency

api.lisp (file).

Source

magicffi.asd.

Parent Component

magicffi (system).

Public Interface

4 Packages

Packages are listed by definition order.


4.1 magicffi

Usage:
> (asdf:load-system :magicffi)
> (use-package :magicffi)
> (with-open-magic (magic ’(:mime-type :symlink)) (magic-load magic)
(magic-file magic #P"magicffi.asd")) "text/plain"

Source

package.lisp.

Use List
  • cffi.
  • common-lisp.
Public Interface
Internals

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


5.1 Public Interface


5.1.1 Special variables

Special Variable: *magic-database*

Default magic database files. It can be NIL(default), or a designator for a non-empty list of pathname designators. NIL means the default database files defined by libmagic.

Package

magicffi.

Source

api.lisp.


5.1.2 Macros

Macro: with-open-magic ((magic &optional flags magicfiles) &body body)

Opens the magic cookie MAGIC, executes BODY and close MAGIC.

FLAGS:
A list of keywords (see types), defaulted to (:none).

MAGICFILES:
NIL, or a list of pathname designators for the database files.
Defaulted to NIL, which uses the default database available in the system. This covers the most usage.

Package

magicffi.

Source

api.lisp.


5.1.3 Ordinary functions

Function: magic-buffer (magic string)

Returns a textual description of the contents of the STRING argument. An error of type MAGIC-ERROR is signaled on failure.

Package

magicffi.

Source

api.lisp.

Function: magic-check (magic &optional pathname-list)

Checks the validity of database files. PATHNAME-LIST is NIL(default), which means use *MAGIC-DATABASE*, or a designator for a non-empty list of pathname designators. Returns ’true’ on success and signals an error of type MAGIC-ERROR on failure.

Package

magicffi.

Source

api.lisp.

Function: magic-close (magic)

Closes the magic database and deallocates any resources used. It is permissible to close an already closed magic, and has no effect. Returns ’true’ if an open magic cookie has been closed, or ’false’ if the magic cookie is already closed.

Package

magicffi.

Source

api.lisp.

Function: magic-compile (magic &optional pathname-list)

Compiles database files. PATHNAME-LIST is NIL(default), which means use *MAGIC-DATABASE*, or a designator for a non-empty list of pathname designators. Returns ’true’ on success and signals an error of type MAGIC-ERROR on failure. The compiled files created are named from the basename(1) of each file argument with ‘.mgc’ appended to it.

Package

magicffi.

Source

api.lisp.

Function: magic-error (magic)

Signals an error of type MAGIC-ERROR.

Package

magicffi.

Source

api.lisp.

Function: magic-file (magic pathspec)

Returns a textual description of the contents of the PATHSPEC argument. PATHSPEC is a pathname designator. An error of type MAGIC-ERROR is signaled on failure.

Package

magicffi.

Source

api.lisp.

Function: magic-load (magic &optional pathname-list)

Loads database files. PATHNAME-LIST is NIL(default), which means use *MAGIC-DATABASE*, or a designator for a non-empty list of pathname designators. Returns ’true’ on success and signals an error of type MAGIC-ERROR on failure.

Package

magicffi.

Source

api.lisp.

Function: magic-open (flags)

Creates a magic cookie and returns it. An error of type SIMPLE-ERROR is signaled on failure. FLAGS specifies how the other magic functions should behave. See README for the flags usage.

Package

magicffi.

Source

api.lisp.

Function: magic-setflags (magic flags)

Sets the magic flags. Signals an error of type SIMPLE-ERROR on systems that don’t support utime(2), or utimes(2) when :PRESERVE-ATIME is set; otherwise, returns ’true’.

Package

magicffi.

Source

api.lisp.

Function: magicp (object)

Returns ’true’ if object is of type MAGIC; otherwise, returns ’false’. It is unaffected by whether object, if it is a magic, is open or closed.

Package

magicffi.

Source

types.lisp.

Function: open-magic-p (magic)

Returns ’true’ if MAGIC is open; otherwise, returns ’false’.

Package

magicffi.

Source

types.lisp.

Function: pathname-apple (file &rest flags &key debug symlink compress devices continue check preserve-atime raw error compress-transp no-check-compress no-check-tar no-check-soft no-check-apptype no-check-elf no-check-text no-check-cdf no-check-tokens no-check-encoding)

Return the Apple creator/type

Package

magicffi.

Source

shortcuts.lisp.

Function: pathname-extension (file &rest flags &key debug symlink compress devices continue check preserve-atime raw error compress-transp no-check-compress no-check-tar no-check-soft no-check-apptype no-check-elf no-check-text no-check-cdf no-check-tokens no-check-encoding)

Return a /-separated list of extensions. This is NOT about the file name extensions (such as .png).

Package

magicffi.

Source

shortcuts.lisp.

Function: pathname-file (file &rest flags &key debug symlink compress devices continue check preserve-atime raw error compress-transp no-check-compress no-check-tar no-check-soft no-check-apptype no-check-elf no-check-text no-check-cdf no-check-tokens no-check-encoding)

Returns a description, as in unix ‘file‘ command

Package

magicffi.

Source

shortcuts.lisp.

Function: pathname-mime (file &rest flags &key debug symlink compress devices continue check preserve-atime raw error compress-transp no-check-compress no-check-tar no-check-soft no-check-apptype no-check-elf no-check-text no-check-cdf no-check-tokens no-check-encoding)

Return the MIME type

Package

magicffi.

Source

shortcuts.lisp.

Function: pathname-mime-encoding (file &rest flags &key debug symlink compress devices continue check preserve-atime raw error compress-transp no-check-compress no-check-tar no-check-soft no-check-apptype no-check-elf no-check-text no-check-cdf no-check-tokens no-check-encoding)

Return the MIME encoding

Package

magicffi.

Source

shortcuts.lisp.

Function: pathname-mime-type (file &rest flags &key debug symlink compress devices continue check preserve-atime raw error compress-transp no-check-compress no-check-tar no-check-soft no-check-apptype no-check-elf no-check-text no-check-cdf no-check-tokens no-check-encoding)

Return the MIME type

Package

magicffi.

Source

shortcuts.lisp.


5.1.4 Generic functions

Generic Reader: magic-error-errno (condition)
Package

magicffi.

Methods
Reader Method: magic-error-errno ((condition magic-error))
Source

types.lisp.

Target Slot

%errno.

Generic Reader: magic-error-error (condition)
Package

magicffi.

Methods
Reader Method: magic-error-error ((condition magic-error))
Source

types.lisp.

Target Slot

%error.


5.1.5 Conditions

Condition: magic-error

Consists of errors that are related to MAGICFFI.
Use the function MAGIC-ERROR to signal it. The error number and error string are accessed by the functions MAGIC-ERROR-ERRNO and MAGIC-ERROR-ERROR.

Package

magicffi.

Source

types.lisp.

Direct superclasses

error.

Direct methods
Direct slots
Slot: %errno
Initargs

:errno

Readers

magic-error-errno.

Writers

This slot is read-only.

Slot: %error
Initargs

:error

Readers

magic-error-error.

Writers

This slot is read-only.


5.1.6 Classes

Class: magic

Lisp magic class.

Package

magicffi.

Source

types.lisp.

Direct methods
Direct slots
Initargs

:cookie

Readers

%magic-cookie.

Writers

(setf %magic-cookie).


5.2 Internals


5.2.1 Symbol macros

Symbol Macro: *errno*
Package

magicffi.

Source

api.lisp.


5.2.2 Macros

Macro: %database-funcall (name-and-options magic pathname-list)
Package

magicffi.

Source

api.lisp.


5.2.3 Ordinary functions

Function: %boolean-from-lisp (value)
Package

magicffi.

Source

types.lisp.

Function: %boolean-to-lisp (value)
Package

magicffi.

Source

types.lisp.

Function: %magic-c-to-lisp (cookie)
Package

magicffi.

Source

types.lisp.

Function: %magic-error-reporter (condition stream)
Package

magicffi.

Source

types.lisp.

Function: %magic-lisp-to-c (magic)
Package

magicffi.

Source

types.lisp.

Function: %pathlist-to-cstring (pathname-list)
Package

magicffi.

Source

api.lisp.

Function: %pathname-concat (seq)
Package

magicffi.

Source

api.lisp.

Function: %truename (filespec)
Package

magicffi.

Source

api.lisp.

Function: %var-accessor-*errno* ()
Package

magicffi.

Source

api.lisp.

Function: (setf %var-accessor-*errno*) ()
Package

magicffi.

Source

api.lisp.

Function: magic-verify-version ()
Package

magicffi.

Source

api.lisp.

Function: magic-version ()

The magic_version() command returns the version number of this library which is compiled into the shared library using the constant MAGIC_VERSION from <magic.h>. This can be used by client programs to verify that the version they compile against is the same as the version that they run against.

Package

magicffi.

Source

api.lisp.


5.2.4 Generic functions

Generic Reader: %magic-cookie (object)
Package

magicffi.

Methods
Reader Method: %magic-cookie ((magic magic))

automatically generated reader method

Source

types.lisp.

Target Slot

cookie.

Generic Writer: (setf %magic-cookie) (object)
Package

magicffi.

Methods
Writer Method: (setf %magic-cookie) ((magic magic))

automatically generated writer method

Source

types.lisp.

Target Slot

cookie.


Appendix A Indexes


A.1 Concepts


A.2 Functions

Jump to:   %   (  
F   G   M   O   P   W  
Index Entry  Section

%
%boolean-from-lisp: Private ordinary functions
%boolean-to-lisp: Private ordinary functions
%database-funcall: Private macros
%magic-c-to-lisp: Private ordinary functions
%magic-cookie: Private generic functions
%magic-cookie: Private generic functions
%magic-error-reporter: Private ordinary functions
%magic-lisp-to-c: Private ordinary functions
%pathlist-to-cstring: Private ordinary functions
%pathname-concat: Private ordinary functions
%truename: Private ordinary functions
%var-accessor-*errno*: Private ordinary functions

(
(setf %magic-cookie): Private generic functions
(setf %magic-cookie): Private generic functions
(setf %var-accessor-*errno*): Private ordinary functions

F
Function, %boolean-from-lisp: Private ordinary functions
Function, %boolean-to-lisp: Private ordinary functions
Function, %magic-c-to-lisp: Private ordinary functions
Function, %magic-error-reporter: Private ordinary functions
Function, %magic-lisp-to-c: Private ordinary functions
Function, %pathlist-to-cstring: Private ordinary functions
Function, %pathname-concat: Private ordinary functions
Function, %truename: Private ordinary functions
Function, %var-accessor-*errno*: Private ordinary functions
Function, (setf %var-accessor-*errno*): Private ordinary functions
Function, magic-buffer: Public ordinary functions
Function, magic-check: Public ordinary functions
Function, magic-close: Public ordinary functions
Function, magic-compile: Public ordinary functions
Function, magic-error: Public ordinary functions
Function, magic-file: Public ordinary functions
Function, magic-load: Public ordinary functions
Function, magic-open: Public ordinary functions
Function, magic-setflags: Public ordinary functions
Function, magic-verify-version: Private ordinary functions
Function, magic-version: Private ordinary functions
Function, magicp: Public ordinary functions
Function, open-magic-p: Public ordinary functions
Function, pathname-apple: Public ordinary functions
Function, pathname-extension: Public ordinary functions
Function, pathname-file: Public ordinary functions
Function, pathname-mime: Public ordinary functions
Function, pathname-mime-encoding: Public ordinary functions
Function, pathname-mime-type: Public ordinary functions

G
Generic Function, %magic-cookie: Private generic functions
Generic Function, (setf %magic-cookie): Private generic functions
Generic Function, magic-error-errno: Public generic functions
Generic Function, magic-error-error: Public generic functions

M
Macro, %database-funcall: Private macros
Macro, with-open-magic: Public macros
magic-buffer: Public ordinary functions
magic-check: Public ordinary functions
magic-close: Public ordinary functions
magic-compile: Public ordinary functions
magic-error: Public ordinary functions
magic-error-errno: Public generic functions
magic-error-errno: Public generic functions
magic-error-error: Public generic functions
magic-error-error: Public generic functions
magic-file: Public ordinary functions
magic-load: Public ordinary functions
magic-open: Public ordinary functions
magic-setflags: Public ordinary functions
magic-verify-version: Private ordinary functions
magic-version: Private ordinary functions
magicp: Public ordinary functions
Method, %magic-cookie: Private generic functions
Method, (setf %magic-cookie): Private generic functions
Method, magic-error-errno: Public generic functions
Method, magic-error-error: Public generic functions

O
open-magic-p: Public ordinary functions

P
pathname-apple: Public ordinary functions
pathname-extension: Public ordinary functions
pathname-file: Public ordinary functions
pathname-mime: Public ordinary functions
pathname-mime-encoding: Public ordinary functions
pathname-mime-type: Public ordinary functions

W
with-open-magic: Public macros