Une fabuleuse lib s'appelle libmagic et permet d'obtenir le mimetype d'un fichier.

Petit example d'utilisation (à compiler avec -lmagic):

#include <magic.h>
#include <stdio.h>
#include <stdlib.h>
#include <err.h>
 
int
main(int argc, char *argv[])
{
	const char* program_name = argv[0];
	char *filename = argv[1];
 
	if (filename == NULL) {
		fprintf(stderr, "Usage: %s file\n", program_name);
		return(1);
	}
 
	struct magic_set *magic = magic_open(MAGIC_MIME_TYPE);
	if (magic == NULL)
		err(1, "magic_set");
 
	magic_load(magic, NULL);
 
	printf("%s: %s\n", filename, magic_file(magic, filename));
 
        magic_close(magic);
 
	return(0);
}
c/lib/mimetype_d_un_fichier_via_libmagic.txt · Last modified: 2010/01/12 13:29 (external edit)
www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0