comp.lang.ada
 help / color / mirror / Atom feed
From: Thierry Lelegard <thierry.lelegard@canal-plus.fr>
Subject: Re: How to find directory where the program is?
Date: Wed, 24 Apr 2002 10:35:01 +0200
Date: 2002-04-24T10:35:01+02:00	[thread overview]
Message-ID: <3CC66E35.69EECB@canal-plus.fr> (raw)
In-Reply-To: slrnacb9v4.5ud.randhol+abuse@kiuk0156.chembio.ntnu.no

Preben Randhol wrote :
> 
> How can one in Ada95 find out from which directory the Ada program is
> stored in.  I mean I need to find out if my program is stored in
> /usr/bin/ or /usr/local/bin or some other directory. Does anybody know
> how I can do this. Note that current directory is not equal to the
> directory the program is stored in. I use GNAT so if GNAT has some
> routines for this that I have missed, please tell me. I'll make it
> portable later if needed.

It entirely depends on the operating system. On UNIX, getting argv[0]
is not reliable since there are some flavors of exec (such as execve)
which allow the caller to set argv[0] to something different from the
program name (see a login shell: argv[0] is "-sh" while the program name
is "sh" without leading dash).

To get the full path name, we use system-dependent techniques,
usually using the /proc filesystem on UNIX. However, the usage
of the the /proc filesystem depends on the UNIX flavor.

It works fine on Solaris and Linux (enter "man proc"). On HP-UX,
there is no /proc file system and we use pstat_getproc. HOwever,
it returns the basename only.

On the other OS we use (OpenVMS and Windows, although Windows can hardly
be considered as an OS :-(), there are dedicated system calls to get
the full pathname of the program.

-Thierry
____________________________________________________________________________

Thierry Lelegard, "The Jazzing Troll", CANAL+ Technologies
____________________________________________________________________________



  parent reply	other threads:[~2002-04-24  8:35 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-23 18:28 How to find directory where the program is? Preben Randhol
2002-04-23 19:10 ` Florian Weimer
2002-04-23 19:37 ` Randy Brukardt
2002-04-23 20:53   ` Preben Randhol
2002-04-23 21:04 ` Joachim Schr�er
2002-04-24  8:35 ` Thierry Lelegard [this message]
2002-04-24  8:43 ` Jean-Pierre Rosen
2002-04-24 10:33   ` Preben Randhol
2002-04-24 11:43     ` Jean-Pierre Rosen
2002-04-24 14:44       ` Preben Randhol
2002-04-24 15:38 ` Hyman Rosen
2002-04-24 17:44   ` Preben Randhol
2002-04-24 23:08   ` Nick Roberts
2002-04-25  7:28     ` Preben Randhol
2002-04-25 14:18       ` Marin David Condic
2002-04-26 16:24         ` Stephen Leake
2002-04-26 20:41           ` achrist
2002-04-26 21:31           ` Larry Kilgallen
2002-04-29 15:38           ` Marin David Condic
2002-04-25 17:10       ` Sergey Koshcheyev
2002-04-25 21:11         ` Nick Roberts
2002-04-25 23:28           ` Sergey Koshcheyev
2002-04-26  5:57             ` Preben Randhol
2002-04-26 16:22           ` Stephen Leake
2002-04-26 17:13         ` Anders Gidenstam
2002-04-26 12:18       ` Jacob Sparre Andersen
2002-04-26 12:23         ` Preben Randhol
2002-04-26 12:48           ` David C. Hoos
2002-04-26 14:13             ` Preben Randhol
2002-04-27  8:18               ` Eric G. Miller
2002-04-26 13:09         ` Marin David Condic
2002-04-27 14:39           ` Larry Kilgallen
2002-04-27 21:12             ` Nick Roberts
2002-04-29 15:52             ` Marin David Condic
2002-04-24 17:44 ` Egil Harald Hoevik
  -- strict thread matches above, loose matches on Subject: below --
2002-04-23 19:24 Beard, Frank [Contractor]
2002-04-23 19:56 Beard, Frank [Contractor]
2002-04-23 22:41 ` Larry Kilgallen
2002-04-23 23:28 Beard, Frank [Contractor]
2002-04-24  0:49 ` Larry Kilgallen
2002-04-24  2:31   ` achrist
2002-04-24 10:29     ` Preben Randhol
2002-04-24 15:28       ` Darren New
2002-04-24 17:43         ` Preben Randhol
2002-04-24 18:33           ` Randy Brukardt
2002-04-24 21:00             ` Wes Groleau
2002-04-25 19:26               ` Randy Brukardt
2002-04-25  2:37             ` Steve Doiel
2002-04-25  7:26               ` Preben Randhol
2002-04-24  9:44 Grein, Christoph
2002-04-25 10:35 ` Thierry Lelegard
2002-04-25 19:30   ` Philippe Waroquiers
2002-04-25 22:57     ` Larry Kilgallen
2002-04-25 16:43 Beard, Frank [Contractor]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox