Skip to content

Instantly share code, notes, and snippets.

@xuchunyang
Created November 13, 2018 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuchunyang/096a85312a843135d574d6149c9ffc63 to your computer and use it in GitHub Desktop.
Save xuchunyang/096a85312a843135d574d6149c9ffc63 to your computer and use it in GitHub Desktop.
/*
~ $ ./file-mime-type foo.png
image/png
*/
#include <magic.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
magic_t cookie = magic_open (MAGIC_MIME_TYPE);
magic_load (cookie, NULL);
printf("%s\n", magic_file (cookie, argv[1]));
return 0;
}
/* Local Variables: */
/* compile-command: "cc -std=c99 -Wall -Wpedantic file-mime-type.c -o file-mime-type -lmagic" */
/* End: */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment