Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - readlink() error while reading /proc/self/exefile on QNX: (4 Items)
   
readlink() error while reading /proc/self/exefile on QNX  
I am working on QNX platform, in which I need to get the path of executable which is running.

I have wrote a small peice of code, which is returning always -1:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

extern int errno;

int main( int argc, char** argv )
{
    char buf[512] = {0};
    const char mypath[100] = "/proc/self/exefile";
    errno = 0;
    printf("The value readlink:: %d %s\n",readlink(mypath, buf, 512 ), strerror( errno ));    
    return( 0 );
}

When I ran above code then I get following output:

The value readlink:: -1 No such file or directory

Am I missing anything? What needs to be done to get my current exe path in QNX?
Re: readlink() error while reading /proc/self/exefile on QNX  
Read the file itself. It's just a text file, not a symlink.
Re: readlink() error while reading /proc/self/exefile on QNX  
Thanks for your suggestion Roger.

Reading the file worked for me.

But do you know any one line command to read the path of executable?
Because to read the file I need to open the file and read it, then close it. Bit length process.

Just curious to know if we can do it any other way.

Thanks in advance.

Re: readlink() error while reading /proc/self/exefile on QNX  
Well if you're not fussy about line length and not too hung up on using the preprocessor you can do anything in C in one
 line :-)

Not really sure what you're after (or why you're after it). There's no single function that does everything.