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

file types from /usr/share/ginnos/mime.conf. More...

#include "mime.h"
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

Macros

#define CONF_MAX_SIZE   (256 * 1024)
#define EXT_MAX   15

Enumerations

enum  rule_kind_t { RULE_EXT , RULE_MAGIC , RULE_TEXT }

Functions

mime_table_t * mime_from_text (const char *text)
 a table from text in memory (for tests).
mime_table_t * mime_open (const char *path)
 read a table file (MIME_CONF for the system one).
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 from /usr/share/ginnos/mime.conf.

Macro Definition Documentation

◆ CONF_MAX_SIZE

#define CONF_MAX_SIZE   (256 * 1024)

◆ EXT_MAX

#define EXT_MAX   15

Enumeration Type Documentation

◆ rule_kind_t

Enumerator
RULE_EXT 
RULE_MAGIC 
RULE_TEXT 

Function Documentation

◆ mime_from_text()

mime_table_t * mime_from_text ( const char * text)

a table from text in memory (for tests).

◆ 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_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.