#include <stdint.h>
#include <time.h>
#include <magic.h>
+#include <locale.h>
+#include <langinfo.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
free(buf);
}
-static int strrcmp(char *str, char *end)
-{
- return(strcmp(str + strlen(str) - strlen(end), end));
-}
-
static char *attrmimetype(char *file)
{
#ifdef HAVE_XATTR
if((ret = attrmimetype(file)) != NULL)
return(ret);
if(cookie == NULL) {
- cookie = magic_open(MAGIC_MIME_TYPE);
+ cookie = magic_open(MAGIC_MIME_TYPE | MAGIC_SYMLINK);
magic_load(cookie, NULL);
}
if((ret = magic_file(cookie, file)) != NULL)
return("application/octet-stream");
}
+/* XXX: This could be made far better and check for other attributes
+ * and stuff, but not now. */
+static const char *ckctype(const char *ctype)
+{
+ if(!strncmp(ctype, "text/", 5) && (strchr(ctype, ';') == NULL))
+ return(sprintf2("%s; charset=%s", ctype, nl_langinfo(CODESET)));
+ return(ctype);
+}
+
static void checkcache(char *file, struct stat *sb)
{
char *hdr;
int fd;
const char *contype;
+ setlocale(LC_ALL, "");
contype = NULL;
while((c = getopt(argc, argv, "c:")) >= 0) {
switch(c) {
}
if(contype == NULL)
contype = getmimetype(file, &sb);
+ contype = ckctype(contype);
checkcache(file, &sb);