mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-07 08:28:43 +02:00
xdgmime: Add better detection for text vs. binary and zero-sized files
This detects zero-sized files to return the special-case "application/x-zerosize" mime-type, as well as trying to differentiate unknown file types based on their first 128 bytes of data, so that text editors can automatically handle unknown text files. Based on: https://cgit.freedesktop.org/xdg/xdgmime/commit/?id=5181175d5fdaa3832b0fd094cda0120b1fe92af6 https://cgit.freedesktop.org/xdg/xdgmime/commit/?id=9c5802b8da56187c5c6abaf70042d14b12d832a9 https://bugzilla.gnome.org/show_bug.cgi?id=795544
This commit is contained in:
committed by
Emmanuele Bassi
parent
d0a48f26c7
commit
1c177ce0ab
@@ -185,3 +185,18 @@ _xdg_reverse_ucs4 (xdg_unichar_t *source, int len)
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
_xdg_binary_or_text_fallback(const void *data, size_t len)
|
||||
{
|
||||
unsigned char *chardata;
|
||||
int i;
|
||||
|
||||
chardata = (unsigned char *) data;
|
||||
for (i = 0; i < 128 && i < len; ++i)
|
||||
{
|
||||
if (chardata[i] < 32 && chardata[i] != 9 && chardata[i] != 10 && chardata[i] != 13)
|
||||
return XDG_MIME_TYPE_UNKNOWN; /* binary data */
|
||||
}
|
||||
|
||||
return XDG_MIME_TYPE_TEXTPLAIN;
|
||||
}
|
||||
|
Reference in New Issue
Block a user