ご回答ありがとうございます。
私はこれで解決:
const char *w_get_mime(const char *arg, const char *file, int line_no)
{
const char *magic_full;
magic_t magic_cookie;
if(arg == NULL)
w_report_error("called with NULL argument.",file,line_no,__func__,0,1,error);
else if ((magic_cookie = magic_open(MAGIC_MIME)) == NULL)
report_error("unable to initialize magic library.",0,1,error);
else if (magic_load(magic_cookie, NULL) != 0)
{
magic_close(magic_cookie);
snprintf(globals.err_buff,MAX_BUFF,"cannot load magic database - %s .",magic_error(magic_cookie));
report_error(globals.err_buff,0,1,error);
}
magic_full = magic_file(magic_cookie, arg);
magic_close(magic_cookie);
return magic_full;
}
おかげでたくさん! :)
"私はファイルのMIMEタイプを知る必要があります" - >可能な複製http://stackoverflow.com/questions/9137732/how-to-generate-the-http-content-type-header -in-c/9137758、私はhttp://stackoverflow.com/a/9137758/960195として回答しました –
バイナリ以上のものが必要です。 Fileは/ etc/magicを使用します。このファイルにはさまざまなファイルタイプの「フィンガープリント」が含まれています。ベスト/シンプルな方法は単にpopen()またはsystem()を使うことです。 – wildplasser
'popen'や' system'を使うのは(いつも)とても悪い考えです。 'libmagic'があります。もし' file(1) 'を起動したいのであれば、' posix_spawn'を使うべきです。 –