Reputation: 1625
I have a function on Windows to get the address of the module in buf:
GetModuleFileName(0, buf, buf_size);
I want to do the same on Linux (which I do not know much about). I found the function dladdr(X, &dlInfo)
which seems to do the right thing. As I understand I get the name and other details (dli_sname
, dli_saddr
, dli_fname
, ..) of X
in dlInfo
with this function.
But what is X
? I know it it an address. But which one? How would I use this to obtain the same result as on Windows?
Upvotes: 1
Views: 692
Reputation: 39085
X
is any interesting address, usually the address of an interesting module function. If you want to get the current module name, X
can be an address of the caller
void X() {
// ...
dladdr(X, &dlInfo);
// or dladdr(&X, &dlInfo);
}
Upvotes: 1