Lex
Lex

Reputation: 171

How to get file type on linux?

I need to get file type without using file extensions on linux. There is "file" utility, which can do this. How can I do the same using C/C++? Not 'system(const char *)', of course... Thanks)

Upvotes: 1

Views: 819

Answers (2)

smbear
smbear

Reputation: 1041

AFAIK file is implemented over libmagic. For more reference see:

Upvotes: 5

Andrew
Andrew

Reputation: 12009

Either call file as a child process or emulate what it does. There are no other options if you want to intelligently examine a file's content to guess what it contains.

Upvotes: 1

Related Questions