简体   繁体   English

如何在Linux上获取文件类型?

[英]How to get file type on linux?

I need to get file type without using file extensions on linux. 我需要获取文件类型而不在Linux上使用文件扩展名。 There is "file" utility, which can do this. 有“文件”实用程序,可以执行此操作。 How can I do the same using C/C++? 如何使用C / C ++进行相同操作? Not 'system(const char *)', of course... Thanks) 当然不是'system(const char *)'...谢谢)

AFAIK file is implemented over libmagic . AFAIK file是通过libmagic实现的。 For more reference see: 有关更多参考,请参见:

Either call file as a child process or emulate what it does. 可以将调用file作为子进程,也可以模拟它的作用。 There are no other options if you want to intelligently examine a file's content to guess what it contains. 如果要智能地检查文件的内容以猜测其内容,则没有其他选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM