The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
mime.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file mime.h
5 * @brief file types: the type name and the icon of a file.
6 *
7 * the table is /usr/share/ginnos/mime.conf (its format is described in
8 * the file). a file is matched by its name's extension, then by its first
9 * bytes, then as text.
10 */
11
12#include <stdbool.h>
13#include <stddef.h>
14#include <stdint.h>
15
16#define MIME_CONF "/usr/share/ginnos/mime.conf"
17
18// how many first bytes of a file the magic rules can look at
19#define MIME_HEAD_SIZE 64
20
21typedef struct
22{
23 const char *type; // "text/plain"
24 const char *icon; // a Tela icon name, "text-x-generic"
26
27typedef struct mime_table mime_table_t;
28
29/**
30 * read a table file (MIME_CONF for the system one).
31 * @return the table, or NULL (no file). bad lines are skipped.
32 */
33mime_table_t *mime_open(const char *path);
34
35/**
36 * a table from text in memory (for tests).
37 */
38mime_table_t *mime_from_text(const char *text);
39
40void mime_close(mime_table_t *table);
41
42/**
43 * the type of a file from its name and its first bytes.
44 * @param name the file name (a path is fine), or NULL.
45 * @param head the first bytes of the file, or NULL.
46 * @return the type; never NULL (application/octet-stream when nothing
47 * matches). it stays valid until the table is closed.
48 */
49const mime_type_t *mime_lookup(const mime_table_t *table, const char *name,
50 const uint8_t *head, size_t head_len);
51
52/**
53 * the type of a file on disk: inode/directory for a directory, else by
54 * its name and first bytes.
55 */
56const mime_type_t *mime_lookup_file(const mime_table_t *table, const char *path);
unsigned char uint8_t
Definition fb.h:18
NULL, size_t, ptrdiff_t, offsetof.
integer types of fixed width.
mime_table_t * mime_open(const char *path)
read a table file (MIME_CONF for the system one).
Definition mime.c:181
void mime_close(mime_table_t *table)
Definition mime.c:210
struct mime_table mime_table_t
Definition mime.h:27
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.
Definition mime.c:287
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.
Definition mime.c:248
mime_table_t * mime_from_text(const char *text)
a table from text in memory (for tests).
Definition mime.c:120
bool, true and false.
Definition mime.h:22
const char * type
Definition mime.h:23
const char * icon
Definition mime.h:24