BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / generic / mime_table / module.c
blob684aa779e2f9508c51904060d4f84662c161a303
1 /*******************************************************************************
3 / File: mime_table.c
5 / Description: Kernel module implementing kernel-space mime_table API
7 / Copyright 2004, François Revol.
9 *******************************************************************************/
11 #include <Drivers.h>
12 #include <KernelExport.h>
13 #include <string.h>
14 #include <stdlib.h>
16 #include <mime_table.h>
17 extern struct ext_mime mimes[];
19 #if DEBUG > 0
20 #define ddprintf(x) dprintf x
21 #else
22 #define ddprintf(x)
23 #endif
25 /* Module static data */
26 const char mime_table_module_name[] = B_MIME_TABLE_MODULE_NAME;
28 static status_t
29 std_ops(int32 op, ...)
31 switch(op) {
32 case B_MODULE_INIT:
33 return B_OK;
34 case B_MODULE_UNINIT:
35 return B_OK;
36 default:
37 /* do nothing */
40 return -1;
43 status_t get_table(struct ext_mime **table)
45 if (!table)
46 return EINVAL;
47 /* no need to malloc & copy yet */
48 *table = mimes;
49 return B_OK;
52 void free_table(struct ext_mime *table)
54 /* do nothing yet */
57 const char *mime_for_ext(const char *ext)
59 int i;
60 /* should probably be optimized */
61 for (i = 0; mimes[i].extension; i++) {
62 if (!strcmp(ext, mimes[i].extension))
63 return mimes[i].mime;
65 return NULL;
68 const char *ext_for_mime(const char *mime)
70 int i;
71 /* should probably be optimized */
72 for (i = 0; mimes[i].mime; i++) {
73 if (!strcmp(mime, mimes[i].mime))
74 return mimes[i].extension;
76 return NULL;
79 static mime_table_module_info mime_table = {
81 mime_table_module_name,
83 std_ops
85 get_table,
86 free_table,
87 mime_for_ext,
88 ext_for_mime
91 _EXPORT mime_table_module_info *modules[] = {
92 &mime_table,
93 NULL