Get the header file in which a function is declared

Hi,

I'm trying to get header file in which a function is declared using libtooling in clang.

#include <stdio.h>

int main() {
   void *ptr = malloc(10);
   return 0;
}

In above example, I can get "FunctionDecl" object of "malloc". But how can I get in which header file "malloc" is declared (in above example, it's "stdio.h") provided that I've "FunctionDecl" object?

Thanks
Riyad

Try one of the methods that returns a SourceLocation (or SourceRange). E.g. getLocStart() which it inherits from Decl. http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html

– Sean Silva