2 * - by Richard W.M. Jones <rich@annexia.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * $Id: mime_types.c,v 1.3 2002/10/06 11:57:22 rich Exp $
31 #include "mime_types.h"
33 static pool mt_pool = 0;
34 static sash mt_map = 0;
37 mime_types_reread_config (const char *path)
46 if (mt_pool) delete_pool (mt_pool);
47 mt_pool = new_subpool (global_pool);
49 mt_map = new_sash (mt_pool);
51 tmp = new_subpool (mt_pool);
53 /* Read the /etc/mime.types file. */
54 fp = fopen (path, "r");
55 if (fp == 0) { perror (path); exit (1); }
57 while ((line = pgetlinec (tmp, fp, line)) != 0)
59 v = pstrresplit (tmp, line, re_ws);
61 switch (vector_size (v))
70 vector_get (v, 0, mt);
71 for (i = 1; i < vector_size (v); ++i)
73 vector_get (v, i, ext);
74 sash_insert (mt_map, ext, mt);
86 mime_types_get_type (const char *ext)
90 sash_get (mt_map, ext, mt);