Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to find the default handling application in my C program. Is there a C API with same functionality as xdg-mime query default mime-type on Linux?

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

glibc doesn't know anything about MIME types; the API functions live at the level of desktop environment APIs, and the freedesktop.org recognize that harmonizing them is an impossible task so they only specify the shell-level interface. You either use that via popen() or code for a particular desktop environment.

share|improve this answer
    
Thanks for the information! Could you give me some hint about using system() to get this information? –  Amanda Mar 14 '11 at 1:38
    
Actually, not system() but rather popen() so you can capture the output of xdg-mime. –  geekosaur Mar 14 '11 at 1:41
add comment

I don't believe there's a C API for querying mime-types in the same way that xdg-mime works. xdg-mime is just a shell script that queries your desktop environment (Gnome, KDE, or other), and runs the appropriate command to get the MIME type from that DE's internal configuration.

You could replicate the behaviour of the shell script, or just call the shell script directly from C. The XDG Utils web page doesn't seem to show anything about a C API.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.