2 * Copyright (C) 1995-2006, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: mime.c,v 1.2 2006-04-20 20:50:51 adam Exp $
9 \brief Small utility to manage MIME types
19 #include <yaz/xmalloc.h>
23 struct yaz_mime_entry {
26 struct yaz_mime_entry *next;
29 struct yaz_mime_info {
30 struct yaz_mime_entry *table;
33 yaz_mime_types yaz_mime_types_create()
35 yaz_mime_types p = xmalloc(sizeof(*p));
40 void yaz_mime_types_add(yaz_mime_types t, const char *suffix,
41 const char *mime_type)
43 struct yaz_mime_entry *e = xmalloc(sizeof(*e));
44 e->mime_type = xstrdup(mime_type);
45 e->suffix = xstrdup(suffix);
50 const char *yaz_mime_lookup_suffix(yaz_mime_types t, const char *suffix)
52 struct yaz_mime_entry *e = t->table;
53 for (; e; e = e->next)
55 if (!strcmp(e->suffix, suffix))
61 const char *yaz_mime_lookup_fname(yaz_mime_types t, const char *fname)
63 const char *cp = strrchr(fname, '.');
64 if (!cp) /* if no . return now */
66 return yaz_mime_lookup_suffix(t, cp+1); /* skip . */
69 void yaz_mime_types_destroy(yaz_mime_types t)
71 struct yaz_mime_entry *e = t->table;
74 struct yaz_mime_entry *e_next = e->next;
86 * indent-tabs-mode: nil
88 * vim: shiftwidth=4 tabstop=8 expandtab