CAPS Universe documentation  1.0.4
All you need to know to be successful
Functions

Detect some MIME types of printing documents. More...

Functions

int detect_mimetype (const char *buf, size_t sz, const char **mimetype)
 

Detailed Description

Used to assign a corresponding rasterizer.

Function Documentation

◆ detect_mimetype()

int detect_mimetype ( const char *  buf,
size_t  sz,
const char **  mimetype 
)

Detect the MIME type of the given header of file content

Parameters
[in]bufPointer to files header data
[in]szCount of bytes of file data
[out]mimetypeWhere to store a pointer to the file's content MIME type
Returns
0 on success (*mimetype is valid), negative errno else

This function is a wrapper for the CAPS implementation of detecting a few kind of printing document formats. It will be used, if libmagic isn't available or disabled at build-time.

Currently detected printing document formats:

  • "image/pwg-raster"
  • "image/png"
  • "image/jpeg"
  • "application/postscript"
  • "application/pdf"
  • "application/cups-raster"
  • "application/x-lzw"

Any leading PJL commands are skipped to detect the real data's MIME format.

Precondition
Provide enough data (not only a few bytes) from the header of the file.

If libmagic is available and enabled at build-time, it is used instead. The calling code can continue to use the detect_mimetype() function in this case (another wrapper does the job).

Attention
This routine isn't thread safe!