Parth Shah
Parth Shah

Reputation: 573

Get file extension in C

Is there a C library function to get the extension of file? I know that I can design a function on my own to get extension after '.' but not all files are stored with their extensions when we read them.

Upvotes: 0

Views: 474

Answers (2)

qdot
qdot

Reputation: 6335

The file command in Linux uses a library called libmagic (don't confuse with libmagick) to check the 'magic' bytes in the file itself to determine the likely content type.

The library is fairly cross platform, it's well documented, for example here: http://linux.die.net/man/3/libmagic

Upvotes: 3

silverzhao
silverzhao

Reputation: 61

So you'd like to get the type of a file? Maybe the command 'file' in Linux is what you want. You can check its source code.

Upvotes: 4

Related Questions