The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
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
21
typedef
struct
22
{
23
const
char
*
type
;
// "text/plain"
24
const
char
*
icon
;
// a Tela icon name, "text-x-generic"
25
}
mime_type_t
;
26
27
typedef
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
*/
33
mime_table_t
*
mime_open
(
const
char
*path);
34
35
/**
36
* a table from text in memory (for tests).
37
*/
38
mime_table_t
*
mime_from_text
(
const
char
*text);
39
40
void
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
*/
49
const
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
*/
56
const
mime_type_t
*
mime_lookup_file
(
const
mime_table_t
*table,
const
char
*path);
uint8_t
unsigned char uint8_t
Definition
fb.h:18
stddef.h
NULL, size_t, ptrdiff_t, offsetof.
stdint.h
integer types of fixed width.
mime_open
mime_table_t * mime_open(const char *path)
read a table file (MIME_CONF for the system one).
Definition
mime.c:181
mime_close
void mime_close(mime_table_t *table)
Definition
mime.c:210
mime_table_t
struct mime_table mime_table_t
Definition
mime.h:27
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.
Definition
mime.c:287
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.
Definition
mime.c:248
mime_from_text
mime_table_t * mime_from_text(const char *text)
a table from text in memory (for tests).
Definition
mime.c:120
stdbool.h
bool, true and false.
mime_type_t
Definition
mime.h:22
mime_type_t::type
const char * type
Definition
mime.h:23
mime_type_t::icon
const char * icon
Definition
mime.h:24
src
lib
mime
include
mime.h
Generated by
1.18.0