The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
mime.h File Reference

file types: the type name and the icon of a file. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  mime_type_t

Macros

#define MIME_CONF   "/usr/share/ginnos/mime.conf"
#define MIME_HEAD_SIZE   64

Typedefs

typedef struct mime_table mime_table_t

Functions

mime_table_t * mime_open (const char *path)
 read a table file (MIME_CONF for the system one).
mime_table_t * mime_from_text (const char *text)
 a table from text in memory (for tests).
void mime_close (mime_table_t *table)
const mime_type_t * mime_lookup (const mime_table_t *table, const char *name, const uint8_t *head, size_t head_len)
 the type of a file from its name and its first bytes.
const mime_type_t * mime_lookup_file (const mime_table_t *table, const char *path)
 the type of a file on disk: inode/directory for a directory, else by its name and first bytes.

Detailed Description

file types: the type name and the icon of a file.

the table is /usr/share/ginnos/mime.conf (its format is described in the file). a file is matched by its name's extension, then by its first bytes, then as text.

Macro Definition Documentation

◆ MIME_CONF

#define MIME_CONF   "/usr/share/ginnos/mime.conf"

◆ MIME_HEAD_SIZE

#define MIME_HEAD_SIZE   64

Typedef Documentation

◆ mime_table_t

typedef struct mime_table mime_table_t

Function Documentation

◆ mime_open()

mime_table_t * mime_open ( const char * path)

read a table file (MIME_CONF for the system one).

Returns
the table, or NULL (no file). bad lines are skipped.

◆ mime_from_text()

mime_table_t * mime_from_text ( const char * text)

a table from text in memory (for tests).

◆ mime_close()

void mime_close ( mime_table_t * table)

◆ mime_lookup()

const mime_type_t * mime_lookup ( const mime_table_t * table,
const char * name,
const uint8_t * head,
size_t head_len )

the type of a file from its name and its first bytes.

Parameters
namethe file name (a path is fine), or NULL.
headthe first bytes of the file, or NULL.
Returns
the type; never NULL (application/octet-stream when nothing matches). it stays valid until the table is closed.

◆ mime_lookup_file()

const mime_type_t * mime_lookup_file ( const mime_table_t * table,
const char * path )

the type of a file on disk: inode/directory for a directory, else by its name and first bytes.