How to find the base file type in C ++?

The * nix system has a command called "file" that can tell you the basic file type. Say if you rename the binary executable name to foo.txt or rename the mp3 file to .txt, the system will always tell you the real file type. But on Windows, there are no such functions, if you rename the executable file to .txt, you cannot execute it. Can someone explain to me how this is done on a * nix system, and how can I find the real file type using C ++, especially on Windows, where I cannot use std :: system ("file blah")?

+4
source share
4 answers

The file utility uses the libmagic library. It recognizes the "special" filetype fields in the file.
Of course, you can program some formats yourself, but sometimes it takes a lot of work. For instance. when you try to distinguish between different MP4 formats.

The developers of this library have done quite a bit of work. Therefore, he advises using their results if you want to get the results of the gods, talking about what format you are dealing with (this is a big area, in fact, and knowing what type of format you work with, better rely on them, and then to your code)

- http://www.darwinsys.com/file/
, . -4.26 → magic → Magdir

4.26 Windows ftp://ftp.astron.com/pub/file/


, , . , . , , , , .

+2

UNIX file . , /usr/share/file/magic /etc/magic/, recogized file. () .

UNIX , Windows, Linux .

, Windows , . (,.txt) . , . The Old New Thing - Notepad, ...

0

, . , .

100% , , , . , , . , .

0

Unix/Linux . "" , , , - ​​ , , .

​​, "" Windows; - . Cygwin Windows "", .

.txt "" . - , Windows , ( , ), Unix/Linux , , . chmod a-x Linux, , .exe Windows.

0

Source: https://habr.com/ru/post/1548435/


All Articles