finding the full path of the program which ran.
- From: "Prasad" <prasadjoshi124@xxxxxxxxx>
- Date: 21 Dec 2006 08:40:40 -0800
Hi All,
I m building a library which requires the full path of the program to
which it is linked. How could I do it?
I can't use argv for sure, because this requires user program to be
aware of the library.
The way to find should be portable.
Besides, argv[0] doesn't give the full path. And a program can be ran
using using relative path so, getting the full path is really a hard
process using argv[0].
For eg.
[Prasad@prasadjoshi test]$ cat a_program.c
#include<stdio.h>
void afun ()
{
printf ( "\nIn afun ().\n" );
}
int main ( int argc, char *argv[] )
{
char cwd[100] ;
//intitialize_call_graph ( argv[0] );
getcwd ( cwd, 100 ) ;
printf ( "\ncwd = %s, name = %s \n", cwd, argv[0] ) ;
afun () ;
}
[Prasad@prasadjoshi test]$ ./a.out
cwd = /home/Prasad/programs/c/lsp/test, name = ./a.out
In afun ().
[Prasad@prasadjoshi test]$ ../test/a.out
cwd = /home/Prasad/programs/c/lsp/test, name = ../test/a.out
In afun ().
[Prasad@prasadjoshi test]$ ../../lsp/test/a.out
cwd = /home/Prasad/programs/c/lsp/test, name = ../../lsp/test/a.out
In afun ().
[Prasad@prasadjoshi lsp]$ test/a.out
cwd = /home/Prasad/programs/c/lsp, name = test/a.out
In afun ().
There has to be some other way to do it.
Thanks and regards,
Prasad.
.
- Follow-Ups:
- Re: finding the full path of the program which ran.
- From:
- Re: finding the full path of the program which ran.
- From: John Reiser
- Re: finding the full path of the program which ran.
- From: Grant Edwards
- Re: finding the full path of the program which ran.
- From: Prasad
- Re: finding the full path of the program which ran.
- Prev by Date: Re: If pipe excellent?
- Next by Date: Re: finding the full path of the program which ran.
- Previous by thread: Efficient way for user-mode process - kernel module communication ?? proc / sysfs/ ioctl/ Netlink
- Next by thread: Re: finding the full path of the program which ran.
- Index(es):
Relevant Pages
|