From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,814d0ec938d6e4da X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-04-24 01:40:03 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!deine.net!oleane.net!oleane!nnrp.oleane.net!not-for-mail From: Thierry Lelegard Newsgroups: comp.lang.ada Subject: Re: How to find directory where the program is? Date: Wed, 24 Apr 2002 10:35:01 +0200 Organization: CANAL+ Technologies Message-ID: <3CC66E35.69EECB@canal-plus.fr> References: NNTP-Posting-Host: host227.canal-plus.fr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: s1.read.news.oleane.net 1019637302 16444 194.2.208.227 (24 Apr 2002 08:35:02 GMT) X-Complaints-To: abuse@oleane.net NNTP-Posting-Date: Wed, 24 Apr 2002 08:35:02 +0000 (UTC) X-Mailer: Mozilla 4.78 [fr]C-CCK-MCD C+ (WinNT; U) X-Accept-Language: fr,en,zh-CN,zh-TW Xref: archiver1.google.com comp.lang.ada:23037 Date: 2002-04-24T10:35:01+02:00 List-Id: 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 ____________________________________________________________________________